编译搭建基于LAMP的博客网站
用手工编译的方法搭建的LAMP环境支持自定义路径、各种功能启用等,而且性能要明显高于yum源安装的环境(亲测),本节将记录
笔者亲自编译搭建lamp博客的全过程
0-实验前准备:
a、关闭selinux;关闭防火墙;确保网络环境畅通;
b、从各官网下载源码包要求生产环境稳定版,且操作系统版本为Centos6.x,源码包可参考以下
c、由于php依赖于http服务,也需要和数据库结合,故我们编译安装的顺序为http---mariadb---php前两者顺序无所谓,但php
需要在最后安装部署
1-编译安装http服务:
tar xvf apr-1.6.2.tar.gz
tar xvf apr-util-1.6.0.tar.gz
tar -xvf httpd-2.4.27.tar.bz2
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
yum groupinstall "development tools"
yum install openssl-devel expat-devel pcre-devel
cd httpd-2.4.27
./configure --prefix=/app/httpd24 \
--enable-so \
--enable-ssl \
--enable-rewrite \
--with-zlib \
--with-pcre \
-with-included-apr \
--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
cp /etc/init.d/httpd /etc/init.d/httpd24
vim /etc/init.d/httpd24
chkconfig --add httpd24
service httpd24 restart
ss -ntl 看到80端口已经打开
到此 ok httpd服务已经成功搭建完成
2-二进制安装搭建数据库
tar xvf mariadb-5.5.57-linux-x86_64.tar.gz -C /usr/local/
ln -s mariadb-5.5.57-linux-x86_64/ mysql
vim /etc/profile.d/lamp.sh
PATH=/usr/local/mysql/bin/:/app/httpd24/bin/:$PATH
. /etc/profile.d/lamp.sh
useradd -r -m -d /app/mysqldb -s /sbin/nologin mysql
scripts/mysql_install_db --datadir=/app/mysqldb --user=mysql
cp support-files/my-huge.cnf /etc/mysql/my.cnf
vim /etc/mysql/my.cnf
chkconfig --add mysqld
touch /var/log/mysqld.log
chown mysql /var/log/mysqld.log
ss -ntl
mysql_secure_installation
create dababase wpdb;
grant all on wpdb.* to wpuser@'localhost' identified by 'centos'
3-编译安装部署php环境
yum install libxml2-devel bzip2-devel libmcrypt-devel
tar xvf php-5.6.31.tar.xz
cd php-5.6.31
./configure --prefix=/app/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=/app/httpd24/bin/apxs \
--with-mcrypt \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--with-bz2
make -j 4 && make install
vim /etc/profile.d/lamp.sh
PATH=/app/php/bin:/app/httpd24/bin/:/usr/local/mysql/bin/:$PATH
. /etc/profile.d/lamp.sh
cp php.ini-production /etc/php.ini
vim /app/httpd24/httpd.conf(在文件尾部加两行)
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
修改下面行
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
service httpd24 restart
php安装编译完成!
4-连接数据库测试
vim /app/httpd24/htdocs/index.php
测试效果:
vim mysql.php
源码:
vim /app/httpd24/htdocs/index.php
<html><body><h1>It works!</h1></body></html>
<?php
$mysqli=new mysqli("localhost","root","centos");
if(mysqli_connect_errno()){
echo "连接数据库失败!";
$mysqli=null;
exit;
}
echo "连接数据库成功!";
$mysqli->close();
5-安装wordpress
tar xvf wordpress-4.8.1-zh_CN.tar.gz -C /app/httpd24/htdocs/
cd wordpress/
cp wp-config-sample.php wp-config.php
vim wp-config.php
service httpd24 restart
到此基于LAMP的博客站点搭建成功!并成功创建第一篇文章^_^
6-压力测试
ab -c 10 -n 10 http://172.18.252.229/wordpress/
由上可见基于http自定义安装的站点每秒可处理大概16个php的动态网页站点的请求,yum装的每秒只能应对4-6个,
当然笔者设备性能有限,不过总的性能效果还是有明显提升的。
7-安装php-xcache实现php加速
tar xvf xcache-3.2.0.tar.bz2
cd xcache-3.2.0
phpize
./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-non-zts-20131226/xcache.so
service httpd24 restart
·
8-性能压力测试
ab -c 10 -n 100 http://172.18.252.229/wordpress/
经测试,每秒处理的php动态页面请求数量提升了一倍性能!由此可见php-xcache对于性能提升的效果还是十分明显的!