52、基于httpd-2.4.37、mysql-5.7.24、php-5.6.38源码安装LAMP

1、安装准备

firewall-cmd --state

systemctl stop firewalld

firewall-cmd --state

systemctl disable firewalld

vim /etc/selinux/config 

SELINUX=disabled

setenforce 0


2、安装httpd-2.4.37

2.1安装依赖包

yum -y install pcre-devel expat-devel openssl-devel

yum -y groupinstall "Development tools" "Server Platform Development"


2.2、安装arp、arp-util

tar xf apr-2.6.5.tar.gz

cd apr-2.6.5

./configure --prefix=/usr/local/apr

make && make install

tar xf apr-util-2.6.2.tar.gz

cd apr-util-2.6.1

./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/

make && make install


2.3、安装httpd

tar xf httpd-2.4.37.tar.gz

cd httpd-2.4.37

./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=event

make && make install


2.4、测试

/usr/local/apache/bin/apachectl start

netstat -tuanlp | grep 80

/usr/local/apache/bin/apachectl stop

netstat -tuanlp | grep 80


2.5、服务器启动脚本

cat /etc/init.d/httpd 

#!/bin/bash

#

# httpd        Startup script for the Apache HTTP Server

#

# chkconfig: - 85 15

# description: Apache is a World Wide Web server.  It is used to serve \

#        HTML files and CGI.

# processname: httpd

# config: /etc/httpd/conf/httpd.conf

# config: /etc/sysconfig/httpd

# pidfile: /var/run/httpd.pid


# Source function library.

. /etc/rc.d/init.d/functions


if [ -f /etc/sysconfig/httpd ]; then

        . /etc/sysconfig/httpd

fi


# Start httpd in the C locale by default.

HTTPD_LANG=${HTTPD_LANG-"C"}


# This will prevent initlog from swallowing up a pass-phrase prompt if

# mod_ssl needs a pass-phrase from the user.

INITLOG_ARGS=""


# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server

# with the thread-based "worker" MPM; BE WARNED that some modules may not

# work correctly with a thread-based MPM; notably PHP will refuse to start.


# Path to the apachectl script, server binary, and short-form for messages.

apachectl=/usr/local/apache/bin/apachectl

httpd=${HTTPD-/usr/local/apache/bin/httpd}

prog=httpd

pidfile=${PIDFILE-/var/run/httpd.pid}

lockfile=${LOCKFILE-/var/lock/subsys/httpd}

RETVAL=0


start() {

        echo -n $"Starting $prog: "

        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS

        RETVAL=$?

        echo

        [ $RETVAL = 0 ] && touch ${lockfile}

        return $RETVAL

}


stop() {

  echo -n $"Stopping $prog: "

  killproc -p ${pidfile} -d 10 $httpd

  RETVAL=$?

  echo

  [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}

}

reload() {

    echo -n $"Reloading $prog: "

    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then

        RETVAL=$?

        echo $"not reloading due to configuration syntax error"

        failure $"not reloading $httpd due to configuration syntax error"

    else

        killproc -p ${pidfile} $httpd -HUP

        RETVAL=$?

    fi

    echo

}


# See how we were called.

case "$1" in

  start)

  start

  ;;

  stop)

  stop

  ;;

  status)

        status -p ${pidfile} $httpd

  RETVAL=$?

  ;;

  restart)

  stop

  start

  ;;

  condrestart)

  if [ -f ${pidfile} ] ; then

    stop

    start

  fi

  ;;

  reload)

        reload

  ;;

  graceful|help|configtest|fullstatus)

  $apachectl $@

  RETVAL=$?

  ;;

  *)

  echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"

  exit 1

esac


exit $RETVAL



chmod +x /etc/init.d/httpd


2.6、修改配置文件

cat /etc/httpd24/httpd.conf | grep ^PidFile 

PidFile "/var/run/httpd.pid"


2.7、设置环境变量

vim /etc/profile.d/httpd.sh

export PATH=/usr/local/apache/bin:$PATH

source /etc/profile.d/httpd.sh


2.8、设置开机启动

chkconfig --add httpd

chkconfig httpd on

chkconfig --list httpd


2.9、启动服务

/etc/init.d/httpd start

netstat -tuanlp | grep 80




3、安装mysql-5.7.24

3.1、卸载系统自带Mariadb

find / -name mariadb*

yum -y remove mariadb-libs-5.5.44

find / -name mariadb*


3.2、安装mysql

tar xf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz  -C /usr/local/

mv /usr/local/mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql


3.3、创建相关用户及目录

groupadd -r mysql

useradd -g mysql -r -s /sbin/nologin mysql

mkdir -p /mydata/data

mkdir -p /mydata/binlog

chown mysql:mysql /mydata/data

chown mysql:mysql /mydata/binlog


3.4、服务器启动脚本

chown :mysql /usr/local/mysql -R

cd /usr/local/mysql/

cp support-files/mysql.server /etc/rc.d/init.d/mysqld


3.5、创建配置文件

vim /etc/my.cnf 

[mysqld]

bind-address = 0.0.0.0

socket=/tmp/mysql.sock

basedir=/usr/local/mysql

datadir=/mydata/data

log-bin=/mydata/binlog/log-bin

server-id=1

skip-name-resolve


3.6、设置环境变量

vim /etc/profile.d/mysql.sh

export PATH=/usr/local/mysql/bin:$PATH

source /etc/profile.d/mysql.sh


3.7、配置为开机启动

/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/mydata/data

systemctl start mysqld

chkconfig --add mysqld

chkconfig --list mysqld

netstat -tuanlp | grep 3306


3.8、设置root密码,授权远程连接

mysql

SET PASSWORD = PASSWORD('root123');

GRANT ALL ON mysql.* TO 'root'@'localhost' IDENTIFIED BY 'root123';

GRANT ALL ON mysql.* TO 'root'@'127.0.0.1' IDENTIFIED BY 'root123';

GRANT ALL ON mysql.* TO 'testuser'@'192.168.%.%' IDENTIFIED BY 'testpass';

FLUSH PRIVILEGES;


4、安装php-5.6.38

4.1、安装依赖包

yum -y install https://mirrors.aliyun.com/epel/7Server/x86_64/Packages/e/epel-release-7-11.noarch.rpm

yum -y install bzip2-devel libmcrypt-devel libxml2-devel 


4.2、安装php

ln -s libmysqlclient.so.20.3.11 libmysqlclient_r.so

tar xf php-5.6.38.tar.gz

cd php-5.6.38

./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml  --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2  --enable-maintainer-zts

make && make install


4.3、复制配置文件

cp php.ini-production /etc/php.ini


4.4、修改httpd配置文件以支持php

vim /etc/httpd24/httpd.conf

AddType application/x-httpd-php  .php

AddType application/x-httpd-php-source  .phps

DirectoryIndex  index.php  index.html


4.5、编写测试页

vim /usr/local/apache/htdocs/index.php

<?php

  $link = mysql_connect('127.0.0.1','root','root123');

  if ($link)

    echo "连接数据库成功";

  else

    echo "连接数据库失败";

  mysql_close();

  phpinfo();

?>


4.6、设置环境变量

vim /etc/profile.d/php.sh

export PATH=/usr/local/php/bin/:$PATH

source /etc/profile.d/php.sh


4.7、测试

service httpd restart


5、安装phpMyAdmin-4.8.3

tar xf phpMyAdmin-4.8.3-all-languages.tar.xz 

mv phpMyAdmin-4.8.3-all-languages /usr/local/apache/htdocs/pma


猜你喜欢

转载自blog.51cto.com/kaiyuandiantang/2326415
今日推荐