Apache的依赖关系Apr&& apr-utils
2. MySQL5.5.38MySQL编译方式采用通用二进制格式
3. PHP5.5.15PHP Apache以FCGI的方式编译
4. 配置结合FCGI运行配置默认文档index.php
配置AddType支持PHP
配置php-fpm支持PHP解析
5. 配置xcache加速PHP安装Apache2.4.10
依赖包:
wget http://mirror.bit.edu.cn/apache/apr/apr-1.5.1.tar.gz
wget http://mirror.bit.edu.cn/apache/apr/apr-util-1.5.3.tar.gz
wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.10.tar.gz
# tarzxvf apr-1.5.1.tar.gz
# cdapr-1.5.1
#./configure --prefix=/data/apr
如果configure报libtoolT的错误,请删除configure文件中如下此行
30145 $RM "$cfgfile"
# make && make install
# tarzxvf apr-util-1.5.3.tar.gz
# cdapr-util-1.5.3
#./configure --prefix=/data/apr-util--with-apr=/data/apr/
#make && make install
# tarzxvf httpd-2.4.10.tar.gz
# cdhttpd-2.4.10
#./configure --prefix=/data/apache --sysconfdir=/etc/httpd --enable-so --enable-rewirte --enable-ssl --enable-cgi--enable-cgid --enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all--with-apr=/data/apr --with-apr-util=/data/apr-util/
#make && make install
安装MySQL5.5.38
wget http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.38-linux2.6-x86_64.tar.gz
# yuminstall libaio libaio-devel
#useradd -M -s /sbin/nologin mysql
# tarzxvf mysql-5.5.38-linux2.6-x86_64.tar.gz -C /usr/local/
# cd/usr/local/
# ln-s mysql-5.5.38-linux2.6-x86_64/ mysql
# chown root:mysql -R mysql
# cpsupport-files/mysql.server /etc/init.d/mysqld
#chmod +x /etc/init.d/mysqld
# cpsupport-files/my-huge.cnf /etc/my.cnf
#mkdir -p /data/mysql/data
#chown -R mysql:mysql /mydata/data
#scripts/mysql_install_db --user=mysql--datadir=/data/mysql/data/
# sed-i '37a\basedir = /usr/local/mysql' /etc/my.cnf
# sed-i '38a\datadir = /data/mysql/data' /etc/my.cnf
# sed-i '39a\log-error = /data/mysql/data/mysql_error.log' /etc/my.cnf
# sed-i '40a\pid-file = /data/mysql/data/mysql.pid' /etc/my.cnf
# sed-i '41a\skip-name-resolve' /etc/my.cnf
#chkconfig --add mysqld
#chkconfig mysqld on
#service mysqld start
输出MySQL的头文件:
# ln-sv /usr/local/mysql/include /usr/include/mysql
输出MySQL的库文件路径
#echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
#ldconfig
输出MySQL的命令到全局
# cat/etc/profile.d/mysql.sh
exportPATH=$PATH:/usr/local/mysql/bin
#source /etc/profile.d/mysql.sh
安装PHP5.5.15
wget http://cn2.php.net/distributions/php-5.5.15.tar.gz
如果要让PHP支持mcrypt扩展,必须手动安装libmcrypt-2.5.7.tar.gz
# tarzxvf libmcrypt-2.5.7.tar.gz
# cdlibmcrypt-2.5.7
#./configure --prefix=/data/libmcrypt
#make && make install
# tarzxvf php-5.5.15.tar.gz
# cdphp-5.5.15
./configure --prefix=/data/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-mcrypt=/data/libmcrypt/--with-config-file-path=/etc/ --with-config-file-scan-dir=/etc/php.d --with-bz2--enable-fpm
#make && make install
# cpphp.ini-production /etc/php.ini
# cpsapi/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 php-fpm on
# cp/data/php/etc/php-fpm.conf.default /data/php/etc/php-fpm.conf
# vim/data/php/etc/php-fpm.conf
pm.max_children= 50
pm.start_servers= 5
pm.min_spare_servers= 2
pm.max_spare_servers= 8
#service php-fpm start
配置Apache
1、启用httpd的相关模块
在Apachehttpd 2.4以后已经专门有一个模块针对FastCGI的实现,此模块为mod_proxy_fcgi.so,它其实是作为mod_proxy.so模块的扩充,因此,这两个模块都要加载
LoadModuleproxy_module modules/mod_proxy.so
LoadModuleproxy_fcgi_module modules/mod_proxy_fcgi.so
2、配置虚拟主机支持使用fcgi
在相应的虚拟主机中添加类似如下两行。
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$fcgi://127.0.0.1:9000/PATH/TO/DOCUMENT_ROOT/$1
例如:
<VirtualHost*:80>
DocumentRoot "/data/wwwroot"
ServerName xxx.com
ServerAlias www.xxx.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$fcgi://127.0.0.1:9000/data/wwwroot/$1
<Directory"/data/wwwroot/">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
ProxyRequestsOff:关闭正向代理
ProxyPassMatch:把以.php结尾的文件请求发送到php-fpm进程,php-fpm至少需要知道运行的目录和URI,所以这里直接在fcgi://127.0.0.1:9000后指明了这两个参数,其它的参数的传递已经被mod_proxy_fcgi.so进行了封装,不需要手动指定。
3、编辑apache配置文件httpd.conf,让apache能识别php格式的页面,并支持php格式的主页
# vim /etc/httpd/httpd.conf
1、添加如下二行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
2、定位至DirectoryIndexindex.html
修改为:
DirectoryIndex index.php index.html
补充:Apachehttpd 2.4以前的版本中,要么把PHP作为Apache的模块运行,要么添加一个第三方模块支持PHP-FPM实现。
安装xcache3.10
wget http://xcache.lighttpd.net/pub/Releases/3.1.0/xcache-3.1.0.tar.gz
# tarzxvf xcache-3.1.0.tar.gz
# cdxcache-3.1.0
#/data/php/bin/phpize
#./configure --enable-xcache--with-php-config=/data/php/bin/php-config
#make && make install
#mkdir -p /etc/php.d
# cpxcache.ini /etc/php.d/
# vim/etc/php.d/xcache.ini
extension= /data/php/lib/php/extensions/no-debug-non-zts-20121212/xcache.so
#/etc/init.d/php-fpm restart