(Apache和MySQL的安裝在前面的博客也有詳細介紹)
首先準備幾個安裝包
libmcrypt-2.5.8.tar.gz(http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/)
php-5.6.2.tar.gz (http://cn2.php.net/downloads.php)
1.首先添加依賴應用
yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libpng libpng-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses curl openssl-devel gdbm-devel db4-devel
libXpm-devel libX11-devel gd-devel gmp-devel readline-devel libxslt-devel expat-devel xmlrpc-c xmlrpc-c-devel
這一步是爲了支持一些php運行的東西,還有以下編譯需要的
2.安裝加密擴展庫
cd /usr/local/src/
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make
make install
3.到php壓縮包存放的目錄下
tar zxvf php-5.6.8.tar.gz #解壓
cd php-5.6.8 #進入文件夾
運行
[root@VPS php-5.6.8]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-mysql-sock --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-fpm --with-ncurses --enable-soap
--with-libxml-dir --with-XMLrpc --with-openssl --with-mcrypt --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter
--with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --disable-mbregex
--disable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-pdo-mysql --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sqlite-utf8 --enable-sysvmsg --enable-sysvsem
--enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear
這一步不能有錯誤,警告可能會有,是說某些包不能識別之類的,一般沒有很大問題
執行
make
顯示
Build complete.
Don't forget to run 'make test'.
【
如果顯示: undefined reference to `ts_resource_ex'
collect2: ld returned 1 exit status
make: *** [sapi/cli/php] 錯誤 1
出現這樣的錯誤信息是我之前用不同的參數編譯過PHP。
解決方法:執行make clean刪除上次的編譯結果,然後再重新編譯就OK了。
如果是你第一次編譯就出現這樣的錯誤,百度解決。
】
執行
make install
最後就是配置apache讓它支持php
修改apache的配置文件httpd.conf
vi /usr/local/apache/conf/httpd.conf
然後在文本最後面添加
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php
(注意,在apache安裝目錄下,modules下有libphp5.so,這是php安裝時添加進去的,如果沒有,php,你需要重裝下
生成libphp5.so文件的是./configure中的這段代碼 --with-apxs2=/usr/local/apache/bin/apxs,路徑要和你安裝的路徑對應
)
接下來複制php啓動文件
cp php-5.6.3/php.ini-development /usr/local/php/lib/php.ini
保存,重新啓動
service httpd start
如果沒有報錯則說明啓動成功
測試php是否安裝成功
寫一個簡單的php頁面
<?php
phpinfo();
?>
安裝參考網址
http://www.th7.cn/Program/WPF/201409/285211.shtml
http://blog.sina.com.cn/s/blog_584362020101ldxd.html
http://www.centoscn.com/image-text/install/2014/1118/4140.html
http://blog.163.com/yxba_02/blog/static/1875576201272583532588/
http://www.111cn.net/sys/linux/72138.htm
http://blog.csdn.net/hahaad/article/details/8287353