Debian 5 VPS下的Nginx+PHP+MySQL的解決方案

來源:互聯網
上載者:User

本文介紹在Debian 5 VPS下的nginx+php+mysql的解決方案,本方案使用php-fpm作為fastcgi的進程管理器。

本文基於64位的Debian 5 VPS,如果是32位的Debian VPS,請在相應部分做修改。

使用php-fpm就必須重新編譯php,不能使用系統內建的php。MySQL使用Debian內建的,Nginx是從Debian官方軟體庫中下載的最新版本。



安裝Nginx
Debian 5系統內建的nginx版本比較低,現在Nginx的新穩定版本0.7.61,即將發行的Debian 6裡面帶的是最新版本的nginx,測試後發現這個nginx在Debian 5下可以運行。安裝命令:

wget http://ftp.us.debian.org/debian/pool/main/n/nginx/nginx_0.7.61-2_amd64.deb
dpkg -i nginx_0.7.61-2_amd64.deb
/etc/init.d/nginx start
mkdir -p /var/www/nginx-default
echo ‘nginx ok’>/var/www/nginx-default/index.html
echo ‘‘ > /var/www/nginx-default/test.php

另外運行dpkg -L nginx命令可以看到nginx的檔案都安裝在哪些目錄下面了

Debian下nginx的預設網頁目錄是/var/www/nginx-default,這個目錄安裝的時候沒有建立,我們是手工建立的。

通過瀏覽器訪問,應該能看到nginx的預設網頁了,說明nginx正常工作了!

安裝MySQL
我們使用Debian內建的MySQL,安裝命令:

apt-get install mysql-server-5.0
/etc/init.d/mysql start

運行mysql -uroot -p命令,應該可以正常串連到MySQL

安裝php & php-fpm
安裝php所需要的庫檔案:

apt-get update
apt-get install libxml2 libldap-2.4-2 libmhash2 curl libpng3 libjpeg62 libsasl2-2 libmcrypt4

到http://rashost.com/download 下載安裝我們自己在Debian下編譯的php-fpm:

cd /opt
tar zxf php-fpm-5.2.10-amd64.tar.gz
ln -s /opt/php/sbin/php-fpm /etc/init.d/php-fpm
update-rc.d -f php-fpm defaults
/etc/init.d/php-fpm start

整合
首先在/var/www/nginx-default目錄下建立檔案test.php,其內容很簡單,只要下面一行:


假設所在VPS的地址是debian5.rashost.com,這時通過瀏覽器訪問http://debian5.rashost.com/test.php是得不到正確的顯示結果的。

修改nginx的設定檔/etc/nginx/sites-enabled/default,在檔案內搜尋fastcgi_pass,修改該部分內容為:

location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/nginx-default/$fastcgi_script_name;
include fastcgi_params;
}

注意,Debian下的nginx設定檔和centos下的區別比較大,Debian下把配置分割成多個檔案了,推薦一個網站一個設定檔,我們修改的是/etc/nginx/sites-enabled/default。另外fastcgi_param參數後面的/var/www/nginx-default/部分,這是具體的網頁目錄,如果像Debian下那樣寫成$document_root不知道為什麼就不工作了。

然後重啟nginx:

/etc/init.d/nginx/restart

然後在瀏覽器中訪問test.php頁面,http://ubuntuone.cn就應該能正確顯示了,reboot VPS測試一下,各個模組應該都能內建啟動。大功告成!
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.