- CentOS 7.3环境LAMP源码编译安装WordPress
- CentOS 6.9环境LAMP源码编译安装WordPress(php module模式)
- CentOS 6.9环境LAMP源码编译安装WordPress(php fpm模式)
一、CentOS 7.3环境LAMP源码编译安装WordPress
(一)环境准备
搭建环境:
主机1:负责httpd, php, wordpress (IP: 192.168.136.130)
主机2:负责MariaDB (IP: 192.168.136.230)软件环境:
apr-1.6.2.tar.gz
apr-util-1.6.0.tar.gz
httpd-2.4.27.tar.bz2
php-7.1.10.tar.xz
wordpress-4.8.1-zh_CN.tar.gz
mariadb-10.2.8-linux-x86_64.tar.gz
(二)源码编译安装httpd2.4
- 安装开发环境
yum groupinstall "development tools"
yum install openssl-devel expat-devel pcre-devel
- 解压缩源码包
tar xvf apr-1.6.2.tar.gz -C /usr/local/src
tar xvf apr-util-1.6.0.tar.gz -C /usr/local/src
tar xvf httpd-2.4.27.tar.bz -C /usr/local/src
cd /usr/local/src
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 --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --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
apachectl start
ss -ntlp
- 设置开机启动脚本
vim /etc/rc.d/rc.local
/app/httpd24/bin/apachectl start
chmod +x /etc/rc.d/rc.local
- 设置帮助文件路径
vim /etc/man_db.conf
MANDATORY_MANPATH /app/httpd24/man
(三)二进制安装MariaDB
- 解压缩二进制包至指定目录
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/ mysql
- 安装数据库
useradd -r -d /app/mysqldb -s /sbin/nologin mysql -m
cd mysql/
scripts/mysql_install_db --datadir=/app/mysqldb --user=mysql
- 编辑配置文件
mkdir /etc/mysql
cp support-files/my-large.cnf /etc/mysql/my.cnf
vim /etc/mysql/my.cnf
[mysqld] //添加以下三行
datadir = /app/mysqldb
innodb_file_per_table = ON
skip_name_resolve = ON
- 设置启动脚本
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --list mysqld
- 设置日志目录,并启动服务
mkdir /var/log/mariadb
chown mysql /var/log/mariadb/
service mysqld start
ss -ntlp
- 设置环境变量
vim /etc/profile.d/lamp.sh
PATH=/usr/local/mysql/bin:$PATH
source /etc/profile.d/lamp.sh
- 配置数据库,建立WordPress的数据库
mysql_secure_installation
mysql -uroot -p
MariaDB [(none)]> create database wpdb;
MariaDB [(none)]> grant all on wpdb.* to wpadmin@'192.168.136.%' identified by 'centos';
MariaDB [(none)]> grant all on wpdb.* to wpadmin@'127.%' identified by 'centos';
MariaDB [(none)]> grant all on wpdb.* to wpadmin@'localhost' identified by 'centos';
(四)源码编译安装php
- 编译环境准备
yum install libxml2-devel bzip2-devel libmcrypt-devel
tar xvf php-7.1.10.tar.xz -C /usr/local/src/
cd /usr/local/src/php-7.1.10/
- 编译安装
./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 --with-apxs2=/app/httpd24/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-maintainer-zts --disable-fileinfo
make -j 4 && make install
- 编辑配置文件
cp php.ini-production /etc/php.ini
vim /etc/httpd24/httpd.conf
// 在文件尾部加两行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
// 修改下面行
DirectoryIndex index.php index.html
apachectl stop
apachectl start
ss -ntlp
(五)测试php与MariaDB的连接
vim /app/httpd24/htdocs/index.php
close();
phpinfo();
?>
(六)安装配置WordPress
- 解压缩软件包至网页存放目录
tar -xvf wordpress-4.8.1-zh_CN.tar.gz -C /app/httpd24/htdocs/
cd /app/httpd24/htdocs/
ln -s wordpress/ blog
cd blog/
- 编辑安装配置文件
cp wp-config-sample.php wp-config.php
vim wp-config.php
// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
/** WordPress数据库的名称 */
define('DB_NAME', 'wpdb');
/** MySQL数据库用户名 */
define('DB_USER', 'wpadmin');
/** MySQL数据库密码 */
define('DB_PASSWORD', 'centos');
/** MySQL主机 */
define('DB_HOST', '192.168.136.230');
- 浏览器打开
http://192.168.136.130/blog/
,按照提示填入信息开始安装
- WordPress安装成功后,博客显示界面
- ab测试性能
ab -c 10 -n 100 http://192.168.136.130/blog/
二、CentOS 6.9环境LAMP源码编译安装WordPress(php module模式)
(一)环境准备
搭建环境:
主机1:负责httpd, php, wordpress (IP: 192.168.136.129)
主机2:负责MariaDB (IP: 192.168.136.229)软件环境:
apr-1.6.2.tar.gz
apr-util-1.6.0.tar.gz
httpd-2.4.27.tar.bz2
php-5.6.4.tar.xz
xcache-3.2.0.tar.bz2
wordpress-4.8.1-zh_CN.tar.gz
mariadb-5.5.57-linux-x86_64.tar.gz
(二)源码编译安装httpd2.4
- 安装开发环境
yum groupinstall "development tools"
yum install openssl-devel expat-devel pcre-devel
- 解压缩源码包
tar xvf apr-1.6.2.tar.gz -C /usr/local/src
tar xvf apr-util-1.6.0.tar.gz -C /usr/local/src
tar xvf httpd-2.4.27.tar.bz -C /usr/local/src
cd /usr/local/src
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-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
- 设置启动脚本
scp /etc/init.d/httpd 192.168.136.129:/etc/init.d/httpd24 //从其他主机复制脚本进行修改
vim /etc/init.d/httpd24
apachectl=/app/httpd24/bin/apachectl
httpd=${HTTPD-/app/httpd24/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/app/httpd24/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}
chkconfig --add httpd24
chkconfig --list httpd24
service httpd24 start
ss -ntlp
- 设置帮助文件路径
vim /etc/man.config
MANPATH /app/httpd24/man
(三)二进制安装MariaDB
- 解压缩二进制包至指定目录
tar xvf mariadb-5.5.57-linux-x86_64.tar.gz -C /usr/local
cd /usr/local/
ln -s mariadb-5.5.57-linux-x86_64/ mysql
- 安装数据库
useradd -r -d /app/mysqldb -s /sbin/nologin mysql -m
cd mysql/
scripts/mysql_install_db --datadir=/app/mysqldb --user=mysql
- 编辑配置文件
mkdir /etc/mysql
cp support-files/my-large.cnf /etc/mysql/my.cnf
vim /etc/mysql/my.cnf
[mysqld] //添加以下三行
datadir = /app/mysqldb
innodb_file_per_table = ON
skip_name_resolve = ON
- 设置启动脚本
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --list mysqld
- 设置日志目录,并启动服务
touch /var/log/mysqld.log
chown mysql /var/log/mysqld.log
service mysqld start
ss -ntlp
- 设置环境变量
vim /etc/profile.d/lamp.sh
PATH=/usr/local/mysql/bin:$PATH
source /etc/profile.d/lamp.sh
- 配置数据库,建立WordPress的数据库
mysql_secure_installation
mysql -uroot -p
MariaDB [(none)]> create database wpdb;
MariaDB [(none)]> grant all on wpdb.* to wpadmin@'192.168.136.%' identified by 'centos';
MariaDB [(none)]> grant all on wpdb.* to wpadmin@'127.%' identified by 'centos';
MariaDB [(none)]> grant all on wpdb.* to wpadmin@'localhost' identified by 'centos';
(四)源码编译安装php
- 编译环境准备
yum install libxml2-devel bzip2-devel libmcrypt-devel
tar xvf php-5.6.4.tar.xz -C /usr/local/src/
cd /usr/local/src/php-5.6.4/
- 编译安装
./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 --with-apxs2=/app/httpd24/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-maintainer-zts --disable-fileinfo
make -j 4 && make install
- 设置环境变量
vim /etc/profile.d/lamp.sh
PATH=/app/php/bin:/app/httpd24/bin:$PATH
source /etc/profile.d/lamp.sh
- 编辑配置文件
cp php.ini-production /etc/php.ini
vim /app/httpd24/conf/httpd.conf
// 在文件尾部加两行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
// 修改下面行
DirectoryIndex index.php index.html
service httpd24 restart
ss -ntlp
(五)测试php与MariaDB的连接
vim /app/httpd24/htdocs/index.php
close();
phpinfo();
?>
(六)安装配置WordPress
- 解压缩软件包至网页存放目录
tar -xvf wordpress-4.8.1-zh_CN.tar.gz -C /app/httpd24/htdocs/
cd /app/httpd24/htdocs/
ln -s wordpress/ blog
cd blog/
- 编辑安装配置文件
cp wp-config-sample.php wp-config.php
vim wp-config.php
// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
/** WordPress数据库的名称 */
define('DB_NAME', 'wpdb');
/** MySQL数据库用户名 */
define('DB_USER', 'wpadmin');
/** MySQL数据库密码 */
define('DB_PASSWORD', 'centos');
/** MySQL主机 */
define('DB_HOST', '192.168.136.229');
- 浏览器打开
http://192.168.136.129/blog/
,按照提示填入信息开始安装
- WordPress安装成功后,博客显示界面
- ab测试性能
ab -c 10 -n 100 http://192.168.136.129/blog/
(七)编译安装xcache
- 解压缩源码包
tar xvf xcache-3.2.0.tar.bz2 -C /usr/local/src
cd /usr/local/src/xcache-3.2.0/
- 编译安装
phpize //生成configure文件
./configure --enable-xcache --with-php-config=/app/php/bin/php-config
make && make install
- 安装后配置
mkdir /etc/php.d
cp xcache.ini /etc/php.d/
vim /etc/php.d/xcache.ini
extension = /app/php/lib/php/extensions/no-debug-zts-20131226/xcache.so
service httpd24 restart
- ab测试性能
ab -c 10 -n 100 http://192.168.136.129/blog/
三、CentOS 6.9环境LAMP源码编译安装WordPress(php fpm模式)
(一)环境准备
搭建环境:
主机1:负责httpd, php, wordpress (IP: 192.168.136.129)
主机2:负责MariaDB (IP: 192.168.136.229)软件环境:
apr-1.6.2.tar.gz
apr-util-1.6.0.tar.gz
httpd-2.4.27.tar.bz2
php-5.6.4.tar.xz
xcache-3.2.0.tar.bz2
wordpress-4.8.1-zh_CN.tar.gz
mariadb-5.5.57-linux-x86_64.tar.gz
(二)源码编译安装httpd2.4
- 安装开发环境
yum groupinstall "development tools"
yum install openssl-devel expat-devel pcre-devel
- 解压缩源码包
tar xvf apr-1.6.2.tar.gz -C /usr/local/src
tar xvf apr-util-1.6.0.tar.gz -C /usr/local/src
tar xvf httpd-2.4.27.tar.bz -C /usr/local/src
cd /usr/local/src
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-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
- 设置启动脚本
scp /etc/init.d/httpd 192.168.136.129:/etc/init.d/httpd24 //从其他主机复制脚本进行修改
vim /etc/init.d/httpd24
apachectl=/app/httpd24/bin/apachectl
httpd=${HTTPD-/app/httpd24/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/app/httpd24/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}
chkconfig --add httpd24
chkconfig --list httpd24
service httpd24 start
ss -ntlp
- 设置帮助文件路径
vim /etc/man.config
MANPATH /app/httpd24/man
(三)二进制安装MariaDB
- 解压缩二进制包至指定目录
tar xvf mariadb-5.5.57-linux-x86_64.tar.gz -C /usr/local
cd /usr/local/
ln -s mariadb-5.5.57-linux-x86_64/ mysql
- 安装数据库
useradd -r -d /app/mysqldb -s /sbin/nologin mysql -m
cd mysql/
scripts/mysql_install_db --datadir=/app/mysqldb --user=mysql
- 编辑配置文件
mkdir /etc/mysql
cp support-files/my-large.cnf /etc/mysql/my.cnf
vim /etc/mysql/my.cnf
[mysqld] //添加以下三行
datadir = /app/mysqldb
innodb_file_per_table = ON
skip_name_resolve = ON
- 设置启动脚本
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --list mysqld
- 设置日志目录,并启动服务
touch /var/log/mysqld.log
chown mysql /var/log/mysqld.log
service mysqld start
ss -ntlp
- 设置环境变量
vim /etc/profile.d/lamp.sh
PATH=/usr/local/mysql/bin:$PATH
source /etc/profile.d/lamp.sh
- 配置数据库,建立WordPress的数据库
mysql_secure_installation
mysql -uroot -p
MariaDB [(none)]> create database wpdb;
MariaDB [(none)]> grant all on wpdb.* to wpadmin@'192.168.136.%' identified by 'centos';
MariaDB [(none)]> grant all on wpdb.* to wpadmin@'127.%' identified by 'centos';
MariaDB [(none)]> grant all on wpdb.* to wpadmin@'localhost' identified by 'centos';
(四)源码编译安装php
- 编译环境准备
yum install libxml2-devel bzip2-devel libmcrypt-devel
tar xvf php-5.6.4.tar.xz -C /usr/local/src/
cd /usr/local/src/php-5.6.4/
- 编译安装
./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
make -j 4 && make install
- 设置环境变量
vim /etc/profile.d/lamp.sh
PATH=/app/php/bin:/app/httpd24/bin:$PATH
source /etc/profile.d/lamp.sh
- 配置启动脚本
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
- 编辑配置文件
cp php.ini-production /etc/php.ini
cd /app/php/etc/
cp php-fpm.conf.default php-fpm.conf
vim /app/httpd24/conf/httpd.conf
// 取消两行的注释
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
// 在文件尾部加两行
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
// 修改下面行
DirectoryIndex index.php index.html
service php-fpm start
service httpd24 restart
ss -ntlp
(五)测试php与MariaDB的连接
vim /app/httpd24/htdocs/index.php
close();
phpinfo();
?>
(六)安装配置WordPress
- 解压缩软件包至网页存放目录
tar -xvf wordpress-4.8.1-zh_CN.tar.gz -C /app/httpd24/htdocs/
cd /app/httpd24/htdocs/
ln -s wordpress/ blog
cd blog/
- 编辑安装配置文件
cp wp-config-sample.php wp-config.php
vim wp-config.php
// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
/** WordPress数据库的名称 */
define('DB_NAME', 'wpdb');
/** MySQL数据库用户名 */
define('DB_USER', 'wpadmin');
/** MySQL数据库密码 */
define('DB_PASSWORD', 'centos');
/** MySQL主机 */
define('DB_HOST', '192.168.136.229');
浏览器打开
http://192.168.136.129/blog/
,按照提示填入信息开始安装ab测试性能
ab -c 10 -n 100 http://192.168.136.129/blog/
(七)编译安装xcache
- 解压缩源码包
tar xvf xcache-3.2.0.tar.bz2 -C /usr/local/src
cd /usr/local/src/xcache-3.2.0/
- 编译安装
phpize //生成configure文件
./configure --enable-xcache --with-php-config=/app/php/bin/php-config
make && make install
- 安装后配置
mkdir /etc/php.d
cp xcache.ini /etc/php.d/
vim /etc/php.d/xcache.ini
extension = /app/php/lib/php/extensions/no-debug-zts-20131226/xcache.so
service php-fpm restart
- ab测试性能
ab -c 10 -n 100 http://192.168.136.129/blog/
由此看到:在php_fpm模式下,使用xcache加速效率提升非常明显