天天看點

Linux下安裝、配置PHP環境

Linux下安裝、啟動MySQL :http://blog.csdn.net/wy3552128/article/details/8143686

Linux下安裝、配置、啟動Apache:http://blog.csdn.net/wy3552128/article/details/8143875

Mysql和Apache已經安裝成功,接下來我們來安裝、配置PHP環境,編譯PHP5的時候貌似比較複雜,出現了很多問題,都記錄在這裡吧。

平台:VMware上虛拟的centos4.7

主控端:windows

安裝PHP前準備:

1、檢查php是否已經安裝,使用php -v,是否能夠看到版本号;或者使用rpm -qa | grep php檢視是否安裝過。

2、下載下傳PHP安裝包,下載下傳位址:http://www.php.net/downloads.php 我下載下傳的是php-5.3.18.tar.gz,放在Linux的任意目錄下,隻在編譯時指定安裝到的目錄。

tar -zxvf php-5.3.18.tar.gz
cd php-5.3.18      

不過在接下來的configure編譯過程中,遇到了一些比較繁瑣的問題:

1、提示錯誤資訊:configure: error: Cannot find MySQL header files under /var/lib/mysql/

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs  --with-mysql=/var/lib/mysql/      

解決:

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/lib --enable-track-vars --with-xml --with-mysql      

2、提示錯誤資訊:configure: error: Cannot find MySQL header files under yes

解決:此問題主要是由于上面的configure參數中沒有指定--with-mysql路徑。

通過find / -name mysql.h檢視是否存在這個檔案所在路徑,如果不存在,則要安裝MySQL-devel-4.1.12-1.i386.rpm(必須要安裝的)。

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/lib --enable-track-vars --with-xml --with-mysql-dir=/usr/include/mysql/mysql.h      

3、提示錯誤資訊:configure: error: Try adding --with-zlib-dir=<DIR>. Please check config.log for more information.

解決:

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/lib --enable-track-vars --with-xml --with-mysql-dir=/usr/include/mysql/mysql.h --with-zlib-dir=/usr/lib      

編譯PHP完整的configure參數(請注意apache的路徑):

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/lib --enable-track-vars --with-xml --with-mysql-dir=/usr/include/mysql/mysql.h --with-zlib-dir=/usr/lib
make
make install      

把配置php.ini,隻需要把php-5.3.18安裝包中的php.ini-production拷貝到/usr/local/php/lib/下即可。

[root@localhost php-5.3.18]#cp php.ini-production /usr/local/lib/php.ini 
(一定要命名為php.ini,放在/usr/local/lib/路徑下;在編譯時可以指定php.ini的存放位置,也可以在Apache裡指定其位置;如果位置錯誤,php擴充就不發加載,phpinfo()測試頁中看不到擴充資訊)      

-----------------------------------------------還算可以的分割線----------------------------------------------------------------

配置Apache中的PHP環境

需要修改Apache的配置檔案httpd.conf以得到PHP的解析:

1、在LoadModule中添加:LoadModule php5_module     modules/libphp5.so

2、在AddType application/x-gzip .gz .tgz下面添加:

# probably should define those extensions to indicate media types:
    #
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps      
3、在DirectoryIndex增加 index.php,以便Apache識别PHP格式的index      
<IfModule dir_module>  
    DirectoryIndex index.html index.php  
</IfModule>       

最後一步驗證PHP環境:

在Apache網站目錄下建立php的phpinfo測試頁,/usr/local/apache/htdocs/info.php

[root@localhost htdocs]# vi info.php

<?php

phpinfo();

?>      

通過http://192.168.200.102/info.php 驗證,通過phpinfo()可以檢視很多資訊,比如php.ini的存放路徑,以及所有擴充元件等,很強大。

Linux下安裝、配置PHP環境