1 准备环境,两台主机:
一台: httpd, php 192.168.21.104
安装包存放路径: /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.106
安装包存放路径:/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-devel
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
把解压后的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/
./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-apr
#make -j 4 && make install
环境变量 #echo 'PATH=/app/httpd24/bin:$PATH' > /etc/profile.d/lamp.sh #source /etc/profile.d/lamp.sh
创建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
方法 二
.==================================================================
- 编写启动脚本 #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
-
加入系统服务: #chmod a+x httpd #cp -arf httpd /etc/init.d/
-
启动自己编写的服务: #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/