您好,欢迎访问一九零五行业门户网

CentOS65下安装Apache24+PHP56

可能立刻会有人要问:为啥不装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教程有兴趣的朋友有所帮助。
其它类似信息

推荐信息