该实验需要的软件环境:
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是否已安装 [iyunv@centos7 ~]#rpm -qa mariadb* 2、查询是否有mysql用户,若没有就连同用户的家目录/app/mysqldb和默认 shell(/sbin/nologin) 一同创建。 [iyunv@centos7 ~]#getent passwd mysql [iyunv@centos7 ~]#useradd -d /app/mysqldb -r -m -s /sbin/nologin mysql 3、准备二进制文件:从官网下载mariadb最新版本并解压,此时的解压路径一定要放到MySQL 默认的路径里,否则会出错,还要把mariadb-10.2.8-linux-x86_64目录改成mysql目录,或 创建软连接,这里就以创建软连接为例。 [iyunv@centos7 ~]#tar xvf mariadb-10.2.8-linux-x86_64.tar.gz -C /usr/local/ [iyunv@centos7 ~]#cd /usr/local/ [iyunv@centos7 local]#ln -s mariadb-10.2.8-linux-x86_64/ mysql 4、准备配置文件 [iyunv@centos7 local]#cd mysql/ [iyunv@centos7 mysql]#mkdir /etc/mysql [iyunv@centos7 mysql]#cp support-files/my-huge.cnf /etc/mysql/my.cnf [iyunv@centos7 mysql]#vim /etc/mysql/my.cnf [mysqld] datadir = /app/mysqldb innodb_file_per_table = on skip_name_resolve = on 5、创建数据库文件,此时必须在/usr/local/mysql目录下,否则会出现以下错误
[iyunv@centos7 mysql]#. scripts/mysql_install_db --user=mysql -- datadir= /app/mysqldb
6、准备日志文件 [iyunv@centos7 mysql]#touch /var/log/mariadb/ [iyunv@centos7 mysql]#chown mysql /var/log/mariadb/ 7、准备服务脚本,并启动服务 [iyunv@centos7 mysql]#cp support-files/mysql.server /etc/init.d/mysqld [iyunv@centos7 mysql]#chkconfig --list mysqld [iyunv@centos7 mysql]#chkconfig --add mysqld [iyunv@centos7 mysql]#systemctl start mysqld 8 、配置环境变量 [iyunv@centos7 mysql]#vim /etc/profile.d/mysql.sh PATH=/usr/local/mysql/bin:$PATH [iyunv@centos7 mysql]# . /etc/profile.d/mysql.sh 9 、安全初始化 [iyunv@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/
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.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> DocumentRoot "/app/httpd24/htdocs" 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> DocumentRoot "/app/httpd24/htdocs2" 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
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/
|