1. 程式人生 > >52、基於httpd-2.4.37、mysql-5.7.24、php-5.6.38原始碼安裝LAMP

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 [email protected]

  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