WordPress部署实现
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WordPress部署实现相关的知识,希望对你有一定的参考价值。
WordPress及phpMyadmin服务搭建
拓扑规划:
摘要信息 | IP地址 | 作用 | 系统版本 |
---|---|---|---|
nginx | 192.168.2.128 | 负载均衡,反向代理 | CentOS7.2 |
Apache+PHP5.6.36 | 192.168.2.129 | 解析wordpress,phpmyadmin动态页面 | CentOS7.2 |
Nginx+PHP5.6.36 | 192.168.2.130 | 解析wordpress,phpmyadmin动态页面 | CentOS7.2 |
Nginx+mysql | 192.168.2.133 | 解析静态页面,提供MySQL数据库 | CentOS7.2 |
目录顺序:
本次博客涉及所有程序包提供:链接:https://pan.baidu.com/s/1-xBK6Ti5IL_KxyQNjzKd1A
提取码:1ano
基础环境配置
1. 禁用iptables,selinux,配置epel源
2. 安装开发工具包
Centos7: yum groupinstall "Development Tools"
Centos6: yum groupinstall "Development Tools" "Server Platform Development"
192.168.2.128(调度器)配置:
安装pcre正则支持及openssl支持:
[[email protected] ~]# yum -y install pcre-devel openssl-devel
[[email protected] ~]# useradd -r nginx
编译参数:
[[email protected] nginx-1.14.2]# ./configure --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_flv_module --with-http_mp4_module --with-threads --with-file-aio
[[email protected] nginx-1.14.2]# make && make install
配置PATH:
[[email protected] nginx-1.14.2]# echo "export PATH=/usr/local/nginx/sbin:$PATH" >> /etc/profile.d/nginx.sh
[[email protected] nginx-1.14.2]# . /etc/profile.d/nginx.sh
配置nginx目录:
[[email protected] nginx-1.14.2]# mkdir -p /data/nginx
192.168.2.129(Apache+PHP)配置:
Httpd2.4.38编译安装:
(1) apr-1.50
[[email protected] apr-1.5.0]# ./configure --prefix=/usr/local/apr
[[email protected] apr-1.5.0]# make -j 4&& make install
(2) apr-util-1.5.3
[[email protected] apr-util-1.5.3]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[[email protected] apr-util-1.5.3]# make -j 4&& make install
(3) httpd-2.4.38
[[email protected] httpd-2.4.38]# yum install pcre-devel openssl-devel
worker,event模块:
[[email protected] httpd-2.4.38]# ./configure --prefix=/usr/local/apache24 --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event
注意:--with-mpm=xxx ##apahce有三种模型prefork,worker,event根据需要填写,但是需要注意的是如果是worker/event那么编译php时则需要添加 --enable-maintainer-zts 参数
[[email protected] httpd-2.4.38]# make -j 4 && make install
[[email protected] httpd-2.4.38]# echo "export PATH=/usr/local/apache24/bin:$PATH" >> /etc/profile.d/apache24.sh
[[email protected] httpd-2.4.38]# . /etc/profile.d/apache24.sh
添加php支持,准备测试页:
[[email protected] httpd-2.4.38]# vim /etc/httpd/httpd.conf
...
AddType application/x-httpd-php .php ##添加对.php文件的支持
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.html index.php ##配置默认识别主文件
</IfModule>
Options Indexes FollowSymLinks ##注释掉这一行,禁止显示apache目录表
...
配置php测试页面,配置远端数据库的连接信息
[[email protected] httpd-2.4.38]# vim /usr/local/apache24/htdocs/index.php
<?php
// 当数据库连接正常页面输出OK,否则Failure
$conn = mysql_connect(‘192.168.2.133‘,‘wordpress‘,‘123‘);
if ($conn)
echo "OK";
else
echo "Failure";
phpinfo();
?>
### 启动脚本:CentOS6复制epel安装脚本修改即可,7先用apachectl来管理
[[email protected] httpd-2.4.38]# apachectl start
编译安装的模块很少,在配置文件httpd.conf自行启用即可
Php5.6.36(DSO)编译安装:
###解决依赖关系
[[email protected] php-5.6.36]# yum install bzip2-devel libmcrypt-devel libxml2-devel -y
###编译安装PHP(DSO模式)
-- 安装M->P模式(php和MySQL不在一台主机时)
[[email protected] php-5.6.36]# ./configure --prefix=/usr/local/php --with-mysql --with-openssl --with-mysqli=mysqlnd --enable-mbstring --with-png-dir --with-jpeg-dir --with-freetype-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache24/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts
注意:
--enable-maintainer-zts 如果httpd编译的是prefork不需要该项,若为worker,event则需要
--with-apxs2 apxs是一个为Apache服务器编译和安装扩展模块的工具,DSO模式需要指定,FPM模式不需要
[[email protected] php-5.6.36]# make -j4 && make install
[[email protected] php-5.6.36]# echo "export PATH=/usr/local/php/bin:$PATH" > /etc/profile.d/php.sh
[[email protected] php-5.6.36]# . /etc/profile.d/php.sh
[[email protected] php-5.6.36]# httpd -M ##查看是否有libphp5模块,有则php编译完成
配置文件准备:
[[email protected] php-5.6.36]# cp php.ini-production /etc/php.ini
[[email protected] php-5.6.36]# mkdir -p /etc/php.d/
-- 安装M+P模式(php和MySQL在一台主机时)
# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-png-dir --with-jpeg-dir --with-freetype-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache24/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts
-- 关于PHP如何多版本共存:DSO+FPM两种形式存在,将编译目录稍加区分即可
# ./configure --prefix=/usr/local/php5 --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-png-dir --with-jpeg-dir --with-freetype-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php5 --with-bz2 --enable-fpm
xcache3.2.0编译安装:
### xcache准备:
[[email protected] xcache-3.2.0]# phpize --clean && phpize ##执行此步,生成configure文件
[[email protected] xcache-3.2.0]# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
[[email protected] xcache-3.2.0]# make -j4 && make install
注意:编译最后会得到so的地址:/usr/local/php/lib/php/extensions/no-debug-zts-20131226/xcache.so
### 将xcache的库添加到php扩展:
[[email protected] xcache-3.2.0]# mkdir /etc/php.d -p
[[email protected] xcache-3.2.0]# cp xcache.ini /etc/php.d/
### 修改xcache的.so的详细路径
[[email protected] xcache-3.2.0]# vim /etc/php.d/xcache.ini
...
extension = /usr/local/php/lib/php/extensions/no-debug-zts-20131226/xcache.so
xcache.admin.enable_auth = Off
xcache.size = 60M
...
### 编译完成重启apache或重载
[[email protected] xcache-3.2.0]# pkill httpd
[[email protected] xcache-3.2.0]# apachectl start
192.168.2.130(Nginx+PHP)配置:
Nginx1.14.2编译安装:
### 安装pcre正则支持及openssl支持:
[[email protected] nginx-1.14.2]# yum install -y pcre-devel openssl-devel
[[email protected] nginx-1.14.2]# useradd -r nginx
### 编译参数:
[[email protected] nginx-1.14.2]# ./configure --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_flv_module --with-http_mp4_module --with-threads --with-file-aio
[[email protected] nginx-1.14.2]# make && make install
### 配置PATH:
[[email protected] nginx-1.14.2]# echo "export PATH=/usr/local/nginx/sbin:$PATH" >> /etc/profile.d/nginx.sh
[[email protected] nginx-1.14.2]# . /etc/profile.d/nginx.sh
### 配置nginx目录:
[[email protected] nginx-1.14.2]# mkdir -p /data/nginx
PHP5.6.36(FPM)编译安装:
### 解决依赖关系:
[[email protected] php-5.6.36]# yum install bzip2-devel libmcrypt-devel libxml2-devel -y
### 编译参数:
[[email protected] php-5.6.36]# ./configure --prefix=/usr/local/php --with-mysql --with-openssl --with-mysqli=mysqlnd --enable-mbstring --with-png-dir --with-jpeg-dir --with-freetype-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php5 --with-bz2 --enable-fpm
[[email protected] php-5.6.36]# make -j4 && make install
### 配置PATH:
[[email protected] php-5.6.36]# echo "export PATH=/usr/local/php/bin:$PATH" > /etc/profile.d/php.sh
[[email protected] php-5.6.36]# . /etc/profile.d/php.sh
[[email protected] php-5.6.36]# httpd -M ##查看是否有libphp5模块,有则php编译完成
### 配置文件准备:
[[email protected] php-5.6.36]# cp php.ini-production /etc/php.ini
[[email protected] php-5.6.36]# mkdir -p /etc/php.d/
[[email protected] php-5.6.36]# cp sapi/fpm/php-fpm /usr/local/bin
[[email protected] php-5.6.36]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[[email protected] php-5.6.36]# mkdir -p /var/lib/php/session;chown -R nginx.nginx /var/lib/php/session
[[email protected] php-5.6.36]# vim /usr/local/php/etc/php-fpm.conf
...
[www]
listen = 127.0.0.1:9000 ##不建议对外开放,可以开放局域网,这里仅侦听127.0.0.1
listen.allowed_clients = 127.0.0.1
user = nginx ##以nginx用户启动,否则nginx无权访问fpm
group = nginx
pm = dynamic ##动态管理
slowlog = /var/log/php-fpm/www-slow.log
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session ##创建目录并赋予nginx权限
...
### 配置php测试页面,配置远端数据库的连接信息
[[email protected] httpd-2.4.38]# vim /data/nginx/index.php
<?php
// 当数据库连接正常页面输出OK,否则Failure
$conn = mysql_connect(‘192.168.2.133‘,‘wordpress‘,‘123‘);
if ($conn)
echo "OK";
else
echo "Failure";
phpinfo();
?>
192.168.2.133(Nginx+MySQL)配置:
Nginx1.14.2编译安装:
### 安装pcre正则支持及openssl支持:
[[email protected] nginx-1.14.2]# yum -y install pcre-devel openssl-devel
[[email protected] nginx-1.14.2]# useradd -r nginx
### 编译参数:
[[email protected] nginx-1.14.2]# ./configure --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_flv_module --with-http_mp4_module --with-threads --with-file-aio
[[email protected] nginx-1.14.2]# make -j4 && make install
### 配置PATH:
[[email protected] nginx-1.14.2]# echo "export PATH=/usr/local/nginx/sbin:$PATH" >> /etc/profile.d/nginx.sh
[[email protected] nginx-1.14.2]# . /etc/profile.d/nginx.sh
### 配置nginx目录:
[[email protected] nginx-1.14.2]# mkdir -p /data/nginx
MySQL5.6.36编译安装:
[[email protected] pkg]# tar xf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
[[email protected] local]# ln -s mysql-5.6.36-linux-glibc2.5-x86_64 mysql
[[email protected] local]# mkdir -pv /data/mysql
[[email protected] local]# useradd -r mysql
[[email protected] local]# chown -R mysql.mysql /usr/local/mysql-5.6.36-linux-glibc2.5-x86_64
[[email protected] local]# chown -R mysql.mysql /data/mysql
[[email protected] mysql]# ./scripts/mysql_install_db --datadir=/data/mysql/ --user=mysql
[[email protected] mysql]# cp support-files/my-default.cnf /etc/my.cnf ##my.cnf主要修改datadir,socket位置等常规选项
[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld ##改pid位置
[[email protected] mysql]# echo "export PATH=/usr/local/mysql/bin:$PATH" > /etc/profile.d/mysql.sh
[[email protected] mysql]# . /etc/profile.d/mysql.sh
[[email protected] mysql]# chkconfig --add mysqld
[[email protected] mysql]# service mysqld restart
[[email protected] mysql]# ln -sv /usr/local/mysql/mysql.sock /tmp/mysql.sock
[[email protected] mysql]# mysql_secure_installation ##初始化安全设置并配置root密码
[[email protected] mysql]# mysql -uroot -proot ##配置wordpress库及用户、密码
mysql> CREATE DATABASE wordpress;
mysql> GRANT ALL ON wordpress.* TO ‘wordpress‘@‘192.168.2.%‘ IDENTIFIED BY ‘123‘;
wordpress和phpadmin配置修改:
192.168.2.128
[[email protected] pkg]# unzip phpMyAdmin-4.8.5-all-languages.zip
[[email protected] pkg]# unzip wordpress-5.0.3-zh_CN.zip
### 配置phpMyadmin
[[email protected] pkg]# cd phpMyAdmin-4.8.5-all-languages
[[email protected] phpMyAdmin-4.8.5-all-languages]# cp config.sample.inc.php config.inc.php
[[email protected] phpMyAdmin-4.8.5-all-languages]# vim config.inc.php +17
...
$cfg[‘blowfish_secret‘] = ‘asfusd87fsdfgbsdfbkjsdfsd5513wefasdfbsuf763jwegfway6adgfa‘; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
$cfg[‘Servers‘][$i][‘host‘] = ‘192.168.2.133‘;
...
[[email protected] phpMyAdmin-4.8.5-all-languages]# mkdir tmp
[[email protected] phpMyAdmin-4.8.5-all-languages]# chmod 777 tmp
### 配置wordpress
[[email protected] pkg]# cd wordpress
[[email protected] wordpress]# cp wp-config-sample.php wp-config.php
[[email protected] wordpress]# vim wp-config.php
...
/** WordPress数据库的名称 */
define(‘DB_NAME‘, ‘wordpress‘);
/** MySQL数据库用户名 */
define(‘DB_USER‘, ‘wordpress‘);
/** MySQL数据库密码 */
define(‘DB_PASSWORD‘, ‘123‘);
/** MySQL主机 */
define(‘DB_HOST‘, ‘192.168.2.133‘);
...
### 将修改好的项目文件分别发给ap,np的Document目录
[[email protected] pkg]# rsync -az phpMyAdmin-4.8.5-all-languages wordpress [email protected]:/usr/local/apache24/htdocs/
[[email protected] pkg]# rsync -az phpMyAdmin-4.8.5-all-languages wordpress [email protected]:/data/nginx/
[[email protected] pkg]# rsync -az phpMyAdmin-4.8.5-all-languages wordpress [email protected]:/data/nginx/
配置各个组件配置信息:
### 192.168.2.128
[[email protected] ~]# vim /etc/nginx/nginx.conf
...
include conf.d/*.conf; ##在http标签内添加
upstream websrv_php { ##添加php动态解析服务器
#ip_hash;
server 192.168.2.129:80 weight=1;
server 192.168.2.130:80 weight=1;
}
upstream websrv_static { ##添加static静态文件解析服务器
server 192.168.2.133:80 weight=1;
}
...
[[email protected] ~]# mkdir /etc/nginx/conf.d/ ##创建虚拟主机目录
[[email protected] ~]# vim /etc/nginx/conf.d/upstream.conf
server {
listen 80;
server_name www.ifan.com;
root /data/nginx;
index index.html;
location ~* .(jpeg|gif|jpg|png|html|css)$ {
proxy_pass http://websrv_static;
}
location / {
proxy_pass http://websrv_php;
}
}
[[email protected] ~]# nginx -t ##没有报错,则下一步启动即可
[[email protected] ~]# nginx
## 配置192.168.2.129
ap主机我们就使用默认主机提供服务,注意上面配置ap主机时已经完成了index.php文件的默认识别及目录显示功能一关闭,若未进行配置则返回配置,以下只改名
[[email protected] htdocs]# mv phpMyAdmin-4.8.5-all-languages pam
[[email protected] htdocs]# mv wordpress blog
## 配置192.168.2.130
[[email protected] ~]# vim /etc/nginx/nginx.conf
...
include conf.d/*.conf; ##在http标签内添加
...
[[email protected] ~]# mkdir /etc/nginx/conf.d/ ##创建虚拟主机目录
[[email protected] ~]# vim /etc/nginx/conf.d/project.conf
server {
listen 80;
server_name www.ifan.com;
root /data/nginx;
index index.html index.php;
location / {
}
location ~* .php$ {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param SCRIPT_FILENAME /data/nginx$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
[[email protected] nginx]# mv phpMyAdmin-4.8.5-all-languages pam
[[email protected] nginx]# mv wordpress blog
[[email protected] nginx]# nginx -t && nginx
## 192.168.2.133
[[email protected] ~]# vim /etc/nginx/nginx.conf
...
include conf.d/*.conf; ##在http标签内添加
...
[[email protected] ~]# mkdir /etc/nginx/conf.d/ ##创建虚拟主机目录
[[email protected] ~]# vim /etc/nginx/conf.d/project.conf
server {
listen 80;
server_name www.ifan.com;
root /data/nginx;
index index.html index.php;
location / {
}
}
[[email protected] nginx]# mv phpMyAdmin-4.8.5-all-languages pam
[[email protected] nginx]# mv wordpress blog
[[email protected] nginx]# nginx -t && nginx
最终测试效果:
配置本地hosts信息:
cat /etc/hosts
...
192.168.2.128 www.ifan.com
...
测试效果:
由于Firefox和Chrom总是加载缓存,测试出效果很不易,我访问的是php的测试文件,正常页面会显示phpinfo的基本信息及php的扩展信息,这里可以看出我nginx设置的是基本轮询,可以根据需求设置成基于源地址绑定访问
访问blog系统:默认安装好不是这个界面,是需要自行配置的界面
访问pam系统:
这个并非错误,原因是使用负载均衡轮询的时候,第一次请求phpMyAdmin主页的时ap进行处理,页面返回的cookie存放在ap上.填写用户名密码提交之后,是np进行处理的,此时给页面的cookie不是ap上的cookie,所以会报错,解决方案很简单,在nginx代理时使用 ip_hash 即可(配置文件中我已添加,只需要打开即可注释即可)
查看192.168.2.133Nginx日志,均是静态页面的访问:
总结:
- 篇幅较大,此次操作主要以记录和实践为主,并非生产环境使用
- 编译参数并非一定要指定,默认编译会自动寻找,但若依赖是编译安装则需要指定详细路径
- 对于服务的安装,推荐一切从简,以RPM包的形式安装,若非必要不建议参考本篇文章进行编译安装
- 对于Apache和Nginx大部分未做安全和优化,后期会对Nginx的优化篇专门形成一篇文档进行分享
- 目前本篇文档仅仅添加了xcache,对于目前代理层前端仍然可以增加一层varnish缓存层
以上是关于WordPress部署实现的主要内容,如果未能解决你的问题,请参考以下文章
Wordpress - 将代码片段包含到布局的选定部分的插件
PHP WordPress条件为主页SlideDeck主题代码片段
Wordpress阻止访问wp admin€“wpsnipp.com网站你博客的Wordpress代码片段