首先安裝基礎依賴組建,註:這些依賴組建也是LINUX+PHP+MYSQL+APACHE+NGINX+MEMCACHED時必要的系統組件
LANG=C
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel
zlib zlib-devel glibc glibc-devel glib2 glib2-devel gd* bzip2 bzip2-devel ncurses ncurses-devel net-snmp-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients
openldap-servers libmcrypt libmcrypt-devel
下載 php-5.4.8.tar.gz (相應臨近版本即可)
#wget http://cn2.php.net/get/php-5.4.8.tar.gz/from/this/mirror
#tar zxvf php-5.4.8.tar.gz
#cd php-5.4.8
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir --with-jpeg-dir --with-png-dir --with-zlib
--with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --with-freetype-dir --enable-gd-native-ttf
--with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --enable-session --with-gettext
(./configure 中提示缺少什麼依賴組建,yum install 相應組建即可)
編譯過程中可能存在類似這樣的警告資訊:
---------------------------------------------------------------------------------------------------------
#configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
解決方案如下:(或者直接無視它,這並不影響php的正常安裝運行)
wget
http://sourceforge.net/projects/re2c/files/re2c/0.13.5/re2c-0.13.5.tar.gz/download
tar -zxvf re2c-0.13.5.tar.gz
cd re2c-0.13.5
./configure && make && make install
service apache restart 重啟APACHE時出現如下錯誤
httpd: Syntax error on line 53 of /usr/local/apache2/conf/httpd.conf: Cannot load
/usr/local/apache2/modules/libphp5.so into server: /usr/local/apache2/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied
解決方案,執行如下語句 即可
[root@server2 ~]# chcon -t textrel_shlib_t '/usr/local/apache2/modules/libphp5.so'
[root@server2 ~]# service apache restart
[root@server2 ~]# echo $?
0
make(這裡可能由於mysql libmysqlclient.so.18載入失敗 二出現點小差錯,注意,這僅僅是可能,處理方法如下)
make install(如果提示如下資訊,則說明一切順利,安裝成功!)
Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
/var/ftp808/php-5.4.8/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f /usr/local/php/bin/phar.phar /usr/local/php/bin/phar
Installing PDO headers: /usr/local/php/include/php/ext/pdo/
複製源碼包裡的php.ini-production設定檔到PHP安裝目錄即(cp /var/ftp808/php-5.4.8/php.ini-production /usr/local/php/lib/php.ini)
注意php新版本此檔案名稱有變更 具體根據版本 實際檔案名稱路徑
#cp php.ini-production /usr/local/php/lib/php.ini
------------------------------
修改apache的設定檔httpd.conf
增加
AddType application/x-httpd-php .php
修改www的預設檔案地址DocumentRoot
注意還要修改Directoty的路徑和上面的一樣
重啟httpd
測試php檔案
phpinfo()
---------------------------------
執行php檔案
#/usr/local/php/bin/php xx.php
關於靈異事件,在執行make時候提示:
類似error while loading shared libraries: libmysqlclient.so.18: cannot open 錯誤,
這表明libmysqlclient.so.18 沒有載入成功,執行下面語句進行手動註冊 然後重新編譯即可
方法一:
具體根據MYSQL實際安裝目錄 修改路徑
如我的mysql安裝在/usr/local/mysql下,則結果為
ldconfig /usr/local/mysql/lib/libmysqlclient.so.18(mysql5.6.12路徑格式)
ldconfig /usr/local/mysql/lib/mysql/libmysqlclient.so.18(老版本路徑格式)
方法二:
locate libmysqlclient.so.16
如我的mysql安裝在/usr/local/mysql下,則結果為
/usr/local/mysql/lib/libmysqlclient.so.18(mysql5.6.12路徑)
/usr/local/mysql/lib/mysql/libmysqlclient.so.18(mysql老版本路徑)
vi /etc/ld.so.conf
增加一行 /usr/local/mysql/lib
然後執行ldconfig生效。
如果上述方法均不生效,可能你需要方法三:
方法三:
開啟/etc/ld.so.conf
include ld.so.conf.d/*.conf
增加
/usr/local/mysql(根據實際安裝路徑)
/usr/local/mysql/lib(根據實際安裝路徑,這裡是cmake編譯下的新版本路徑格式,5.X以上舊版本一般為/usr/local/mysql/lib/mysql/)
然後運行ldconfig即可
我的家庭電腦採用的方法一,伺服器採用的是方法三,VPS用了方法二