在centos6上实现编译安装lamp和wordpress,并编译xcache

时间:2021-08-25 07:54:35

author:JevonWei

版权声明:原创作品


软件环境:

centos6.9
httpd-2.4.27.tar.bz2
apr-1.5.2.tar.bz2
apr-util-1.5.4.tar.bz2
mariadb-5.5.57-linux-x86_64.tar.gz
php-5.6.31.tar.bz2
wordpress-4.8-zh_CN.tar.gz
xcache-3.2.0.tar.bz2

编译安装httpd-2.4.27

yum groupinstall "Development Tools" -y
yum install pcre-devel openssl-devel 下载相关文件到/root/src目录下
tar xvf apr-1.5.2.tar.bz2
tar xvf apr-util-1.5.4.tar.bz2
tar xvf httpd-2.4.27.tar.bz2
mv apr-1.5.2/ httpd-2.4.27/srclib/apr
mv apr-util-1.5.4/ 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 && make install 或者下面方法
tar xvf apr-1.5.2.tar.bz2
cd apr-1.5.2
./configure --prefix=/app/apr
make && make install tar xvf apr-util-1.5.4.tar.bz2
cd apr-util-1.5.4
./configure --prefix=/app/apr-util --with-apr=/app/apr
make && make install tar xvf httpd-2.4.27.tar.bz2
cd httpd-2.4.27 ./configure --prefix=/app/httpd24 --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/app/apr --with-apr-util=/app/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event
make && make install 配置环境变量
vim /etc/profile.d/app.sh
export PATH=/app/httpd24/bin:$PATH
. /etc/profile.d/app.sh 参考httpd-2.2创建服务脚本
cd /etc/rc.d/init.d/
cp httpd httpd24
vim 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 -ntl
httpd -M 查看
mpm_prefork module(share)或者mpm_event_module(shared)

二进制安装mariadb-5.5.57

rpm –qa “mysql*”
yum remove mysql* 下载mariadb-5.5.57-linux-x86_64
tar xvf mariadb-5.5.57-linux-x86_64 -C /usr/local
注意:建议使用/usr/local,编译安装时的默认路径,否则后续很多配置要指定新路径 id mysql
如果不存在mysql用户
useradd –r -m –s /sbin/nlogin –d /app/mysqldb mysql 如果存在 Mysql用户
mkdir /app/mysqldb
chown mysql.mysql /app/mysqldb cd /usr/local
ln -s mariadb-5.5.57-linux-x86_64/ mysql
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 即
[mysqld]
datadir = /app/mysqldb
innodb_file_per_table = on
skip_name_resolve = on 生成mysqld服务脚本
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
service mysqld start touch /var/log/mysqld.log
chown mysql /var/log/mysqld.log vim /etc/profile.d/app.sh
export PATH=/usr/local/mysql/bin/:/app/httpd24/bin:$PATH
. /etc/profile.d/app.sh
mysql \\用mysql命令测试, 登录成功 mysql_secure_installation \\实现安全,设置root口令 创建wordpress使用的数据库和用户及权限
mysql -uroot -pdanran -e "create database blogdb; grant all on blogdb.* to blog@'localhost' identified by 'blog';" 测试验证登录成功
mysql -blog -pblog

编译安装php

下载 php-5.6.31.tar.bz2
tar xvf php-5.6.31.tar.bz2
cd php-5.6.31
yum -y install bzip2-devel libxml2-devel libmcrypt-devel(epel源) ./configure --prefix=/app/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --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 --with-bz2 说明:
./configure
--prefix=/app/php
--with-mysql=/usr/local/mysql
--with-openssl
--with-mysqli=/usr/local/mysql/bin/mysql_config
--enable-mbstring
--with-freetype-dir 字体格式
--with-jpeg-dir
--with-png-dir
--with-zlib压缩
--with-libxml-dir=/usr 支持文档xml
--enable-xml
--enable-sockets socket通信
--with-apxs2=/app/httpd24/bin/apxs 将Php编译成apache的模块
--with-mcrypt
--with-config-file-path=/etc php配置文件路径
--with-config-file-scan-dir=/etc/php.d
--with-bz2 --enable-maintainer-zts 用于支持worker和event模块,如果prefork不需要 make -j 4 && make install cp php.ini-production /etc/php.ini

配置httpd2.4支持php

vim /app/httpd24/conf/httpd.conf
加二行
AddType application/x-httpd-php .php
Addtype application/x-httpd-php-source .phps 修改
DirectoryIndex index.html
为下面行
DirectoryIndex index.php index.html apachectl stop
apachectl start

测试访问

vim /app/httpd24/htdocs/index.php
<?php
$conn=mysql_connect('127.0.0.1','blog','blog');
if($conn)
echo "OK";
else
echo "Not OK";
mysql_close();
phpinfo();
?>

安装wordpress

tar xvf  wordpress-4.8-zh_CN.tar.gz
mv wordpress /app/httpd24/htdocs/blog/
cd /app/httpd24/htdocs/blog/
cp wp-config-sample.php wp-config.php
vim wp-config.php
define('DB_NAME', 'blogdb');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'magedu');
define('DB_HOST', 'localhost'); http://172.16.253.166/blog 登录成功

测试性能

观察下面命令的结果:
ab -c 10 -n 100 http://websrv/blog/

编译安装xcache

下载xcache-3.2.0.tar.bz2
tar xf xcache-3.2.0.tar.bz2
cd xcache-3.2.0 /app/php/bin/phpize 生成编译环境.configure脚本
./configure --enable-xcache --with-php-config=/app/php/bin/php-config
make && make install
注意最后结果的一行目录
ls /app/php/lib/php/extensions/no-debug-non-zts-20131226/xcache.so mkdir /etc/php.d/
cp xcache.ini /etc/php.d/
vim /etc/php.d/xcache.ini
[xcache-common]
修改
extension = /app/php/lib/php/extensions/no-debug-non-zts-20131226/xcache.so service httpd24 restart

测试性能

http://localhost/ 在后面可以看到xcache的信息
观察下面命令的结果:性能有提高
ab -c 10 -n 100 http://172.16.253.166/pma/index.php

实验:在centos6上配置以fpm方式的php

在上一个实验基础上实现本实验

软件环境:

centos6.9
httpd-2.4.27.tar.bz2
apr-1.5.2.tar.bz2
apr-util-1.5.4.tar.bz2
mariadb-5.5.57-linux-x86_64.tar.gz
php-5.6.31.tar.bz2
wordpress-4.8-zh_CN.tar.gz
xcache-3.2.0.tar.bz2

先在centos6上编译安装httpd2.4和mariadb二进制方式

先删除前面实验的php信息
rm -rf /root/src/php*
和前面实验的步骤一样,先httpd24 mysql,再做下面步骤:

编译安装php

yum -y install bzip2-devel  libxml2-devel libmcrypt-devel(epel源)
tar xvf php-5.6.31.tar.bz2
cd php-5.6.31/ 为防止和上面实验冲突,修改下面的相关路径
./configure --prefix=/app/php5 --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --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/php5 --with-config-file-scan-dir=/etc/php5.d --with-bz2 make -j 4 && make install

实现php的配置文件和服务脚本

mkdir /etc/php5  /etc/php5.d/
cp php.ini-production /etc/php5/php.ini cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
chmod +x /etc/rc.d/init.d/php-fpm
chkconfig --add php-fpm
chkconfig --list php-fpm cd /app/php5/etc
cp php-fpm.conf.default php-fpm.conf 编辑php配置文件,可不做修改
vim /app/php5/etc/php-fpm.conf
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 5 和pm.start_servers一致
pid = /app/php5/var/run/php-fpm.pid service php-fpm start
ps aux|grep fpm
netstat -ntl

修改httpd24的配置文件

service httpd24 stop

cp /app/httpd24/conf/httpd.conf  /app/httpd24/conf/httpd.conf.bak \\备份配置文件
vim /app/httpd24/conf/httpd.conf 去掉下面两行注释
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
\\ 说明:启用httpd的相关模块
在Apache httpd 2.4以后已经专门有一个模块针对FastCGI的实现,此模块为mod_proxy_fcgi.so,它其实是作为mod_proxy.so模块的扩充,因此,这两个模块都要加载 添加如下二行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps 定位至DirectoryIndex index.html
修改为:
DirectoryIndex index.php index.html <IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule> 加下面两行,全局任意位置,如最后
ProxyRequests Off 关闭正向代理
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/app/httpd24/htdocs/$1 \\ProxyPassMatch:把以.php结尾的文件请求发送到php-fpm进程,php-fpm至少需要知道运行的目录和URI,所以这里直接在fcgi://127.0.0.1:9000后指明了这两个参数,其它的参数的传递已经被mod_proxy_fcgi.so进行了封装,不需要手动指定。 httpd -t
httpd –M
service httpd24 restart

生成测试页

vim /app/apache24/htdocs/index.php
如下:
<?php
$link = mysql_connect('127.0.0.1','blog','blog');
if ($link)
echo "Success...";
else
echo "Failure...";
mysql_close();
phpinfo();
?> http://websrv/index.php 成功 ,但没有xcache信息 观察下面命令的结果:Requests per second:没有xcache加速
ab -c 100 -n 1000 http://websrv/index.php

编译安装xcache实现加速

tar xf xcache-3.2.0.tar.bz2
cd xcache-3.2.0/
/app/php5/bin/phpize 生成编译环境.configure脚本
./configure --enable-xcache --with-php-config=/app/php5/bin/php-config
make && make install 注意最后结果的一行目录
ls /app/php5/lib/php/extensions/no-debug-non-zts-20131226 cp xcache.ini /etc/php5.d/
vim /etc/php5.d/xcache.ini
[xcache-common]
修改
extension = /app/php5/lib/php/extensions/no-debug-non-zts-20131226/xcache.so service php-fpm restart
\\ 注意:不需要重启httpd服务
ps aux |grep php 查看php进程
http://localhost/ 在后面可以看到xcache的信息