1. 程式人生 > >CentOS7基於FPM模式編譯LAMP,實現多虛擬主機應用wordpress

CentOS7基於FPM模式編譯LAMP,實現多虛擬主機應用wordpress

lamp、wordpress

該實驗需要的軟件環境:

apr-1.6.2.tar.gz

httpd-2.4.27.tar.bz2

php-7.1.10.tar.xz

apr-util-1.6.0.tar.gz

mariadb-10.2.8-linux-x86_64.tar.gz

wordpress-4.8.1-zh_CN.tar.gz

(一) 源碼編譯安裝Httpd2.4

yum groupinstall "development tools"

yum install openssl-devel expat-devel pcre-devel

tar xvf apr-1.6.2.tar.gz

tar xvf apr-util-1.6.0.tar.gz

tar xvf httpd-2.4.27.tar.bz2

cp -r apr-1.6.2 httpd-2.4.27/srclib/apr

cp -r apr-util-1.6.0 httpd-2.4.27/srclib/apr-util

cd httpd-2.4.27/

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

技術分享

make -j 4 && make install

vim /etc/profile.d/lamp.sh

PATH=/app/httpd24/bin/:$PATH

. /etc/profile.d/lamp.sh

vim /app/httpd24/conf/httpd.conf

User apache #修改為apache

Group apache

vim /etc/init.d/httpd24

apachectl=/app/httpd24/bin/apachectl

httpd=${HTTPD-/app/httpd24/bin/httpd}

pidfile=${PIDFILE-/app/httpd24/logs/httpd.pid}

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

chkconfig --add httpd24

chkconfig httpd24 on

chkconfig --list httpd24

apachectl

ss -tnl

(二) 二進制安裝mariadb

1、查詢mariadb是否已安裝

[root@centos7 ~]#rpm -qa mariadb*

2、查詢是否有mysql用戶,若沒有就連同用戶的家目錄/app/mysqldb和默認

shell(/sbin/nologin) 一同創建。

[root@centos7 ~]#getent passwd mysql

[root@centos7 ~]#useradd -d /app/mysqldb -r -m -s /sbin/nologin

mysql

3、準備二進制文件:從官網下載mariadb最新版本並解壓,此時的解壓路徑一定要放到MySQL 默認的路徑裏,否則會出錯,還要把mariadb-10.2.8-linux-x86_64目錄改成mysql目錄,或 創建軟連接,這裏就以創建軟連接為例。

[root@centos7 ~]#tar xvf mariadb-10.2.8-linux-x86_64.tar.gz -C /usr/local/

[root@centos7 ~]#cd /usr/local/

[root@centos7 local]#ln -s mariadb-10.2.8-linux-x86_64/ mysql

4、準備配置文件

[root@centos7 local]#cd mysql/

[root@centos7 mysql]#mkdir /etc/mysql

[root@centos7 mysql]#cp support-files/my-huge.cnf /etc/mysql/my.cnf

[root@centos7 mysql]#vim /etc/mysql/my.cnf

[mysqld]

datadir = /app/mysqldb

innodb_file_per_table = on

skip_name_resolve = on

5、創建數據庫文件,此時必須在/usr/local/mysql目錄下,否則會出現以下錯誤

技術分享[root@centos7 mysql]#. scripts/mysql_install_db --user=mysql --

datadir= /app/mysqldb

6、準備日誌文件

[root@centos7 mysql]#touch /var/log/mariadb/

[root@centos7 mysql]#chown mysql /var/log/mariadb/

7、準備服務腳本,並啟動服務

[root@centos7 mysql]#cp support-files/mysql.server /etc/init.d/mysqld

[root@centos7 mysql]#chkconfig --list mysqld

[root@centos7 mysql]#chkconfig --add mysqld

[root@centos7 mysql]#systemctl start mysqld

8 、配置環境變量

[root@centos7 mysql]#vim /etc/profile.d/mysql.sh

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

[root@centos7 mysql]# . /etc/profile.d/mysql.sh

9 、安全初始化

[root@centos7 mysql]#mysql_secure_installation

Remove anonymous users? [Y/n] y

... Success!

Disallow root login remotely? [Y/n] y

... Success!

Remove test database and access to it? [Y/n] n

... skipping.

Reload privilege tables now? [Y/n] y

... Success!

Cleaning up...


(三) 源碼編譯安裝Php

yum install libxml2-devel bzip2-devel libmcrypt-devel

tar xvf php-7.1.10.tar.xz

cd php-7.1.10/

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

vim /etc/profile.d/lamp.sh

PATH=/app/httpd24/bin:/usr/local/mysql/bin:/app/php/bin/:$PATH

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

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

chmod +x /etc/init.d/php-fpm

chkconfig --add php-fpm

chkconfig php-fpm on

cd /app/php/etc

cp php-fpm.conf.default php-fpm.conf

cp php-fpm.d/www.conf.default php-fpm.d/www.conf

service php-fpm start

(四) 配置httpd支持fpm php

vim /app/httpd24/conf/httpd.conf

取消下面兩行的註釋

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

修改下面行

<IfModule dir_module>

DirectoryIndex index.php index.html

</IfModule>

加下面四行

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

apachectl stop;apachectl

(五)支持多個虛擬主機

vim /app/httpd24/conf/httpd.conf

Include conf/extra/httpd-vhosts.conf 取消註釋

刪除下面兩行

ProxyRequests Off

ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/app/httpd24/htdocs/$1

vim /app/httpd24/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>

ServerAdmin [email protected]

DocumentRoot "/app/httpd24/htdocs"

ServerName www.a.com

ErrorLog "logs/a.com-error_log"

CustomLog "logs/a.com-access_log" common

ProxyRequests Off

ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/app/httpd24/htdocs/$1

<directory /app/httpd24/htdocs>

require all granted

</directory>

</VirtualHost>

<VirtualHost *:80>

ServerAdmin [email protected]

DocumentRoot "/app/httpd24/htdocs2"

ServerName www.b.com

ErrorLog "logs/b.com-error_log"

CustomLog "logs/b.com-access_log" common

ProxyRequests Off

ProxyPassMatch ^/(.*\.php)$

fcgi://127.0.0.1:9000/app/httpd24/htdocs2/$1

<directory /app/httpd24/htdocs2>

require all granted

</directory>

</VirtualHost>

(六) 配置wordpress

tar xvf wordpress-4.8.1-zh_CN.tar.gz -C /app/httpd24/htdocs

cd /app/httpd24/htdocs

mv wordpress/ blog/

cd /app/httpd24/htdocs/blog/

cp wp-config-sample.php wp-config.php

vim wp-config.php

     define(‘DB_NAME‘, ‘wpdb‘);
 
    /** MySQL數據庫用戶名 */
    define(‘DB_USER‘, ‘wpuser‘);
 
    /** MySQL數據庫密碼 */
    define(‘DB_PASSWORD‘, ‘centos‘);
 
    /** MySQL主機 */
    define(‘DB_HOST‘, ‘localhost‘);

在瀏覽器登錄測試:http://websrv/blog

用ab測試性能:ab -c 10 -n 100 http://websrv/blog/


CentOS7基於FPM模式編譯LAMP,實現多虛擬主機應用wordpress