搭建php-fpm工作方式的LAMP环境,实现wordpress正常访问
1、搭建php-fpm工作方式的LAMP环境,实现wordpress正常访问
实验环境
系统:CentOS7
IP:192.168.253.128
http版本:2.4
关闭防火墙和selinux
systemctl stop firewalld
setenforce 0
安装httpd2.4
cd /usr/local/src
wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.34.tar.gz ##这是官网的httpd2.4tar包地址
wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.6.3.tar.gz ##官网的apr包
wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz ##官网的apr-util地址
tar -xf apr-1.6.3.tar.gz
tar -xf apr-util-1.6.1.tar.gz
tar -xf httpd-2.4.34.tar.gz
mv apr-1.6.3 /usr/local/src/httpd-2.4.34/srclib/apr
mv apr-util-1.6.1 /usr/local/src/httpd-2.4.34/srclib/apr-util
cd httpd-2.4.34
yum install pcre pcre-devel openssl openssl-devel gcc gcc-devel gcc-c++ expat-devel -y
./configure –prefix=/usr/local/apache2.4 –enable-so –enable-ssl –enable-cgi –enable-rewrite –with-zlib –enable-modules=most –enable-mpms-shared=all –with-mpm=prefork –with-included-apr
make && make install
chown -R apache:apache /usr/local/apache2.4/
ln -sv /usr/local/apache2.4/ /usr/local/apache
PATH=/usr/local/apache2.4/bin/:$PATH
echo ‘PATH=/usr/local/apache2.4/bin/:$PATH’ > /etc/profile.d/httpd.sh
useradd -M -s /sbin/nologin apache
设置虚拟主机
创建站点目录
mkdir -pv /www/wordpress echo “Hello world” > /www/wordpress/index.html
chown -R apache:apache /www
备份一下原始的文件/usr/local/apache/conf/extra/httpd-vhosts.conf
cp /usr/local/apache/conf/extra/httpd-vhosts.conf{,.bak}
修改配置文件/usr/local/apache/conf/extra/httpd-vhosts.conf
<VirtualHost 192.168.253.128:80>
ServerAdmin webmaster@wordpress.com
DocumentRoot “/www/wordpress”
ErrorLog “logs/wordpress-error_log”
CustomLog “logs/wordpress-access_log” common
</VirtualHost>
修改主配置文件vim /usr/local/apache/conf/httpd.conf
ServerName 192.168.253.128
User apache Group apache
Include conf/extra/httpd-vhosts.conf ##取消这一行注释‘
<Directory “/www/wordpress”>
Options None
AllowOverride none
Require all granted DirectoryIndex index.php index.html
</Directory>
检查一下配置文件,并启动服务
httpd -t httpd -k start
测试一下,可以正常访问 。apache部分准备好了
编译安装php并设置php-fpm连接
首先下载php的tar包 ,可以在官网找
这里用的版本是php-7.0.31.tar.gz
cd /usr/local/src/
tar -zxf php-7.0.31.tar.gz
cd php-7.0.31
yum install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel bzip2 bzip2-devel
./configure –prefix=/usr/local/php7.0 –with-openssl –enable-mbstring –with-png-dir –with-jpeg-dir –with-freetype-dir –with-zlib –with-libxml-dir=/usr –enable-xml –enable-sockets –with-bz2 –with-mysql=mysqlnd –enable-fpm
make && make install
cp /usr/local/src/php-7.0.31/php.ini-production /usr/local/php7.0/lib/php.ini
cp /usr/local/php7.0/etc/php-fpm.conf.default /usr/local/php7.0/etc/php-fpm.conf
cp /usr/local/php7.0/etc/php-fpm.d/www.conf.default /usr/local/php7.0/etc/php-fpm.d/www.conf
ln -sv /usr/local/php7.0 /usr/local/php
PATH=”/usr/local/php/sbin/:$PATH”
chown -R apache.apache /usr/local/php7.0
启动php-fpm
接下来设置httpd与php的连接
修改apache主配置文件
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so 取消注释
LoadModule proxy_module modules/mod_proxy.so 取消注释
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/www/wordpress/
写一个测试页面
echo -e “<?php\nphpinfo();\n?>”> /www/wordpress/index.php
检查一下配置文件并重启服务
httpd -t httpd -k restart
Mysql部分
这里mysql直接使用二进制包
官网可以找到 版本为5.6.39
wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz
useradd -M -s /sbin/nologin mysql
cd /usr/local/src
tar -xf mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.27-linux-glibc2.12-x86_64 /usr/local/mysql5.7
chown -R mysql.mysql /usr/local/mysql5.7
ln -sv /usr/local/mysql5.7/ /usr/local/mysql
/usr/local/mysql/scripts/mysql_install_db –user=mysql –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data/
PATH=/usr/local/mysql/bin/:$PATH
echo ‘PATH=”/usr/local/mysql/bin/:$PATH”‘ > /etc/profile.d/mysql.sh
启动数据库
mysqld_safe –defaults-file=/usr/local/mysql/my.cnf &
进行一下安全设置
mysql_secure_installation
进入数据库,创建对应的库
mysql -uroot -p ##进入数据库
在数据库中
create database wordpress; ##创建对应的库
grant all on wordpress.* to ‘wordpress’@’127.0.0.1’ identified by ‘wordpress’; ##创建给用户给wordpress连接,账号密码都是wordpress
安装wordpress
下载地址
mv /www/wordpress/* /tmp/ #将之前的测试文件移除
cd /usr/local/src wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz
tar -xf wordpress-4.9.4-zh_CN.tar.gz cp -a wordpress/* /www/wordpress/
chown -R apache:apache /www
然后进入页面配置一下。