如果是yum安装直接
yum install php php-devel php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash php-fpm
Mysql5.5,apache2.2.3centos php5.3.2.8
php下载
# cd /usr/local/src/
# wget http://cn.php.net/get/php-5.3.6.tar.gz/from/this/mirror
php安装
# tar -zxvf php-5.3.6.tar.gz
# cd php-5.3.6
# ./configure --prefix=/usr/local/php --with-mysql=/usr/share/mysql --with-apxs2=/usr/sbin/apxs --enable-mbstring --with-config-file-path=/usr/local/php/etc
# make
# make install
ps:
--prefix=/usr/local/php 指定php安装目录;
--with-mysql=/usr/local/mysql5.5.9 指定mysql安装目录;
--with-apxs2=/usr/sbin/apxs 指定查找Apache2的地方;
--with-config-file-path=/usr/local/php/etc 指定php的配置文件目录
php的设定
# cp -pr php.ini-development php.ini
编辑php.ini
# vi php.ini
default_charset = "UTF-8"
extension_dir = "./ext"
extension=php_mbstring.dll
[mbstring]
mbstring.language = Japanese
mbstring.internal_encoding = UTF-8
mbstring.http_output = UTF-8
Apache的设定
# vi /etc/httpd/conf/httpd.conf
AddType application/x-httpd-php .php
DirectoryIndex index.html index.htm index.html.var index.php
没有如下的文字,追加
LoadModule php5_module /usr/lib/httpd/modules/libphp5.so
# /etc/init.d/httpd restart
测试
在apache的htdocs下建立一个php文件test.php,里面的内容如下:
<?php
phpinfo();
?>
然后在浏览器里输入http://127.0.0.1/test.php
如果出现php的相关配置,成功,如果什么都没有输入,说明失败,重新以上步骤或者查找原因
遇到的问题与解决方案
问题一:
./configure以下错误发生
Sorry, I cannot run apxs. Possible reasons follow:
1. Perl is not installed
2. apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs
3. Apache was not built using --enable-so (the apxs usage page is displayed)
解决方法:指定正确的apxs路径
1.查找apxs路径
# whereis apxs
apxs:
说明系统没有安装apxs扩展工具
2.安装apxs
# yum install httpd-devel
3.查找apxs路径
# whereis apxs
apxs: /usr/sbin/apxs /usr/share/man/man8/apxs.8.gz
apxs安装成功
问题二:
安装apxs以下错误发生:
Package cyrus-sasl-plain needs cyrus-sasl-lib = 2.1.22-4, this is not available.
解决方法:
# yum -y install cyrus*
之后再次安装apxs
问题三:
再次./configure以下错误发生
configure: error: xml2-config not found. Please check your libxml2 installation.
解决方法:
安装libxml2
# yum install libxml2-devel
问题四:
编译PHP时提示:configure: error: Cannot find MySQL header files under /usr/share/mysql
解决方法:
这个是缺少了 mysql-devel 安装包,用
#yum install -y mysql-devel
问题五:
php 安装 configure: error: Cannot find libmysqlclient under /usr/share/mysql. 解决
解决方法:
这个是缺少了 mysql-devel 安装包,用
#yum install -y mysql-devel