CentOS7基于FPM模式编译LAMP,实现多虚拟主机应用wordpress
该实验需要的软件环境:apr-1.6.2.tar.gz httpd-2.4.27.tar.bz2 php-7.1.10.tar.xzapr-util-1.6.0.tar.gzmariadb-10.2.8-linux-x86_64.tar.gzwordpress-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
chkconfighttpd24 on
chkconfig --list httpd24
apachectl
ss -tnl
(二) 二进制安装mariadb
1、查询mariadb是否已安装#rpm -qa mariadb*2、查询是否有mysql用户,若没有就连同用户的家目录/app/mysqldb和默认shell(/sbin/nologin)一同创建。#getent passwd mysql#useradd -d /app/mysqldb -r -m -s /sbin/nologin mysql 3、准备二进制文件:从官网下载mariadb最新版本并解压,此时的解压路径一定要放到MySQL默认的路径里,否则会出错,还要把mariadb-10.2.8-linux-x86_64目录改成mysql目录,或创建软连接,这里就以创建软连接为例。#tar xvf mariadb-10.2.8-linux-x86_64.tar.gz-C /usr/local/#cd /usr/local/#ln -s mariadb-10.2.8-linux-x86_64/ mysql4、准备配置文件#cd mysql/#mkdir /etc/mysql #cp support-files/my-huge.cnf/etc/mysql/my.cnf#vim /etc/mysql/my.cnf datadir = /app/mysqldbinnodb_file_per_table = onskip_name_resolve = on5、创建数据库文件,此时必须在/usr/local/mysql目录下,否则会出现以下错误#. scripts/mysql_install_db --user=mysql -- datadir= /app/mysqldb
6、准备日志文件#touch /var/log/mariadb/#chown mysql /var/log/mariadb/7、准备服务脚本,并启动服务#cpsupport-files/mysql.server/etc/init.d/mysqld#chkconfig --list mysqld#chkconfig --add mysqld#systemctl start mysqld 8 、配置环境变量#vim /etc/profile.d/mysql.shPATH=/usr/local/mysql/bin:$PATH# . /etc/profile.d/mysql.sh9 、安全初始化#mysql_secure_installation Remove anonymous users? y ... Success!Disallow root login remotely? y ... Success!Remove test database and access to it? n ... skipping.Reload privilege tables now? 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/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
./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.confInclude conf/extra/httpd-vhosts.conf取消注释
删除下面两行ProxyRequests OffProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/app/httpd24/htdocs/$1
vim /app/httpd24/conf/extra/httpd-vhosts.conf <VirtualHost *:80> ServerAdmin webmaster@dummy-host.example.com 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 webmaster@dummy-host.example.com 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.phpwp-config.php
vim wp-config.php
1
2
3
4
5
6
7
8
9
10
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/
页:
[1]