CentOS编译安装Apache2.4+PHP5.6

WBOY
Release: 2016-06-23 09:09:41
Original
1070 people have browsed it

分类:Linux时间: 2015年12月26日

CentOS下YUM安装PHP和Apache是比较简单的,可是一般默认情况下的PHP版本是5.3,Apache版本是2.2。因为考虑到PHP版本和Apache版本越高性能越好,就打算在CentOS下编译安装Apache2.4+PHP5.6。现在PHP程序员雷雪松总结一份比较完整的CentOS编译安装Apache2.4+PHP5.6安装步骤分享给大家。

1、下载Apache2.4+PHP5.6源码包

从http://httpd.apache.org/download.cgi#apache24下载httpd-2.4.17.tar.gz和other file下载httpd-2.4.17-deps.tar.gz

从http://php.net/downloads.php下载php-5.6.16.tar.gz源码包

从http://sourceforge.net/projects/pcre/files/pcre/8.32/ 下载pcre-8.32.tar.gz

2、先装gcc和make编译工具

[Raykaeso@LAMP php-5.6.16]# yum -y install gcc make gcc-c++ 没有这个gcc-c++一会编译不prce
Copy after login

切到下载好的源码包目录,以系统根目录/LAMP为例。

3、解压Apache2.4依赖包,安装apr、apr-util和pcre,编译安装Apache2.4

[Raykaeso@LAMP download]# tar -zxvf httpd-2.4.17-deps.tar.gz 安装apr [Raykaeso@LAMP download]# cd apr [Raykaeso@LAMP apr]# ./configure --prefix=/usr/local/apr [Raykaeso@LAMP apr]# make && make install  安装apr-util [Raykaeso@LAMP apr-util]# cd ../apr-util [Raykaeso@LAMP apr-util]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr [Raykaeso@LAMP apr-util]# make && make install  安装pcre [Raykaeso@LAMP apr-util]#  cd /LAMP [Raykaeso@LAMP LAMP]# tar -zvxf pcre-8.32.tar.gz [Raykaeso@LAMP LAMP]# cd pcre-8.32 [Raykaeso@LAMP pcre-8.32]# ./configure [Raykaeso@LAMP pcre-8.32]# make && make install  安装Apache2.4必须要先安装apr、apr-util和pcre [Raykaeso@LAMP pcre-8.32]#  cd /LAMP [Raykaeso@LAMP LAMP]#  tar -zvxf httpd-2.4.17.tar.gz [Raykaeso@LAMP LAMP]#  cd httpd-2.4.17 [Raykaeso@LAMP httpd-2.4.17]#  ./configure --prefix=/usr/local/apache --with-apr-util=/usr/local/apr-util [Raykaeso@LAMP httpd-2.4.17]#  make && make install
Copy after login

4、编译安装PHP5.6

[Raykaeso@LAMP httpd-2.4.17]#  cd /LAMP [Raykaeso@LAMP LAMP]# yum -y install libxml2-devel #不装这个编译不了PHP5.5 [Raykaeso@LAMP LAMP]# yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel png jpeg gd #开启GD库需要的依赖 [Raykaeso@LAMP LAMP]# yum -y install curl curl-devel #开启CURL库需要的依赖 [Raykaeso@LAMP LAMP]# tar -zvxf php-5.6.16.tar.gz [Raykaeso@LAMP LAMP]# cd php-5.6.16 [Raykaeso@LAMP php-5.6.16]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --enable-sysvsem --enable-sockets --enable-pcntl --enable-mbstring --enable-mysqlnd  --enable-pdo --with-pdo-mysql --enable-opcache --enable-shmop --enable-zip --enable-ftp --enable-gd-native-ttf --enable-wddx --enable-soap  --with-png-dir --with-freetype-dir --with-jpeg-dir --with-gd --with-mysqli [Raykaeso@LAMP php-5.6.16]# make && make install 拷贝一份正式的php-fpm.conf和php.ini配置文件 [Raykaeso@LAMP php-5.6.16]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf [Raykaeso@LAMP php-5.6.16]# cp ./php.ini-production /usr/local/php/etc/php.ini
Copy after login

启动和关闭PHP

[Raykaeso@LAMP php-5.6.16]# /usr/local/php/sbin/php-fpm [Raykaeso@LAMP php-5.6.16]# killall php-fpm
Copy after login

5、编辑apache配置httpd.conf文件:

[Raykaeso@LAMP php-5.6.16]# vi /usr/local/apache/conf/httpd.conf  把这三行前面的#号去掉 LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so LoadModule rewrite_module modules/mod_rewrite.so #开启rewrite  在最下面加两行: #proxy php ServerName 127.0.0.1 ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/$1 保存退出:wq
Copy after login

重启 Apache

[Raykaeso@LAMP php-5.6.16]# /usr/local/apache/bin/apachectl restart
Copy after login

到这里,CentOS编译安装Apache2.4+PHP5.6就配置完了,在实际的安装过程中可能还是会越到了坑,一般报错就是因为PHP依赖包没有安装。Apache2.4+PHP5.6安装配置成功了可以写个phpinfo的文件,看一下常用的扩展是否装好。还有一点需要注意的是,上线尽量和开发的PHP版本保持一致,不然使用一些废弃的PHP函数就很头疼了。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template