下载
wget http://cn2.php.net/distributions/php-5.4.44.tar.gz
解压
tar zxvf php-5.4.44.tar.gz
提前安装一些依赖包
- yum install -y libjpeg-devle libxml2-devel openssl openssl-devel bzip2 bzip2-devel libpng libpng-devel freetype freetype-devel epel-release libmcrypt
- yum install -y libmcrypt-devel
配置编译参数:
- cd php-5.4.44
- ./configure \
- --prefix=/u01/php \
- --with-apxs2=/u01/apache2/bin/apxs \
- --with-config-file-path=/u01/php/etc \
- --with-mysql=/u01/mysql \
- --with-libxml-dir \
- --with-gd \
- --with-jpeg-dir \
- --with-png-dir \
- --with-freetype-dir \
- --with-iconv-dir \
- --with-zlib-dir \
- --with-bz2 \
- --with-openssl \
- --with-mcrypt \
- --enable-soap \
- --enable-gd-native-ttf \
- --enable-mbstring \
- --enable-sockets \
- --enable-exif \
- --disable-ipv6
可能出现的错误及解决办法
configure: error: xml2-config not found. Please check your libxml2 installation.
解决办法是:
yum install -y libxml2-devel
还有错误:
configure: error: Cannot find OpenSSL's <evp.h>
解决办法是:
yum install -y openssl openssl-devel
错误:
checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution
解决办法:
yum install -y bzip2 bzip2-devel
错误:
configure: error: png.h not found.
解决办法:
yum install -y libpng libpng-devel
错误:
configure: error: freetype.h not found.
解决办法:
yum install -y freetype freetype-devel
错误:
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决办法:
- yum install -y epel-release
- yum install -y libmcrypt-devel
因为 centos6 默认的 yum 源没有 libmcrypt-devel 这个包, 只能借助 epel 的 yum 源.
make&&make install
拷贝 php 配置文件:
cp php.ini-production /usr/local/php/etc/php.ini
修改 apache 配置文件
vi /usr/local/apache2/conf/httpd.conf
找到:
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
改为:
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
</Directory>
说明: 如果不修改这个地方, 我们访问网站会禁止访问, 显示 403.
然后找到:
AddType application/x-gzip .gz .tgz
在该行下面添加:
AddType application/x-httpd-php .php
说明, 要想支持 php 脚本解析, 必须要加上对应的类型.
再找到:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
将该行改为:
<IfModule dir_module>
DirectoryIndex index.html index.htm index.php
</IfModule>
说明: 增加针对 php 的索引, 如果一个站点默认页为 index.php, 那么就得加上这个
index.php 的支持.
再找到:
#ServerName www.example.com:80
修改为:
ServerName localhost:80
如果不去掉 #, 则启动 apache 时, 会有警告信息 "httpd: Could not reliably determine the
server's fully qualified domain name, using localhost.localdomain for ServerName", 看起来像是
错误, 其实没有影响.
查看配置文件是否有问题:
/usr/local/apache2/bin/apachectl -t
如果显示 Syntax OK, 说明配置没问题了. 然后启动服务:
/usr/local/apache2/bin/apachectl start
检查 apache 是否正常启动的命令是:
ps aux |grep httpd
看有没有进程列表.
来源: http://www.bubuko.com/infodetail-2709283.html