Nginx + PHP(FastCGI)安裝配置筆記

來源:互聯網
上載者:User

這是站長在2011年時一次安裝伺服器時所記錄的Nginx和PHP的安裝筆記。安裝過程記錄的比較簡略,僅僅是一個大致的流程,一些細節描述的不夠詳細,請多多諒解,我會在日後重新整理一份詳細的安裝過程,本文僅供參考!

軟體環境:CentOS 5.7 + PHP 5.2.17 + Nginx 0.8.55

 

1. 編譯安裝 PHP 和 PHP-FPM

提示:

安裝PHP前應先安裝MySQL,具體方法請自行baidu或google;
PHP所需支援庫的安裝這裡不做過多介紹,可上網搜尋參照相關教程進行安裝。
從http://php-fpm.org/downloads/下載與當前PHP版本對應的PHP-FPM源碼包,例如:php-5.2.17-fpm-0.5.14.diff.gz
tar zxvf php-5.2.17.tar.gz
gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1
cd php-5.2.17
./configure –prefix=/usr/local/php/ –with-config-file-path=/usr/local/php/etc –with-mysql=/usr/local/mysql/ –with-pdo-mysql=/usr/local/mysql/ –with-gd –with-zlib –with-curl –with-jpeg-dir –with-png-dir –with-libxml-dir –with-freetype-dir –with-iconv=/usr/local –with-mcrypt –enable-fastcgi –enable-fpm –enable-xml –enable-mbstring
make
make install
cp php.ini-dist /usr/local/php/etc/php.ini

注意:上面配置PHP編譯參數中的–enable-fastcgi是必須開啟的。

 

2. 建立 Nginx 使用的使用者和使用者組

groupadd www
useradd -g www www

 

3. 建立網站目錄並設定許可權

mkdir -p /htdocs/www
chmod +w /htdocs/www
chown -R www:www /htdocs/www

 

4. 安裝 Nginx 所需的 PCRE 庫

tar zxvf pcre-8.13.tar.gz
cd pcre-8.13
./configure
make
make install

 

5. 安裝 Nginx

tar zxvf nginx-0.8.55.tar.gz
cd nginx-0.8.55
./configure –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module –user=www –group=www
make
make install

 

6. 配置 Nginx,建立虛擬機器主機

在 nginx.conf 檔案的 http{…} 段中,增加一個 server{…} 段,例如下面的代碼:

server {
listen 80;
server_name www.youdomain.com; #你的網域名稱
root /htdocs/www;
access_log logs/www.access.log;
location / {
index index.html index.php;
}
error_page 500 502 503 504  /50x.html;
location = /50x.html {
root html;
}
location ~ .*\.php?$ {
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
include        fastcgi.conf;
}
location ~ /nginx_info {
access_log off;
stub_status on;
}
}

注意:上面的配置中,增加了location ~ /nginx_info {…},這樣就可以通過http://www.youdomain.com/nginx_info/來查詢Nginx的狀態資訊了。

 

啟動 PHP-FPM

/usr/local/php/sbin/php-fpm start

 

啟動 Nginx

/usr/local/nginx/sbin/nginx

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.