Nginx php環境配置安裝方法

來源:互聯網
上載者:User

nginx 0.7.x + php教程 5.2.10(fastcgi)搭建勝過apache十倍的web伺服器(第5版) 編寫
原文地址
http://blog.s135.com/nginx_php_v5/
因為編譯過程和等待時間繁瑣,於是就自己寫了個全自動安裝的shell指令碼,此指令碼可以隨意修改,轉載請註明出處。
這篇文章為這個系列的第二版,在第一版的基礎上加入
1、日誌切割
2、智能選擇yum或者rpm安裝
下載地址
注意:如果不能使用yum源,請放入系統光碟片,單張dvd的,如果是多張光碟片請務必在光碟片裡找到所有要安裝的rpm包,拷貝到一個目錄,並修改
umount /dev/cdrom
mkdir /mnt/cdrom_$$
mount /dev/cdrom /mnt/cdrom_$$
cd /mnt/cdrom_$$/
rpmpath=$(find $(pwd) -name ‘kernel-2*')
rpmpath=${rpmpath%/*}
cd ${rpmpath}

cd yourdir
yourdir為你所有包的存放根路徑
下載後
#unzip install.zip
#chmod +x install.sh
#./install.sh
請以root許可權執行
注意:此指令碼很多參數是按照大負載伺服器的配置,如果是虛擬機器做實驗,可能造成有些服務啟動不起來,比如說mysql教程的參數需要大記憶體支援,此時請手動修改配置參數

這是我從網站找到的

利用linux nginx架設高效能的web環境 linux nginx ("engine x") 是一個高效能的 http 和反向 Proxy伺服器,也是一個 imap/pop3/smtp Proxy 伺服器。 linux nginx 是由 igor sysoev 為俄羅斯訪問量第二的 rambler.ru 網站開發的,它已經在該網站運行超過兩年半了。igor 將原始碼以類bsd許可證的形式發布。
linux nginx 超越 apache 的高效能和穩定性,使得國內使用linux nginx作為 網頁伺服器的網站也越來越多,其中包括新浪部落格、新浪播客、網易新聞等門戶網站頻道,六間房、56.com等視頻分享網站,discuz!官方論壇、水木社區等知名論壇,豆瓣、yupoo相簿、海內sns、迅雷線上等新興web 2.0網站。
實驗環境ubuntu
1、安裝linux nginx
 
  1. # tar -zxvf nginx-0.8.5.tar.gz
  2. # cd nginx-0.8.5
  3. # ./configure --prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module –with-http_gzip_static_module –with-http_ssl_module(安裝路徑及
  4. 所需依賴包)--prefix(安裝路徑)
  5. # make && make install
  1. 啟動nginx# /usr/local/nginx/sbin/nginx
  2. 停止nginx# kill -quit `cat /usr/local/nginx/logs/nginx.pid`
  3. 重啟nginxkill -hup `cat /usr/local/nginx/logs/nginx.pid`
  4. 添加到自啟動# echo "/usr/local/nginx/sbin/nginx">>/etc/rc.local
或者用 /usr/local/nginx/sbin/nginx 啟動 nginx
/usr/local/nginx/sbin/nginx -s quit 退出nginx
/usr/local/nginx/sbin/nginx -s reload 重新載入
還需要安裝 apt-get install spawn-fcgi
每次啟動並執行時候執行:告訴php需要相應的連接埠號碼 跟之前做的java一樣
spawn-fcgi -a 127.0.0.1 -p 9000 -c 5 -u www-data -g www-data -f
/usr/bin/php-cgi(必須滴)
2、spawn-fcgi,用來啟動php的fastcgi模式
(linux下載包用 wget方式 或者可以直接安裝用apt-get install spawn-fcgi方式)
wget http://www.lighttpd.net/download/spawn-fcgi-1.6.3.tar.gz
tar -zxf spawn-fcgi-1.6.3.tar.gz
cd spawn-fcgi-1.6.3
./configure –bindir=/usr/bin –libdir=/usr/lib –prefix=/etc
make&&make install
3、安裝mysql
 
  1. # tar -zxvf mysql-5.0.67.tar.gz
  2. # cd mysql-5.0.67
  3. # groupadd mysql
  4. # useradd -g mysql -s /sbin/nologin -m mysql
  5. # ./configure --prefix=/usr/local/mysql --with-charset=gbk --with-extra-charset=all --enable-hread-safe-client
    --enable-local-infile --with-low-memory
  6. # make && make install
  7. # cp support-files/my-medium.cnf   /etc/my.cnf
  8. # chown -r mysql.mysql /usr/local/mysql/
  9. # /usr/local/mysql/bin/mysql_install_db --user=mysql
  10. # chown -r root.root /usr/local/mysql/
  11. # chown -r mysql.mysql /usr/local/mysql/var/
啟動資料庫教程服務,並添加到自啟動
 
  1. # /usr/local/mysql/bin/mysqld_safe --user=mysql &
  2. #cp   support-files/mysql.server   /etc/rc.d/init.d/mysqld
  3. #chmod   755   /etc/rc.d/init.d/mysqld
加入自動啟動服務隊列:
 
  1. #chkconfig --add mysqld
  2. #chkconfig   --level   345   mysqld   on添加root密碼
  3. # /usr/local/mysql/bin/mysqladmin -u root password "123456"
  4. 測試一下:# /usr/local/mysql/bin/mysql -u root -p輸入密碼:123456,看能不能進入到資料庫
配置庫檔案搜尋路徑
 
  1. # echo "/usr/local/mysql/lib/mysql">>/etc/ld.so.conf
  2. # ldconfig
  3. # ldconfig -v
  4. 添加/usr/local/mysql/bin到環境變數path中
  5. #echo "export path=$path:/usr/local/mysql/bin">>/etc/profile
  6. #source /etc/profile
4、安裝php
這裡產生的是可執行檔,和apache的不一樣,和apache結合的時候產生的是動態庫
 
  1. # tar -jxvf php-5.2.6.tar.bz2
  2. # gzip -cd php-5.2.6-fpm-0.5.9.diff.gz |patch -d php-5.2.6 -p1
  3. # cd php-5.2.6
  4. # ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --enable-fastcgi --enable-fpm
  5. --with-config-file-path=/usr/local/php/etc --enable-force-cgi-redirect
  6. # make && make install
  7. # cp php.ini-recommended /usr/local/php/etc/php.ini
  8. # vi /usr/local/php/php-fpm.conf
 
  1. (1)<value name="listen_address">127.0.0.1:9000</value>修改為<value name="listen_address">ip:9000</value>  
    //本機就用預設的127.0.0.1
  2. (2)下面這兩行去掉注釋並修改                       
  3. <value name="sendmail_path">/usr/sbin/sendmail -t -i</value>
  4. <value name="display_errors">1</value>
  5. (3)<value name="user">nobody</value>    //去注釋
  6. (4)<value name="group">nobody</value>   //去注釋
  7. (5)<value name="allowed_clients">127.0.0.1</value>    //允許串連的pc,本機就用127.0.0.1
啟動php-fpm# /usr/local/php/sbin/php-fpm start添加到自啟動# echo "/usr/local/php/sbin/php-fpm start">>/etc/rc.local
5、修改linux nginx的設定檔,支援php
 
  1. # vim /usr/local/nginx/conf/nginx.conf
  2. user   nobody;
  3. worker_processes   8;
  4. pid   /usr/local/nginx/logs/nginx.pid;
  5. worker_rlimit_nofile 1024;
  6. events
  7. {use epoll;
  8. worker_connections 1024;}
  9. http{
  10. include        mime.types;
  11. default_type   application/octet-stream;
  12. server_names_hash_bucket_size 128;
  13. client_header_buffer_size 32k;
  14. large_client_header_buffers 4 32k;
  15. client_max_body_size 8m;
 
  1. sendfile on;
  2. tcp_nopush      on;
  3. keepalive_timeout 60;
  4. tcp_nodelay on;
  5. fastcgi_connect_timeout 300;
  6. fastcgi_send_timeout 300;
  7. fastcgi_read_timeout 300;
  8. fastcgi_buffer_size 64k;
  9. fastcgi_buffers 4 64k;
  10. fastcgi_busy_buffers_size 128k;
  11. fastcgi_temp_file_write_size 128k;
  12. gzip on;
  13. gzip_min_length   1k;
  14. gzip_buffers      4 16k;
  15. gzip_http_version 1.0;
  16. gzip_comp_level 2;
  17. gzip_types        text/plain application/x-網頁特效 text/css教程 application/xml;
  18. gzip_vary on;
  19.  
  20. server {
  21. listen        80;
  22. server_name   www.bbb.com;
  23. root    /www/uuweb;
  24. index   index.html index.htm index.php;
  25. location ~ .*.(php|php5)?$ { 或者 location / {
  26. 不知道怎麼回事我用前一個css不起作用,只能用後面一個。
  27. root            /www/uuweb;
  28. fastcgi_pass    127.0.0.1:9000;    
  29. fastcgi_index   index.php;
  30. fastcgi_param   script_filename   /www/uuweb$fastcgi_script_name;
  31. include         fastcgi_params;}
  32. #location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
  33. #{expires       30d;}
  34. #location ~ .*.(js|css)?$
  35. #{expires       1h;}   
  36. log_format   access   '$remote_addr - $remote_user [$time_local] "$request" '
  37. '$status $body_bytes_sent "$http_referer" '
  38. '"$http_user_agent" $http_x_forwarded_for';
  39. access_log   /var/logs/access.log   access;}}
註:server部分為php虛擬機器主機127.0.0.1:9000為fastcgi的pc,我這裡用的本機/www/uuweb$fastcgi_script_name; 為php網頁儲存的目錄測試組態檔案:
# /usr/local/nginx/sbin/nginx -t
相關文章

聯繫我們

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