一. 安裝Apahce伺服器
1. 下載
:http://archive.apache.org/dist/httpd/
下載以下檔案:
httpd-2.2.4.tar.gz
將這個檔案放入/user/local目錄中,並開始安裝。
2.安裝
#tar zxvf httpd-2.2.4.tar.gz#cd httpd-2.2.4#./configure --enable-module=so --enable-dav --enable-dav-fs --enable-so --prefix=/usr/local/apache2 --enable-ssl --with-ssl --enable-track-vars --enable-rewrite --with-z-dir --enable-mods-shared=most (加上SVN模組)#make#make install
錯誤提示:在啟動httpd的時候提示錯誤資訊的,但仍可以啟動成功。
Starting httpd: httpd: apr_sockaddr_info_get() failed for MYHOSThttpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName.
可用以下辦法解決
#vi /etc/hosts127.0.0.1 localhost.localdomain localhost MYHOSTNAME#vi /etc/sysconfig/networkHOSTNAME= MYHOSTNAME#vi /usr/local/apache2/conf/httpd.confServerName MYHOSTNAME:80
二. 安裝PHP伺服器
1. 下載
:http://www.php.net/releases/
下載以下檔案:
php-5.2.1.tar.gz
將這個檔案放入/user/local目錄中,並開始安裝。
2.安裝
# tar -zvxf php-5.2.1.tar.gz# mkdir -p /usr/local/php# cd php-5.2.1#./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-xml --with-png --with-jpeg-dir --with-zlib --with-freetype --with-gd --enable-track-vars --enable-mbstring=all --with-config-file-path=/etc --with-mysql=/usr/local/mysql(注意:如果沒有mysql可以去掉選項)# make# make install
然後進行PHP設定檔配置
[root@centos6-208 php-5.3.8]# cp php.ini-production /usr/local/php/php.ini[root@centos6-208 php-5.3.8]# ./build/shtool install -e ext/phar/phar.phar /usr/local/php/bin/[root@centos6-208 php-5.3.8]# ln -s -f /usr/local/php/bin/phar.phar /usr/local/php/bin/phar
編輯apache設定檔httpd.conf
# vi /usr/local/apache2/conf/httpd.conf
找到LoadModule php5_module modules/libphp5.so預設前面的#號已去掉,如果未去掉應該手工去掉#。
找到#AddType application/x-gzip .gz .tgz並在下面加二行
AddType application/x-httpd-php .phpAddType application/x-httpd-php-source .php5
找到DirectoryIndex一行改為
DirectoryIndex index.htm index.php index.html
找到Options Index FollowSymLinks一行修改為
Options FollowSymLinks
3.驗證
cd /usr/local/apache2/htdocs/mv index.html index.phpvi index.php
在裡面加上如下內容
<? phpinfo();?>
然後重新啟動apache伺服器
/usr/local/apache2/bin/apachectl restart
重啟成功之後,在瀏覽器中輸入http://localhost或者http://XXX.XXX.XXX.XXX(xxx.xxx.xxx.xxx為本機ip)進行測試,如果能正常顯示,則apache和php配置成功
4.修改apache啟動並執行根目錄
vi /usr/local/apache2/conf/httpd.conf
找到以下兩行並修改為
DocumentRoot "/var/www"<Directory "/var/www">
修改完畢之後,重啟apache伺服器,則代碼可放到/var/www/html目錄中
5.設定開機自動啟動
vi /etc/rc.d/rc.local
在裡面加入一行
/usr/local/apache2/bin/apachetcl restart
然後儲存退出即可。
註:http://mirrors.sohu.com/ ,此網站有很多系統的源碼包,當安裝以上軟體時出現軟體依賴問題,可來此處找依賴包安裝解決。