下载安装包后,在安装php之前必须先安装libxml2,因此可以通过下载libxml2安装包,编译安装
我通过yum -y install libxml2 libxml2-devel(不安装这个的话,会找出解析错误)
配置: ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php --enable-mbstring=all
这是最简单或者是最基本的要求(前三个)
make
make install 若提示如下,则说明php安装成功啦
- Installing PHP SAPI module: apache2handler
- /usr/local/apache2/build/instdso.sh SH_LIBTOOL='/usr/lib/apr-1/build/libtool' libphp5.la /usr/local/apache2/modules
- /usr/lib/apr-1/build/libtool --mode=install cp libphp5.la /usr/local/apache2/modules/
- libtool: install: cp .libs/libphp5.so /usr/local/apache2/modules/libphp5.so
- libtool: install: cp .libs/libphp5.lai /usr/local/apache2/modules/libphp5.la
- libtool: install: warning: remember to run `libtool --finish /home/Gogo_yueyue/下载/php-5.3.6/libs'
- chmod 755 /usr/local/apache2/modules/libphp5.so
- [activating module `php5' in /usr/local/apache2/conf/httpd.conf]
- Installing PHP CLI binary: /usr/local/bin/
- Installing PHP CLI man page: /usr/local/man/man1/
- Installing build environment: /usr/local/lib/php/build/
- Installing header files: /usr/local/include/php/
- Installing helper programs: /usr/local/bin/
- program: phpize
- program: php-config
- Installing man pages: /usr/local/man/man1/
- page: phpize.1
- page: php-config.1
- Installing PEAR environment: /usr/local/lib/php/
- [PEAR] Archive_Tar - installed: 1.3.7
- [PEAR] Console_Getopt - installed: 1.3.0
- [PEAR] Structures_Graph- installed: 1.0.4
- [PEAR] XML_Util - installed: 1.2.1
- [PEAR] PEAR - installed: 1.9.2
- Wrote PEAR system config file at: /usr/local/etc/pear.conf
- You may want to add: /usr/local/lib/php to your php.ini include_path
- /home/Gogo_yueyue/下载/php-5.3.6/build/shtool install -c ext/phar/phar.phar /usr/local/bin
- ln -s -f /usr/local/bin/phar.phar /usr/local/bin/phar
- Installing PDO headers: /usr/local/include/php/ext/pdo/
因此,我们要修改apache配置文件来支持php解析
AddType application/x-httpd-php .php .php3
表示apache服务中可以解析php格式文件
接下来要检查apache目录下生成的php动态连接库文件,在目录/usr/local/apache/modules,找到是否存在 libphp5.so文件
/usr/local/apache/bin/apachectl -M 查看所有支持的模块,可以查看到是否支持php5.so
再到/usr/local/apache/htdocs/下创建php文件,重启apache即可测试
出现的问题:
在重启apache出现了错误提示:httpd: Syntax error on line 53 of /usr/local/apache/conf/httpd.conf: Cannot load /usr/local/apache/modules/libphp5.so into server: /usr/local/apache/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied
原因:是Linux有一个SELinux保护模式引起的。
解决办法:
1关闭SELINUX的方法:
vi /etc/selinux/config 将SELINUX=enforcing 改成SELINUX=disabled 需要重启
这个方法可能会对服务器带来风险。
2不关闭SELINUX的方法:
# setenforce 0
# chcon -c -v -R -u system_u -r object_r -t textrel_shlib_t /usr/local/apache/modules/libphp5.so
# service httpd restart
# setenforce 1