1分鐘完美安裝最新CentOS+Nginx+PHP-FPM+MySQL_PHP教程

來源:互聯網
上載者:User
PHP 5.3.1

MySQL 5.0.89

Nginx 0.8.33 或 0.7.65 (可選)

現在,我們可以快速全自動搞定 CentOS + Nginx + PHP-FPM + MySQL 的安裝了

這個可比網上流傳的什麼一鍵安裝包要好得多,強烈推薦此法安裝,適合所有菜鳥和高手

我伺服器上全用的原始碼編譯安裝,也好不到哪去,還很費勁

我這個裝完已經包含PHP的一些常用擴充, PDO,eaccelerator,memcache,tidy等等

先建立一個 repo

  
  1. # vi /etc/yum.repos.d/centos.21andy.com.repo

放入如下內容

 
  1. [21Andy.com]
  2. name=21Andy.com Packages for Enterprise Linux 5 - $basearch
  3. baseurl=http://www.21andy.com/centos/5/$basearch/
  4. enabled=1
  5. gpgcheck=0
  6. protect=1

啟用 EPEL repo

i386

 
  1. rpm -ihv
  2. http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm

x86_64

 
  1. rpm -ihv
  2. http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm

接著匯入key

 
  1. rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL

好了,一鍵安裝

 
  1. # yum install nginx php-fpm mysql-server

如果 nginx 你要用 0.7.65 最新穩定版,把yum -y install nginx換成yum -y install nginx-stable就可以了

更完整的安裝

 
  1. yum -y update
  2. yum -y mysql-server
  3. service mysqld start
  4. mysqladmin -u root password root
  5. service mysqld stop
  6. yum -y install nginx php-fpm
  7. php-cli php-pdo php-mysql php-mcrypt php-mbstring
  8. php-gd php-tidy php-xml php-xmlrpc
  9. php-pear php-pecl-memcache php-eaccelerator
  10. # APC 和 eAccelerator 有衝突,2選1
  11. yum -y install php-pecl-apc

看下我的完整安裝,只要一句

yum -y install nginx mysql-server php-fpm php-cli php-pdo php-mysql php-mcrypt php-mbstring php-gd php-tidy php-xml php-xmlrpc php-pear php-pecl-memcache php-eaccelerator

安裝結果,全自動

 
  1. Dependencies Resolved
  2. ==========================================================
  3. Package Arch Version Repository Size
  4. ==========================================================
  5. Installing:
  6. mysql x86_64 5.0.89-1.el5 21Andy.com 3.5 M
  7. mysql-server x86_64 5.0.89-1.el5 21Andy.com 10 M
  8. nginx x86_64 0.8.33-3.el5 21Andy.com 422 k
  9. php-cli x86_64 5.3.1-2.el5 21Andy.com 2.4 M
  10. php-eaccelerator x86_64 2:0.9.6-1.el5 21Andy.com 118 k
  11. php-fpm x86_64 5.3.1-2.el5 21Andy.com 1.2 M
  12. php-gd x86_64 5.3.1-2.el5 21Andy.com 110 k
  13. php-mbstring x86_64 5.3.1-2.el5 21Andy.com 1.1 M
  14. php-mcrypt x86_64 5.3.1-2.el5 21Andy.com 27 k
  15. php-mysql x86_64 5.3.1-2.el5 21Andy.com 84 k
  16. php-pdo x86_64 5.3.1-2.el5 21Andy.com 91 k
  17. php-pear noarch 1:1.9.0-1.el5 21Andy.com 420 k
  18. php-pecl-memcache x86_64 2.2.5-3.el5 21Andy.com 44 k
  19. php-tidy x86_64 5.3.1-2.el5 21Andy.com 31 k
  20. php-xml x86_64 5.3.1-2.el5 21Andy.com 115 k
  21. php-xmlrpc x86_64 5.3.1-2.el5 21Andy.com 48 k
  22. Installing for dependencies:
  23. gmp x86_64 4.1.4-10.el5 base 201 k
  24. libXaw x86_64 1.0.2-8.1 base 329 k
  25. libXmu x86_64 1.0.2-5 base 63 k
  26. libXpm x86_64 3.5.5-3 base 44 k
  27. libedit x86_64 2.11-2.20080712cvs.el5 epel 80 k
  28. libmcrypt x86_64 2.5.8-4.el5.centos extras 105 k
  29. libtidy x86_64 0.99.0-14.20070615.el5 epel 140 k
  30. php-common x86_64 5.3.1-2.el5 21Andy.com 554 k
  31. sqlite2 x86_64 2.8.17-5.el5 21Andy.com 165 k
  32. t1lib x86_64 5.1.1-7.el5 epel 208 k
  33. Updating for dependencies:
  34. libevent x86_64 1.4.12-1.el5 21Andy.com 129 k
  35. Transaction Summary
  36. ==========================================================
  37. Install 26 Package(s)
  38. Update 1 Package(s)
  39. Remove 0 Package(s

最後只要 yum -y update 一下,全是最新的

別忘了開機啟動

 
  1. chkconfig --level 345 mysqld on
  2. chkconfig --level 345 php-fpm on
  3. chkconfig --level 345 nginx on

來看看我用虛擬機器測試的強大結果

http://www.21andy.com/blog/20100219/1703.html

補充:所有的設定檔都在 /etc 目錄下,包括 nginx, php-fpm, mysql 的設定檔,請自行尋找設定,以下為我的 nginx 的配置範例

先建立一個 /www 目錄,網站和日誌也全放在這裡

別忘了建日誌存放目錄,你在設定檔中 access_log 用到的 /www/logs

注意:fastcgi_params 要加入這一行

# vim /etc/nginx/fastcgi_params

 
  1. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

# vi /etc/nginx/nginx.conf

 
  1. user nobody nobody;
  2. worker_processes 8; #這雷根據你的CPU和記憶體配置, 設定2到10都OK
  3. error_log /www/logs/nginx_error.log crit;
  4. pid /usr/local/nginx/logs/nginx.pid;
  5. #Specifies the value for maximum file descriptors that can be opened by this process.
  6. worker_rlimit_nofile 51200;
  7. events {
  8. use epoll;
  9. worker_connections 51200;
  10. }
  11. http {
  12. include mime.types;
  13. default_type application/octet-stream;
  14. #charse gb2312; # 預設編碼,可以不設定
  15. server_names_hash_bucket_size 128;
  16. client_header_buffer_size 16k;
  17. large_client_header_buffers 4 16k;
  18. client_max_body_size 8m;
  19. sendfile on;
  20. tcp_nopush on;
  21. keepalive_timeout 60;
  22. tcp_nodelay on;
  23. fastcgi_connect_timeout 300;
  24. fastcgi_send_timeout 300;
  25. fastcgi_read_timeout 300;
  26. fastcgi_buffer_size 64k;
  27. fastcgi_buffers 4 64k;
  28. fastcgi_busy_buffers_size 128k;
  29. fastcgi_temp_file_write_size 128k;
  30. gzip on;
  31. gzip_min_length 1k;
  32. gzip_buffers 4 16k;
  33. gzip_http_version 1.0;
  34. gzip_comp_level 5;
  35. gzip_types text/plain text/javascript application/x-javascript text/css application/xml;
  36. gzip_vary on;
  37. #limit_zone crawler $binary_remote_addr 10m;
  38. server {
  39. listen 80;
  40. server_name localhost;
  41. root /www;
  42. location /status {
  43. stub_status on;
  44. access_log off;
  45. }
  46. location / {
  47. # 這裡是把所有不存在的檔案和目錄,全都轉到 index.php 處理
  48. try_files $uri $uri/ /index.php?q=$uri&$args;
  49. }
  50. # 這裡分開放到 server.conf 是為了再開 server 的時候方便,統一調用,放到/etc/nginx/ 目錄下
  51. include server.conf;
  52. log_format access '$remote_addr - $remote_user [$time_local] "$request" '
  53. '$status $body_bytes_sent "$http_referer" '
  54. '"$http_user_agent" $http_x_forwarded_for';
  55. access_log /www/logs/access.log access;
  56. }
  57. server {
  58. listen 80;
  59. server_name www.21andy.com 21andy.com *.21andy.com;
  60. root /www/21andy.com;
  61. if ($host !~* 21andy.com$) {
  62. return 444;
  63. }
  64. location / {
  65. try_files $uri $uri/ /index.php?q=$uri&$args;
  66. }
  67. include server.conf; # 這裡複用了,這段就省了
  68. access_log /www/logs/21andy.com_access.log access;
  69. }
  70. }

# vi /etc/nginx/server.conf

 
  1. index index.html index.htm index.php;
  2. #limit_conn crawler 20;
  3. location ~ /.ht {
  4. deny all;
  5. }
  6. location ~ .*.(sqlite|sq3)$ {
  7. deny all;
  8. }
  9. location ~ .*.php$ {
  10. fastcgi_pass unix:/tmp/php-cgi.sock;
  11. #fastcgi_pass 127.0.0.1:9000;
  12. fastcgi_index index.php;
  13. include fastcgi_params;
  14. }
  15. location ~ .*.(gif|jpg|jpeg|png|bmp|swf|ico)$ {
  16. expires 30d;
  17. access_log off;
  18. }
  19. location ~ .*.(js|css)?$ {
  20. expires 30d;
  21. access_log off;
  22. }

本行以下內容可以略過

php-fpm 也可以用以下設定,但建議用上面的,比較穩定

 
  1. location ~ .php$ {
  2. root /www;
  3. fastcgi_pass 127.0.0.1:9000;
  4. fastcgi_index index.php;
  5. #下面這一行要加在 /etc/nginx/fastcgi_params 裡
  6. #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  7. include fastcgi_params;
  8. }

不管是使用 php-cgi.sock 或 9000 連接埠方法,nginx 和 php-fpm 都要同時設定成一樣的

nginx 的設定上面已經提過,記得同時修改 php-fpm.conf 相應的地方

# vi /etc/php-fpm.conf

127.0.0.1:9000

unix:/tmp/php-cgi.sock

原文地址:http://www.21andy.com/blog/20100219/1701.html


http://www.bkjia.com/PHPjc/445841.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/445841.htmlTechArticlePHP 5.3.1 MySQL 5.0.89 Nginx 0.8.33 或 0.7.65 (可選) 現在,我們可以快速全自動搞定 CentOS + Nginx + PHP-FPM + MySQL 的安裝了 這個可比網上流傳的什麼一鍵...

  • 聯繫我們

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