PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

CentOS65下安装Apache24+PHP56

原创
2016-07-29 09:12:23 723浏览
可能立刻会有人要问:为啥不装MySql,这是因为本次项目准备购买云RDS,所以就不在系统中自己安装MySql了。

言归正传,开始安装系统。

1,准备工作,首先要下载所需软件的源码包,有如下这些:
apr-1.5.2.tar.gz
apr-util-1.5.4.tar.gz
pcre-8.36.tar.gz
httpd-2.4.17.tar.gz

php-5.6.15.tar.gz

把所有的源码包上传到服务器上。

2,安装Apache2.4

首先要安装Apache的依赖库
apr-1.5.2.tar.gz
apr-util-1.5.4.tar.gz
pcre-8.36.tar.gz


tar zxvf apr-1.5.2.tar.gz
cd apr-1.5.2
./configure --prefix=/usr/local/apr
make && make install

tar zxvf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install

tar zxvf pcre-8.36.tar.gz
cd pcre-8.36
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && 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-rewrite
make && make install

注意:之前安装的时候从windows上复制的./configure配置参数,结果中间不知为何多出来一些换行符,导致运行结果出错了,所以大家拷贝指令的时候一定要小心。

2,安装PHP5.6.15
解压缩
Cd php-5.6.15
配置参数太复杂于是去网上找了一个大牛的推荐,如下:
./configure --prefix=/usr/local/php--with-apxs2=/usr/local/Apache2/bin/apxs --with-libxml-dir=/usr/include/libxml2--with-config-file-path=/usr/local/Apache2/conf --with-mysql=/usr/local/mysql--with-mysqli=/usr/local/mysql/bin/mysql_config --with-gd--enable-gd-native-ttf --with-zlib --with-mcrypt--with-pdo-mysql=/usr/local/mysql --enable-shmop --enable-soap --enable-sockets--enable-wddx --enable-zip --with-xmlrpc --enable-fpm --enable-mbstring--with-zlib-dir --with-bz2 --with-curl --enable-exif --enable-ftp--with-jpeg-dir=/usr/lib --with-png-dir=/usr/lib --with-freetype-dir=/usr/lib/

于是乎遇到了一系列的报错,推荐我之前的一篇文章介绍了常见错误的解决办法:
http://blog.csdn.net/dodott/article/details/49664379

我遇到的问题如下:

【报错】Configure: error: Please reinstall the BZip2 distribution
解决方案:
centos: yum install bzip2 bzip2-devel
debian: apt-get install bzip2-devel


【报错】
configure: error: Please reinstall the libcurl distribution -
easy.h should be in/include/curl/
解决方案:
centos: yum install curl curl-devel (For Redhat & Fedora)


【报错】
configure: error: mcrypt.h not found. Please reinstalllibmcrypt.
解决方案:
网上大部分给的方法是使用如下指令
yum install libmcrypt libmcrypt-devel (For Redhat & Fedora)
但是基本上都没有作用,系统甚至会提示:nothing to do。估计可能和YUM源的软件版本太低有关系。

正确做法是自己下载源码来安装:
libmcrypt-2.5.7.tar.gz

cd libmcrypt-2.5.7
#编译(默认安装到/usr/local/lib/)
./configure --prefix=/usr/local/libmcrypt

#执行安装
make && make install

注意:这里的安装路径要记住,等会安装PHP的时候会用到。


继续回到PHP的安装,此时的配置参数修改为:
./configure --prefix=/usr/local/php--with-apxs2=/usr/local/Apache2/bin/apxs --with-libxml-dir=/usr/include/libxml2--with-config-file-path=/usr/local/Apache2/conf --with-mysql=/usr/local/mysql--with-mysqli=/usr/local/mysql/bin/mysql_config --with-gd --enable-gd-native-ttf--with-zlib --with-pdo-mysql=/usr/local/mysql --enable-shmop --enable-soap--enable-sockets --enable-wddx --enable-zip --with-xmlrpc --enable-fpm--enable-mbstring --with-zlib-dir --with-bz2 --with-curl --enable-exif--enable-ftp --with-jpeg-dir=/usr/lib --with-png-dir=/usr/lib--with-freetype-dir=/usr/lib/ --with-mcrypt=/usr/local/libmcrypt

修改内容是:
去掉了--with-mcrypt,在最后增加了--with-mcrypt=/usr/local/libmcrypt

【报错】
configure: error: Cannot find MySQL header files under/usr/local/mysql.
Note that the MySQL client library is not bundled anymore!

这个问题是因为没有安装mysql,所以找不到mysql的运行库。
但是本次安装本身就不想安装完整的mysql软件,去php官网查了资料后找到如下一段翻译文字:
“对于 php-5.3.0或更新版本,mysqli 默认使用Mysql Native Driver作为驱动。 这个驱动比libmysql会有一些优势, --with-mysql=mysqlnd”

最终configure参数修改为:
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/Apache2/bin/apxs--with-libxml-dir=/usr/include/libxml2--with-config-file-path=/usr/local/Apache2/conf--with-mysql=mysqlnd --with-mysqli=mysqlnd --with-gd --enable-gd-native-ttf--with-zlib --with-pdo-mysql=mysqlnd --enable-shmop --enable-soap--enable-sockets --enable-wddx --enable-zip --with-xmlrpc --enable-fpm--enable-mbstring --with-zlib-dir --with-bz2 --with-curl --enable-exif--enable-ftp --with-jpeg-dir=/usr/lib --with-png-dir=/usr/lib--with-freetype-dir=/usr/lib/ --with-mcrypt=/usr/local/libmcrypt

注意:上面红色标记出来的目录就是后面php.ini需要放置的目录。


到此终于把PHP的configure成功通过。
make 和 makeinstall。PHP安装完毕。

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.so
Mcrypt.so
Memcache.so
Openssl.so
Zip.so

然后在php.ini的最后增加如下配置文字:
extension=memcache.so
extension=openssl.so
extension=mcrypt.so
extension=zip.so




4,修改Apache配置文件httpd.conf相关修改以支持PHP
vi /usr/local/Apache/conf/httpd.conf
? 添加php支持。
【添加字段一】
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps

【添加字段二】

SetHandler application/x-httpd-php

? 添加默认索引页面index.php,再找到“DirectoryIndex”,在index.html后面加上“ index.php”
DirectoryIndex index.html index.php
? 3. 不显示目录结构,找到“OptionsIndexes FollowSymLinks”,修改为
Options FollowSymLinks
? 4. 开启Apache支持伪静态,找到“AllowOverride None”,修改为
AllowOverride All

重启Apache
service 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+PHP5.6的环境搭建完毕。

推荐文章:

PHP的编译安装

以上就介绍了CentOS65下安装Apache24+PHP56,包括了Apache,准备工作,索引,安装Apache方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。