CentOS6.5下安装Apache2.4+PHP7
http://blog.csdn.net/along602/article/details/42695779
http://www.th7.cn/Program/php/201511/691594.shtml
http://jingyan.baidu.com/article/d2b1d10299bda55c7f37d466.html
1,准备工作,首先要下载所需软件的源码包,有如下这些:
apr-1.5.1.tar.bz2
apr-util-1.5.4.tar.bz2
pcre-8.36.tar.bz2
httpd-2.4.10.tar.bz2
php-7.0.20.tar.gz
把所有的源码包上传到服务器上/var/lamp目录下cd /var/lamp
首先要安装Apache的依赖库
tar jxvf apr-1.5.1.tar.bz2
tar jxvf apr-util-1.5.4.tar.bz2
tar jxvf pcre-8.36.tar.bz2
tar jxvf httpd-2.4.10.tar.bz2
tar zxvf php-7.0.20.tar.gz
cd apr-1.5.1
./configure --prefix=/usr/local/aprmake && make installcd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/aprmake && make installcd pcre-8.36
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/aprmake && make install 2,安装Apache2.4 首先要安装Apache的依赖库apr-1.5.2.tar.gzapr-util-1.5.4.tar.gzpcre-8.36.tar.gz tar zxvf apr-1.5.2.tar.gzcd apr-1.5.2./configure --prefix=/usr/local/aprmake && make install tar zxvf apr-util-1.5.4.tar.gzcd apr-util-1.5.4./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/aprmake && make install tar zxvf pcre-8.36.tar.gzcd pcre-8.36./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/aprmake && make install 安装PCRE的时候遇到如下错误:You need a C++ compiler for C++ support解决方案是:yum install -y gcc gcc-c++注意:这个-y千万不能少。 可以开始安装Apache了,解压缩cd httpd-2.4.17./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util -with-pcre=/usr/local/pcre --enable-so--enable-rewritemake && make install注意:--enable-so--enable-rewrite 中间不能有空格
cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
service httpd start
cd /usr/local/apache2/bin
./httpd -v 出现版本号
http://www.xxx.com 访问出现
It works!
是否安装成功
2,安装PHP7cd /var/lamp/php-7.0.20
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/apache2/conf --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip
make && make install
错误1 如果你在执行./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysqli --with-pdo-mysql --enable-mbstring时,出现这样的错误
configure:error:xml2-config not found.Please check your libxml2 installation.
说明需要libxml2,用yum装一下:yum -y install libxml2 libxml2-devel
装完libxml2后,就可以正常地进行php的源码安装了
错误2 解决 Cannot find OpenSSL's <evp.h>
yum install openssl openssl-devel
错误3 Please reinstall the libcurl distribution -
easy.h should be in <curl-dir>/include/curl/
其实就是curl的dev包没有安装, 解决方案:yum -y install curl-devel
错误4 error: png.h not found.
yum install libpng libpng-devel
错误5 error: freetype-config not found.
yum install freetype-devel
错误6 error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
yum
install
libxslt-devel
出现
Thank you for using PHP.
config.status: creating php7.spec
就代表安装成功了。
1,在Vim中搜索”DirectoryIndex“字符串,大家可以看到已经有index.html了,在index.html后面添加你想让apache识别的DirectoryIndex
在/user/local/apache2/conf/httpd.conf配置文件中再添加一段指令:
<FilesMatch "\.ph(p[2-6]?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
这段指令告诉apache,碰到文件名以
.php, .php2, .php3, .php4, .php5, .php6或phtml结尾的文件使用
libphp7.so模块进行解析。
其中"\.ph(p[2-6]?|tml)$"为正则表达式,你可以随意更改,只要符合PCRE正则表达式语法,都可以。
2,接下来,在Vim中搜索”DirectoryIndex“字符串,大家可以看到已经有index.html了,在index.html后面添加你想让apache识别的DirectoryIndex
<IfModule dir_module>
DirectoryIndex index.html index.php index.phtml</IfModule> 3,修改PHP的配置文件php.ini进入php源码目录,选择php.ini-development复制一份到/usr/local/apache2/conf,并改名为php.ini使用vi打开,查找extension_dir,修改为extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20131226",读者根据自己的PHP安装目录结构配置,目的是找到PHP的扩展库。 查找extension=php_,去掉extension=php_curl.dll,extension=php_gd2.dll,extension=php_mbstring.dll,extension=php_mysql.dll,extension=php_mysqli.dll,extension=php_pdo_mysql.dll,extension=php_xmlrpc.dll前面 的分号。查找short_open_tag = Off把它修改成short_open_tag = On,让其支持短标签(我看注释这个默认是打开的)。 从别人的服务器上我还拷贝了如下文件放到/usr/local/php/lib/php/extensions/no-debug-zts-20131226目录,文件如下:Imap.soMcrypt.soMemcache.soOpenssl.soZip.so 然后在php.ini的最后增加如下配置文字:extension=memcache.soextension=openssl.soextension=mcrypt.soextension=zip.so 4,修改Apache配置文件httpd.conf相关修改以支持PHPvi /usr/local/apache/conf/httpd.confØ 添加php支持。【添加字段一】AddType application/x-httpd-php .php .phtmlAddType application/x-httpd-php-source .phps 【添加字段二】<FilesMatch /.php$>SetHandler application/x-httpd-php</FilesMatch>Ø 添加默认索引页面index.php,再找到“DirectoryIndex”,在index.html后面加上“ index.php”DirectoryIndex index.html index.phpØ 3. 不显示目录结构,找到“OptionsIndexes FollowSymLinks”,修改为Options FollowSymLinksØ 4. 开启Apache支持伪静态,找到“AllowOverride None”,修改为AllowOverride All 重启Apacheservice httpd restart 提醒:实在不知道怎么配置,就找个已经搭建成功的服务器把配置文件弄过来对比一下。此时还会遇到如下报错:
httpd: Could not reliably determine the server's fully qualified domain name
解决办法:
linux : /usr/local/apache/conf
用记事本打开httpd.conf
将里面的#ServerName localhost:80注释去掉即可。
启动apache遇到错误:httpd: Could not reliably determine the server's fully qualified domain name
[root@server httpd-2.2.4]# /usr/local/apache/bin/apachectl starthttpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName1)进入apache的安装目录:(视个人安装情况而不同) [root@server ~]# cd /usr/local/apache/conf2)编辑httpd.conf文件,搜索"#ServerName",添加ServerName localhost:80
到此,整个Apache+PHP5.6的环境搭建完毕。