基于Linux、Apache、Mysql、Php编译安装LAMP环境平台,并使用xcache加速phpphp
编译安装LAMP平台:html
一、下载软件包, 安装依赖包mysql
# yum install -y pcre-devellinux
二、解包安装apachesql
2.1 编译安装apr-1.5.0数据库
# tar xvf apr-1.5.0.tar.bz2apache
# cd apr-1.5.0 && ./configure --prefix=/usr/local/aprvim
# make && make install安全
2.2 编译安装apr-util-1.5.3服务器
# tar xvf apr-util-1.5.3.tar.bz2
# cd apr-util-1.5.3 && ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install
2.3 编译安装httpd-2.4.9
# tar xvf httpd-2.4.9.tar.bz2
# cd httpd-2.4.9
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewirte --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-moudles=most --enable-mpms-shared=all --with-mpm=event
# make && make install
2.4 编辑httpd的启动脚本
# vim /etc/init.d/httpd
# chmod +x /etc/init.d/httpd
# chconfig --add httpd
三、安装mysql(mariaDB)
3.1 准备数据存放的文件系统
# mkdir /mydata/data
3.2 新建用户以安全的方式运行进程
# groupadd -r mysql
# useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
# chown -R mysql:mysql /mydata/data
3.3 安装并初始化
# tar xvf mariadb-5.5.43-linux-x86_64.tar.gz -C /usr/local/
# cd /usr/local/
# ln -s mariadb-5.5.43-linux-x86_64 mysql
# cd mysql && chown -R mysql.mysql .
# scripts/mysql_install_db --user=mysql --datadir=/mydata/data
# chown -R root .
3.4 为mysql提供主配置文件:
# cd /usr/local/mysql
# cp support-files/my-large.cnf /etc/my.cnf
修改如下参数, thread_concurrency值为你的CPU的个数乘以2
thread_concurrency = 8
还须要添加一行定义mysql的数据文件存放位置:
datadir=/mydata/data
3.5 为mysql提供sysv服务脚本
# cd /usr/local/mysql
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
# chmod +x /etc/rc.d/init.d/mysqld
然后就能够测试启动mysql了
3.6 如今就能够输出mysql的man手册至man命令的查找路径
# vi /etc/man.config
添加以下行
MANPATH /usr/local/mysql/man
3.7 输出mysql的头文件至系统头文件路径/usr/include
能够经过简单的建立连接实现
# ln -sv /usr/local/mysql/include/mysql /usr/include/mysql
3.8 输出mysql的库文件给系统库查找路径
# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
而后,让系统从新载入系统库
# ldconfig
3.9 修改PATH环境变量,让系统可使用mysql的相关命令
# vi /etc/profile.d/mysqld.sh
添加以下行
export PATH=/usr/local/mysql/bin:$PATH
# source /etc/profile.d/mysqld.sh
四、编译安装php
4.1 安装依赖关系
# yum groupinstall -y "Desktop Platform Development"
# yum install -y bzip2-devel libmcrypt-devel
注: libmcrypt-devel 须要epel源
4.2 编译安装php-5.6.9
# tar xvf php-5.6.9.tar.bz2
# cd php-5.6.9
# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jepg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts
说明:
一、这里为了支持apache的work和event这两个MPM, 编译时使用了--enable-maintainer-zts选项
二、若是使用php5.3以上版本,为了链接MYSQL数据库, 能够指定mysqlnd,这样在本机就不须要先安装MySQL或MySQL开发包了。mysqlnd从php 5.3开始可用,能够编译时绑定到它(而不用和具体的MySQL客户端库绑定造成依赖),但从PHP 5.4开始它就是默认设置了。
# ./configure --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd
# make && make install
为php提供配置文件
# cp php.ini-production /etc/php.ini
4.3 编辑apache配置文件httpd.conf, 以apache支持php
一、# vim /etc/httpd/httpd.conf
添加如下两行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
二、定位 DirectoryIndex index.html 修改成:
DirectoryIndex index.html index.php
从新启动httpd 或让其从新载入配置文件便可测试php是否已经能够正常使用
测试页:
# vi /usr/local/apache/htdoc/index.php
<?php
$link = mysql_connect('127.0.01','root','');
if ($link)
echo 'Success...';
else
echo 'Failure...';
mysql_close();
?>
五、安装xcache, 为php加速:
5.1 安装
# tar zxvf xcache-3.2.0.tar.gz
# cd xcache-3.2.0
# /usr/local/php/bin/phpize
# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
# make && make install
安装结束会有以下提示
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20131226/
5.2 编辑php.ini, 整合php和xcache
# mkdir /etc/php.d
# cp xcache.ini /etc/php.d
注:
xcache.ini文件在xcache的源码目录中
# vi /etc/php.d/xcache.ini
修改extension为如下内容
extension = /usr/local/php/lib/php/extensions/no-debug-zts-20131226/xcache.so
注:
若是php.ini 文件中有多条zend_extension指令行,要确保此新增的行排在第一位
六、启用服务器状态
mod_status 模块可让管理员查看服务器的执行状态,他经过一个HTML页面展现了当前服务器的统计数据,这些数据一般包括可是不限于:
(1) 处于工做中的worker进程数;
(2) 空闲状态的worker进程数;
(3) 每一个worker的状态,包括此worker已经响应的请求数,及由此worker发送的内容的字节数;
(4) 当前服务器总共发送的字节数;
(5) 服务器自上次启动或重启以来至当前的时长;
(6) 平均每秒响应的请求数、平均每秒钟发送的字节数、平均每一个请求所请求内容的字节数;
启用页面的方法很简单,只须要在主配置文件中添加以下内容便可:
<Location /server-status>
SetHandler Server-status
Require all granted
</Location>
也可使用require ip 192.168.1.0/24来限制仅容许指定网段的主机查看此页面。
eg:
<Location /server-status>
SetHandler Server-status
require ip 192.168.1.0/24
</Location>