一、安裝相關依賴庫
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel curl curl-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers pcre pcre-devel
二、解壓php包
tar -zxvf php-5.6.3.tar.gz
cd php-5.6.3
export LD_LIBRARY_PATH=/usr/local/libgd/lib
三、編譯安裝
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysql-sock=/usr/local/mysql/mysql.sock --with-apxs2=/usr/local/apache/bin/apxs --with-gd --with-jpeg-dir --with-png-dir --enable-mbstring --enable-xml --enable-fpm --with-freetype-dir --with-mcrypt --with-mhash --with-libxml-dir --with-zlib-dir
make
make install
四、配置php
cp php.ini-production /usr/local/php/etc/php.ini #復制php配置文件到安裝目錄
ln -s /usr/local/php/etc/php.ini /etc/php.ini #添加軟鏈接到 /etc目錄
rm -rf /etc/php.ini #刪除系統自帶配置文件
vi /etc/php.ini
找到:disable_functions =
修改為:disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
#列出PHP可以禁用的函數,如果某些程序需要用到這個函數,可以刪除,取消禁用。
找到:;date.timezone =
修改為:date.timezone = PRC #設置時區
找到:expose_php = On
修改為:expose_php = Off #禁止顯示php版本的信息
找到:short_open_tag = Off
修改為:short_open_tag = ON #支持php短標簽
:wq! 保存
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf #拷貝模板文件為php-fpm配置文件
ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf #添加軟連接到 /etc目錄
vi /usr/local/php/etc/php-fpm.conf #編輯
user = www #設置php-fpm運行賬號為www
group = www #設置php-fpm運行組為www
pid = run/php-fpm.pid #取消前面的分號
:wq! #保存退出
cp /home/php-5.6.3/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm #拷貝php-fpm到啟動目錄
chmod +x /etc/rc.d/init.d/php-fpm #添加執行權限
chkconfig php-fpm on #設置開機啟動
編輯apache配置文件httpd.conf,以apache支持php
# vim /etc/httpd/httpd.conf
添加如下
AddType application/x-httpd-php .php .phtml
定位至DirectoryIndex index.html
修改為:
DirectoryIndex index.php index.html
添加index.php為默認主頁
重新啟動apache
五、測試
在/usr/local/apache/htdocs目錄下建一個test.php或test.phtml的文件,內容如下示:
<</FONT>
?
php
phpinfo();
?
>
:wq! #保存退出