centOS下編譯安裝php


點擊訪問原文
您還可以加入全棧技術交流群(QQ群號:254842154)


之前編譯安裝php時折騰了很久,很是惱火,現(xiàn)在終于理順了。整理一下。

1、安裝依賴文件

yum groupinstall "Development tools"

假如不安裝這些開發(fā)庫,到時候需要自己安裝好多東西

其他依賴文件

yum install libxml2-devel gd-devel libmcrypt-devel libcurl-devel openssl-devel

2、安裝php

wget http://us3.php.net/get/php-5.5.20.tar.gz/from/cn2.php.net/mirror

tar -xvf php-5.5.20.tar.gz
cd php-5.5.20

編譯,假如提示

configure: error: mcrypt.h not found. Please reinstall libmcrypt

則需要安裝libmcrypt

wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz
tar -zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure prefix=/usr/local/libmcrypt/ 

繼續(xù)編譯php,安裝到目錄/usr/local/php

假如沒有報錯,不需要with-mcrypt=/usr/local/libmcrypt/ 這個編譯選項

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --disable-cli --enable-shared --with-libxml-dir --with-gd --with-openssl --enable-mbstring --with-mysqli --with-mysql --enable-opcache --enable-mysqlnd --enable-zip --enable-fpm --enable-fastcgi --with-zlib-dir --with-pdo-mysql --with-jpeg-dir --with-freetype-dir --with-curl --without-pdo-sqlite --without-sqlite3 --with-mcrypt=/usr/local/libmcrypt/ 

make
make install

假如后續(xù)可能要安裝nginx,則需要--enable-fpm --enable-fastcgi 這兩個編譯選項,nginx是通過php-fpm來和php通信解析php的,--enable-fpm --enable-fastcgi正是為了安裝php-fpm。從php5.3開始集成了php-fpm。之前的版本沒有,需要單獨安裝。

假如人品好,應該就安裝成功了。

//拷貝php.ini

cp php.ini-production /usr/local/php/lib/php.ini

3、與apache關聯(lián)

查看apache的配置文件是否已經(jīng)開啟關聯(lián)(一般情況下,安裝完php后,會開啟,假如沒有開啟則開啟)

vim /usr/local/apache/conf/httpd.conf
LoadModule php5_module modules/libphp5.so

加入以下代碼:

<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>

更改一下代碼:

DirectoryIndex index.html index.shtml index.cgi index.php index.phtml index.php3

找到AddType處,并添加以下2行:

AddType application/x-httpd-php .php .php3 .phtml .inc
AddType application/x-httpd-php-source .phps

4、測試php

    vim /usr/local/apache/htdocs/info.php

輸入代碼:

<?php
phpinfo();
?>

重啟apache

/etc/init.d/httpd restart

訪問:127.0.0.1/info.php 即可看到php的安裝信息,enjoy it!


參考

1、http://www.onepx.com/centos-php-55.html
2、http://blog.163.com/yxba_02/blog/static/1875576201272583532588/

最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容