標籤:編譯安裝php
1、下載解壓php,config
tar zxvf php-xxxx./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqlli=/usr/local/mysql/bin/mysql_config ##php與mysql 串連需要## --enable-mbstring ##支援其他字元## --with-freetype-dir ##字型庫## --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/httpd/bin/apxs ##把php添加成apache模組## --with-mcrypt ##支援加密## --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts
如果要支援fastcgi,把
--with-apxs2=/usr/local/httpd/bin/apxs
改成--enable-fpm
解決mcrypt看上一篇文章,編譯錯誤2次:
yum install -y libxml2 libxml2-devel
yum install -y bzip2 bzip2-devel
說明:
1、這裡為了支援apache的worker或event這兩個MPM,編譯時間使用了--enable-maintainer-zts選項。
2、如果使用PHP5.3以上版本,為了連結MySQL資料庫,可以指定mysqlnd,這樣在本機就不需要先安裝MySQL或MySQL開發包了。mysqlnd從php 5.3開始可用,可以編譯時間綁定到它(而不用和具體的MySQL用戶端庫綁定形成依賴),但從PHP 5.4開始它就是預設設定了。
# ./configure --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd
2、make&&make install
過程省略
3、為php提供設定檔
在php源碼包裡有php.ini-production
cp php.ini-production /etc/php.ini
編輯apache設定檔httpd.conf,讓apache支援php
vim /etc/httpd/httpd.conf
1、添加如下二行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
2、定位至DirectoryIndex index.html
修改為:
DirectoryIndex index.php index.html
重啟httpd
測試php
<?phpphpinfo();?>
測試php是否與mysql串連正常
<?php$con=mysql_connect(‘localhost‘,‘root‘,‘‘);if ($con) echo "success..";else echo "failure...";?>
編譯安裝php