CentOS7基于FPM模式编译LAMP,实现多虚拟主机应用wordpress
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS7基于FPM模式编译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是否已安装
[[email protected] ~]#rpm -qa mariadb*
2、查询是否有mysql用户,若没有就连同用户的家目录/app/mysqldb和默认
shell(/sbin/nologin) 一同创建。
[[email protected] ~]#getent passwd mysql
[[email protected] ~]#useradd -d /app/mysqldb -r -m -s /sbin/nologin
mysql
3、准备二进制文件:从官网下载mariadb最新版本并解压,此时的解压路径一定要放到MySQL 默认的路径里,否则会出错,还要把mariadb-10.2.8-linux-x86_64目录改成mysql目录,或 创建软连接,这里就以创建软连接为例。
[[email protected] ~]#tar xvf mariadb-10.2.8-linux-x86_64.tar.gz -C /usr/local/
[[email protected] ~]#cd /usr/local/
[[email protected] local]#ln -s mariadb-10.2.8-linux-x86_64/ mysql
4、准备配置文件
[[email protected] local]#cd mysql/
[[email protected] mysql]#mkdir /etc/mysql
[[email protected] mysql]#cp support-files/my-huge.cnf /etc/mysql/my.cnf
[[email protected] mysql]#vim /etc/mysql/my.cnf
[mysqld]
datadir = /app/mysqldb
innodb_file_per_table = on
skip_name_resolve = on
5、创建数据库文件,此时必须在/usr/local/mysql目录下,否则会出现以下错误
[[email protected] mysql]#. scripts/mysql_install_db --user=mysql --
datadir= /app/mysqldb
6、准备日志文件
[[email protected] mysql]#touch /var/log/mariadb/
[[email protected] mysql]#chown mysql /var/log/mariadb/
7、准备服务脚本,并启动服务
[[email protected] mysql]#cp support-files/mysql.server /etc/init.d/mysqld
[[email protected] mysql]#chkconfig --list mysqld
[[email protected] mysql]#chkconfig --add mysqld
[[email protected] mysql]#systemctl start mysqld
8 、配置环境变量
[[email protected] mysql]#vim /etc/profile.d/mysql.sh
PATH=/usr/local/mysql/bin:$PATH
[[email protected] mysql]# . /etc/profile.d/mysql.sh
9 、安全初始化
[[email protected] 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的主要内容,如果未能解决你的问题,请参考以下文章
Centos6.9基于FPM模式编译安装实现LAMP应用wordpress
CentOS6编译LAMP基于FPM模式的应用wordpress
实战案例:编译安装基于 FastCGI 模式LAMP架构多虚拟主机WEB应用(WordPress 和Discuz)