LAMP ----- 編譯實現基於FASTCGI的LAMP的WordPress

1 準備環境,兩臺主機:php

一臺: httpd, php 192.168.21.104 html

安裝包存放路徑: /data   

 apr-1.6.5.tar.bz2                      httpd.apache.org                    
#wget http://mirror.bit.edu.cn/apache//apr/apr-1.6.5.tar.bz2

 apr-util-1.6.1.tar.bz2                 httpd.apache.org                    
 #wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.6.1.tar.bz2

 httpd-2.4.38.tar.bz2                   httpd.apache.org                    
#wget http://mirrors.shu.edu.cn/apache//httpd/httpd-2.4.38.tar.bz2

 php-7.3.2.tar.xz                          www.php.net                          
 #wget http://cn2.php.net/get/php-7.3.2.tar.xz/from/this/mirror

 wordpress-5.0.3-zh_CN.tar.gz     https://cn.wordpress.org/download/   
 #wget https://cn.wordpress.org/wordpress-5.0.3-zh_CN.tar.gz

一臺: mariadb 192.168.21.106mysql

安裝包存放路徑:/root
mariadb-10.2.22-linux-x86_64.tar.gz                 
#wget https://downloads.mariadb.org/interstitial/mariadb-10.2.22/bintar-linux-x86_64/mariadb-10.2.22-linux-x86_64.tar.gz/from/http%3A//mirror.wtnet.de/mariadb/

2 在192.168.21.104上,安裝相關包
#yum -y install gcc glibc pcre-devel openssl-devel expat-devel libxml2-devel bzip2-devel libmcrypt-devellinux

3 源碼編譯安裝httpd
#tar xvf apr-1.6.5.tar.bz2
#tar xvf apr-util-1.6.1.tar.bz2
#tar xvf httpd-2.4.38.tar.bz2 sql

把解壓後的apr, apr-util文件夾移到apache解壓文件的srclib路徑下重命名
#mv apr-1.6.5 httpd-2.4.38/srclib/apr
#mv apr-util-1.6.1 httpd-2.4.38/srclib/apr-util數據庫

#cd httpd-2.4.38/apache

./configure --prefix=/app/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork \
--with-included-aprvim

#make -j 4 && make install centos

環境變量
#echo 'PATH=/app/httpd24/bin:$PATH' > /etc/profile.d/lamp.sh
#source /etc/profile.d/lamp.shapi

建立apache用戶
#useradd -r -s /sbin/nologin apache

把用戶和組改成:apache
#vim /app/httpd24/conf/httpd.conf
user apache
group apache

啓動apache
#apachectl

添加apache爲開機自啓動

方法 一
.==================================================================

[root@centos7 ~]#vim /etc/rc.d/rc.local
./app/httpd24/bin/apachectl

#chmod +x /etc/rc.d/rc.local

方法 二
.==================================================================

  1. 編寫啓動腳本
    #vim httpd

#!/bin/bash
#chkconfig: 12345 80 90

function start_http()
{
/app/httpd24/bin/apachectl start
}

function stop_http()
{
/app/httpd24/bin/apachectl stop
}

case "$1" in
start)
start_http
;;
stop)
stop_http
;;
restart)
stop_http
start_http
;;
*)
echo "Usage : start | stop | restart"
;;
esac

  1. 加入系統服務:
    #chmod a+x httpd
    #cp -arf httpd /etc/init.d/

  2. 啓動本身編寫的服務:
    #systemctl daemon-reload
    #systemctl start httpd

或者能夠這樣玩:
/etc/init.d/httpd start | stop | restart
.===========================================================

4 在192.168.21.106上, 二進制源碼包安裝mariadb
#tar xvf mariadb-10.2.22-linux-x86_64.tar.gz -C /usr/local/
#cd /usr/local
#ln -s mariadb-10.2.22-linux-x86_64/ mysql

#chown -R root.root /usr/local/mysql/

#useradd -r -s /sbin/nologin mysql

建立數據庫文件目錄
#mkdir -pv /data/mysql
#chown mysql.mysql /data/mysql

利用腳本生成數據庫文件
#scripts/mysql_install_db --datadir=/data/mysql --user=mysql

準備數據庫配置文件
#mkdir /etc/mysql/
#cp /usr/local/mysql/support-files/my-huge.cnf /etc/mysql/my.cnf
#vim /etc/mysql/my.cnf
datadir=/data/mysql

準備啓動腳本
#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
#chkconfig --add mysqld
#chkconfig --list mysqld

數據庫安全加固
#mysql_secure_installation

#service mysqld start

配置環境變量
#echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
#. /etc/profile.d/mysql.sh

#mysql -uroot -p

建立數據庫:wpdb (給WordPress用)
mysql>create database wpdb;

建立登錄wpdb數據庫的帳號: 用戶:wpuser 密碼:centos 並給設權限。
mysql>grant all on wpdb.* to wpuser@'192.168.21.%' identified by 'centos';

5 編譯安裝php
#tar xvf php-7.3.2.tar.xz

#cd php-7.3.2/
./configure --prefix=/app/php --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-mbstring --enable-xml --enable-sockets --enable-fpm --enable-maintainer-zts --disable-fileinfo

#make -j 4 && make install

進到php解壓縮的目錄
#cd /data/php-7.3.2

準備php 配置文件
#cp php.ini-production /etc/php.ini

準備php的啓動腳本
#cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
#chmod +x /etc/init.d/php-fpm
#chkconfig --add php-fpm
#chkconfig --list php-fpm

進到php安裝目錄
#cd /app/php/etc

準備php-fpm的配置文件
#cp php-fpm.conf.default php-fpm.conf
#cp php-fpm.d/www.conf.default php-fpm.d/www.conf
#service php-fpm start
#ss -ntl //查看9000的端口號是否已開啓

6 修改httpd的配置支持fpm
#vim /app/httpd24/conf/httpd.conf
取消下面兩行的註釋
LoadModule proxy_modulemodules/mod_proxy.so
LoadModule proxy_fcgi_modulemodules/mod_proxy_fcgi.so

修改下面行
<IfModuledir_module>
DirectoryIndex index.php index.html
</IfModule>

配置文件的最後加下面四行:shift + g (光標移到配置文件尾部)
AddType application/x-httpd-php.php
AddType application/x-httpd-php-source .phps
ProxyRequests Off
ProxyPassMatch^/(.*.php)$ fcgi://127.0.0.1:9000/app/httpd24/htdocs/$1

7 配置wordpress
#cd /data/
把WordPress解壓到apache的網站目錄下
#tar xvf wordpress-5.0.3-zh_CN.tar.gz -C /app/httpd24/htdocs/

注意wordpress目錄權限
#cd /app/httpd24/htdocs/
#setfacl –R –m u:apache:rwx wordpress //設置apache用戶對wordpress目錄有讀寫執行權限

準備wordpress的配置文件
#cd /app/httpd24/htdocs/wordpress
#cp wp-config-sample.php wp-config.php

#vim wp-config.php
/* WordPress數據庫的名稱 /
define('DB_NAME', 'wpdb');

/* MySQL數據庫用戶名 /
define('DB_USER', 'wpuser');

/* MySQL數據庫密碼 /
define('DB_PASSWORD', 'centos');

/* MySQL主機 /
define('DB_HOST', '192.168.21.106');

測試:
#cd /app/httpd24/htdocs/

建立index.php測試頁面
#vim index.php
<?php
phpinfo();
?>

#ls
index.html index.php wordpress

本地瀏覽器訪問:
http://192.168.21.104/index.html
http://192.168.21.104/index.php
http://192.168.21.104/wordpress/

相關文章
相關標籤/搜索