字體:  

安裝最新 CentOS 5.5 + Nginx + php-fpm + MySQL

plurk 發表於: 2010-6-23 12:55 來源: ADJ網路控股集團


PHP 5.3.1
MySQL 5.0.89
Nginx 0.8.33

CentOS 5.5

 

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

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

我服務器上全用的源代碼編譯安裝,也好不到哪去,還很費勁 ...

 

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

本文為 21andy 原创,轉載請以超鏈結方式注明出處 http://www.21andy.com

 

先新建一個 repo

QUOTE:

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

 

放入如下内容

QUOTE:

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

 

啟用 EPEL repo
i386

epel-release-5-4.noarch.rpm
(2012-04-23 22:50:35, Size: 11.9 KB, Downloads: 0)


 

x86_64

QUOTE:

rpm -ihv http://free.nchc.org.tw/fedora-epel/5/x86_64/epel-release-5-4.noarch.rpm

 

接著導入key

QUOTE:

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

 

好了,一鍵安裝

QUOTE:

# yum install nginx php-fpm mysql-server

 

爽吧!

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

 

更完整的安裝,只要一句

QUOTE:

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

 

安裝結果,全自動

QUOTE:

Dependencies Resolved

==========================================================
Package Arch Version Repository Size
==========================================================
Installing:
mysql x86_64 5.0.89-1.el5 21Andy.com 3.5 M
mysql-server x86_64 5.0.89-1.el5 21Andy.com 10 M
nginx x86_64 0.8.33-3.el5 21Andy.com 422 k
php-cli x86_64 5.3.1-2.el5 21Andy.com 2.4 M
php-eaccelerator x86_64 2:0.9.6-1.el5 21Andy.com 118 k
php-fpm x86_64 5.3.1-2.el5 21Andy.com 1.2 M
php-gd x86_64 5.3.1-2.el5 21Andy.com 110 k
php-mbstring x86_64 5.3.1-2.el5 21Andy.com 1.1 M
php-mcrypt x86_64 5.3.1-2.el5 21Andy.com 27 k
php-mysql x86_64 5.3.1-2.el5 21Andy.com 84 k
php-pdo x86_64 5.3.1-2.el5 21Andy.com 91 k
php-pear noarch 1:1.9.0-1.el5 21Andy.com 420 k
php-pecl-memcache x86_64 2.2.5-3.el5 21Andy.com 44 k
php-tidy x86_64 5.3.1-2.el5 21Andy.com 31 k
php-xml x86_64 5.3.1-2.el5 21Andy.com 115 k
php-xmlrpc x86_64 5.3.1-2.el5 21Andy.com 48 k
Installing for dependencies:
gmp x86_64 4.1.4-10.el5 base 201 k
libXaw x86_64 1.0.2-8.1 base 329 k
libXmu x86_64 1.0.2-5 base 63 k
libXpm x86_64 3.5.5-3 base 44 k
libedit x86_64 2.11-2.20080712cvs.el5 epel 80 k
libmcrypt x86_64 2.5.8-4.el5.centos extras 105 k
libtidy x86_64 0.99.0-14.20070615.el5 epel 140 k
php-common x86_64 5.3.1-2.el5 21Andy.com 554 k
sqlite2 x86_64 2.8.17-5.el5 21Andy.com 165 k
t1lib x86_64 5.1.1-7.el5 epel 208 k
Updating for dependencies:
libevent x86_64 1.4.12-1.el5 21Andy.com 129 k

Transaction Summary
==========================================================
Install 26 Package(s)
Update 1 Package(s)
Remove 0 Package(s)

 

 

最後只要 yum -y update 一下,全是最新的
別忘了開機啟動

QUOTE:

chkconfig --level 345 mysqld on
chkconfig --level 345 php-fpm on
chkconfig --level 345 nginx on

 

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

 

網站目錄 /var/www/html

# vi /etc/nginx/nginx.conf

QUOTE:

user nobody nobody;
worker_processes  10;    啟動進程,若是是256MB的VPS最好設定在4-8之間。
worker_rlimit_nofile 100000; 開啟文件數

error_log   /var/log/nginx/error.log;  錯誤信息日誌路徑
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;


events {
    worker_connections  51200;  規定進程的最大連接數
    use epoll;  利用I/O複用模式
}


http {
    include       /etc/nginx/mime.types;  定義文件類型
    default_type  application/octet-stream;

 

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

 

    access_log  /var/log/nginx/access.log  main;  設定訪問日誌

    server_names_hash_bucket_size 128;
    client_header_buffer_size 16k;
    large_client_header_buffers 4 16k;
    client_max_body_size 8m;

    fastcgi_connect_timeout 180;
    fastcgi_send_timeout 180;
    fastcgi_read_timeout 180;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 8 128k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;

 

    sendfile        on;  開啟網路傳輸加快模式

    tcp_nopush      on;  改進TCP的傳輸速率BSD上的好東西
    tcp_nodelay     on;
    server_tokens   off;
    gzip            on;  啟動Gzip傳輸數據
    gzip_static     on;
    gzip_comp_level 5;
    gzip_min_length 1024;
    keepalive_timeout  60;
    #limit_zone   myzone  $binary_remote_addr  10m;

    # Load config files from the /etc/nginx/conf.d directory
    include /etc/nginx/conf.d/*.conf;

}

 

# vi /etc/nginx/conf.d/server.conf

QUOTE:

server {
    listen   80;
    server_name  www.adj.idv.tw;
    access_log  /var/log/nginx/www.adj.idv.tw.access.log;
    error_log   /var/www/html/adj/error.log error;
    charset utf8;

## Default location
    location / {
        root   /var/www/html/adj;
        index  index.php;
    }

 

## Images and static content is treated different
    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
      access_log        on;
      expires           30d;
      root /var/www/html/adj;
    }

## Parse all .php file in the /var/www/html/adj directory
    location ~ .php$ {
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/html/adj$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_param  QUERY_STRING     $query_string;
        fastcgi_param  REQUEST_METHOD   $request_method;
        fastcgi_param  CONTENT_TYPE     $content_type;
        fastcgi_param  CONTENT_LENGTH   $content_length;
        fastcgi_intercept_errors        on;
        fastcgi_ignore_client_abort     off;
        fastcgi_connect_timeout 120;
        fastcgi_send_timeout 180;

        fastcgi_read_timeout 180;
        fastcgi_buffer_size 256k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;

}

 

## Disable viewing .htaccess & .htpassword
    location ~ /\.ht {
        deny  all;
    }
}

 

最後啟動相關服務

QUOTE:

service mysqld start

service php-fpm start

service nginx start

 

這樣就大功告成啦~~

 

相關文件參考:

http://www.howtoforge.com/installing-php-5.3-nginx-and-php-fpm-on-ubuntu-debian
http://wangchengtai.blog.hexun.com.tw/42855094_d.html

 

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

本文為 21andy 原创,轉載請以超鏈結方式注明出處 http://www.21andy.com

 

先新建一個 repo

QUOTE:

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

 

放入如下内容

QUOTE:

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

 

啟用 EPEL repo
i386

[attach]4958[/attach]

 

x86_64

QUOTE:

rpm -ihv http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-5.noarch.rpm

 

接著導入key

QUOTE:

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

 

好了,一鍵安裝

QUOTE:

# yum install nginx php-fpm mysql-server

 

爽吧!

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

 

更完整的安裝,只要一句

QUOTE:

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

 

安裝結果,全自動

QUOTE:

Dependencies Resolved

==========================================================
Package Arch Version Repository Size
==========================================================
Installing:
mysql x86_64 5.0.89-1.el5 21Andy.com 3.5 M
mysql-server x86_64 5.0.89-1.el5 21Andy.com 10 M
nginx x86_64 0.8.33-3.el5 21Andy.com 422 k
php-cli x86_64 5.3.1-2.el5 21Andy.com 2.4 M
php-eaccelerator x86_64 2:0.9.6-1.el5 21Andy.com 118 k
php-fpm x86_64 5.3.1-2.el5 21Andy.com 1.2 M
php-gd x86_64 5.3.1-2.el5 21Andy.com 110 k
php-mbstring x86_64 5.3.1-2.el5 21Andy.com 1.1 M
php-mcrypt x86_64 5.3.1-2.el5 21Andy.com 27 k
php-mysql x86_64 5.3.1-2.el5 21Andy.com 84 k
php-pdo x86_64 5.3.1-2.el5 21Andy.com 91 k
php-pear noarch 1:1.9.0-1.el5 21Andy.com 420 k
php-pecl-memcache x86_64 2.2.5-3.el5 21Andy.com 44 k
php-tidy x86_64 5.3.1-2.el5 21Andy.com 31 k
php-xml x86_64 5.3.1-2.el5 21Andy.com 115 k
php-xmlrpc x86_64 5.3.1-2.el5 21Andy.com 48 k
Installing for dependencies:
gmp x86_64 4.1.4-10.el5 base 201 k
libXaw x86_64 1.0.2-8.1 base 329 k
libXmu x86_64 1.0.2-5 base 63 k
libXpm x86_64 3.5.5-3 base 44 k
libedit x86_64 2.11-2.20080712cvs.el5 epel 80 k
libmcrypt x86_64 2.5.8-4.el5.centos extras 105 k
libtidy x86_64 0.99.0-14.20070615.el5 epel 140 k
php-common x86_64 5.3.1-2.el5 21Andy.com 554 k
sqlite2 x86_64 2.8.17-5.el5 21Andy.com 165 k
t1lib x86_64 5.1.1-7.el5 epel 208 k
Updating for dependencies:
libevent x86_64 1.4.12-1.el5 21Andy.com 129 k

Transaction Summary
==========================================================
Install 26 Package(s)
Update 1 Package(s)
Remove 0 Package(s)

 

 

最後只要 yum -y update 一下,全是最新的
別忘了開機啟動

QUOTE:

chkconfig --level 345 mysqld on
chkconfig --level 345 php-fpm on
chkconfig --level 345 nginx on

 

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

 

網站目錄 /var/www/html

# vi /etc/nginx/nginx.conf

QUOTE:

user nobody nobody;
worker_processes  10;    啟動進程,若是是256MB的VPS最好設定在4-8之間。
worker_rlimit_nofile 100000; 開啟文件數

error_log   /var/log/nginx/error.log;  錯誤信息日誌路徑
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;


events {
    worker_connections  51200;  規定進程的最大連接數
    use epoll;  利用I/O複用模式
}


http {
    include       /etc/nginx/mime.types;  定義文件類型
    default_type  application/octet-stream;

 

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

 

    access_log  /var/log/nginx/access.log  main;  設定訪問日誌

    server_names_hash_bucket_size 128;
    client_header_buffer_size 16k;
    large_client_header_buffers 4 16k;
    client_max_body_size 8m;

    fastcgi_connect_timeout 180;
    fastcgi_send_timeout 180;
    fastcgi_read_timeout 180;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 8 128k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;

 

    sendfile        on;  開啟網路傳輸加快模式

    tcp_nopush      on;  改進TCP的傳輸速率BSD上的好東西
    tcp_nodelay     on;
    server_tokens   off;
    gzip            on;  啟動Gzip傳輸數據
    gzip_static     on;
    gzip_comp_level 5;
    gzip_min_length 1024;
    keepalive_timeout  60;
    #limit_zone   myzone  $binary_remote_addr  10m;

    # Load config files from the /etc/nginx/conf.d directory
    include /etc/nginx/conf.d/*.conf;

}

 

# vi /etc/nginx/conf.d/server.conf

QUOTE:

server {
    listen   80;
    server_name  www.adj.idv.tw;
    access_log  /var/log/nginx/www.adj.idv.tw.access.log;
    error_log   /var/www/html/adj/error.log error;
    charset utf8;

## Default location
    location / {
        root   /var/www/html/adj;
        index  index.php;
    }

 

## Images and static content is treated different
    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
      access_log        on;
      expires           30d;
      root /var/www/html/adj;
    }

## Parse all .php file in the /var/www/html/adj directory
    location ~ .php$ {
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/html/adj$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_param  QUERY_STRING     $query_string;
        fastcgi_param  REQUEST_METHOD   $request_method;
        fastcgi_param  CONTENT_TYPE     $content_type;
        fastcgi_param  CONTENT_LENGTH   $content_length;
        fastcgi_intercept_errors        on;
        fastcgi_ignore_client_abort     off;
        fastcgi_connect_timeout 120;
        fastcgi_send_timeout 180;

        fastcgi_read_timeout 180;
        fastcgi_buffer_size 256k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;

}

 

## Disable viewing .htaccess & .htpassword
    location ~ /\.ht {
        deny  all;
    }
}

 

最後啟動相關服務

QUOTE:

service mysqld start

service php-fpm start

service nginx start

 

這樣就大功告成啦~~

 

相關文件參考:

http://www.howtoforge.com/installing-php-5.3-nginx-and-php-fpm-on-ubuntu-debian
http://wangchengtai.blog.hexun.com.tw/42855094_d.html

 

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

本文為 21andy 原创,轉載請以超鏈結方式注明出處 http://www.21andy.com

 

先新建一個 repo

QUOTE:

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

 

放入如下内容

QUOTE:

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

 

啟用 EPEL repo
i386

[attach]4958[/attach]

 

x86_64

QUOTE:

rpm -ihv http://free.nchc.org.tw/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm

 

接著導入key

QUOTE:

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

 

好了,一鍵安裝

QUOTE:

# yum install nginx php-fpm mysql-server

 

爽吧!

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

 

更完整的安裝,只要一句

QUOTE:

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

 

安裝結果,全自動

QUOTE:

Dependencies Resolved

==========================================================
Package Arch Version Repository Size
==========================================================
Installing:
mysql x86_64 5.0.89-1.el5 21Andy.com 3.5 M
mysql-server x86_64 5.0.89-1.el5 21Andy.com 10 M
nginx x86_64 0.8.33-3.el5 21Andy.com 422 k
php-cli x86_64 5.3.1-2.el5 21Andy.com 2.4 M
php-eaccelerator x86_64 2:0.9.6-1.el5 21Andy.com 118 k
php-fpm x86_64 5.3.1-2.el5 21Andy.com 1.2 M
php-gd x86_64 5.3.1-2.el5 21Andy.com 110 k
php-mbstring x86_64 5.3.1-2.el5 21Andy.com 1.1 M
php-mcrypt x86_64 5.3.1-2.el5 21Andy.com 27 k
php-mysql x86_64 5.3.1-2.el5 21Andy.com 84 k
php-pdo x86_64 5.3.1-2.el5 21Andy.com 91 k
php-pear noarch 1:1.9.0-1.el5 21Andy.com 420 k
php-pecl-memcache x86_64 2.2.5-3.el5 21Andy.com 44 k
php-tidy x86_64 5.3.1-2.el5 21Andy.com 31 k
php-xml x86_64 5.3.1-2.el5 21Andy.com 115 k
php-xmlrpc x86_64 5.3.1-2.el5 21Andy.com 48 k
Installing for dependencies:
gmp x86_64 4.1.4-10.el5 base 201 k
libXaw x86_64 1.0.2-8.1 base 329 k
libXmu x86_64 1.0.2-5 base 63 k
libXpm x86_64 3.5.5-3 base 44 k
libedit x86_64 2.11-2.20080712cvs.el5 epel 80 k
libmcrypt x86_64 2.5.8-4.el5.centos extras 105 k
libtidy x86_64 0.99.0-14.20070615.el5 epel 140 k
php-common x86_64 5.3.1-2.el5 21Andy.com 554 k
sqlite2 x86_64 2.8.17-5.el5 21Andy.com 165 k
t1lib x86_64 5.1.1-7.el5 epel 208 k
Updating for dependencies:
libevent x86_64 1.4.12-1.el5 21Andy.com 129 k

Transaction Summary
==========================================================
Install 26 Package(s)
Update 1 Package(s)
Remove 0 Package(s)

 

 

最後只要 yum -y update 一下,全是最新的
別忘了開機啟動

QUOTE:

chkconfig --level 345 mysqld on
chkconfig --level 345 php-fpm on
chkconfig --level 345 nginx on

 

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

 

網站目錄 /var/www/html

# vi /etc/nginx/nginx.conf

QUOTE:

user nobody nobody;
worker_processes  10;    啟動進程,若是是256MB的VPS最好設定在4-8之間。
worker_rlimit_nofile 100000; 開啟文件數

error_log   /var/log/nginx/error.log;  錯誤信息日誌路徑
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;


events {
    worker_connections  51200;  規定進程的最大連接數
    use epoll;  利用I/O複用模式
}


http {
    include       /etc/nginx/mime.types;  定義文件類型
    default_type  application/octet-stream;

 

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

 

    access_log  /var/log/nginx/access.log  main;  設定訪問日誌

    server_names_hash_bucket_size 128;
    client_header_buffer_size 16k;
    large_client_header_buffers 4 16k;
    client_max_body_size 8m;

    fastcgi_connect_timeout 180;
    fastcgi_send_timeout 180;
    fastcgi_read_timeout 180;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 8 128k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;

 

    sendfile        on;  開啟網路傳輸加快模式

    tcp_nopush      on;  改進TCP的傳輸速率BSD上的好東西
    tcp_nodelay     on;
    server_tokens   off;
    gzip            on;  啟動Gzip傳輸數據
    gzip_static     on;
    gzip_comp_level 5;
    gzip_min_length 1024;
    keepalive_timeout  60;
    #limit_zone   myzone  $binary_remote_addr  10m;

    # Load config files from the /etc/nginx/conf.d directory
    include /etc/nginx/conf.d/*.conf;

}

 

# vi /etc/nginx/conf.d/server.conf

QUOTE:

server {
    listen   80;
    server_name  www.adj.idv.tw;
    access_log  /var/log/nginx/www.adj.idv.tw.access.log;
    error_log   /var/www/html/adj/error.log error;
    charset utf8;

## Default location
    location / {
        root   /var/www/html/adj;
        index  index.php;
    }

 

## Images and static content is treated different
    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
      access_log        on;
      expires           30d;
      root /var/www/html/adj;
    }

## Parse all .php file in the /var/www/html/adj directory
    location ~ .php$ {
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/html/adj$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_param  QUERY_STRING     $query_string;
        fastcgi_param  REQUEST_METHOD   $request_method;
        fastcgi_param  CONTENT_TYPE     $content_type;
        fastcgi_param  CONTENT_LENGTH   $content_length;
        fastcgi_intercept_errors        on;
        fastcgi_ignore_client_abort     off;
        fastcgi_connect_timeout 120;
        fastcgi_send_timeout 180;

        fastcgi_read_timeout 180;
        fastcgi_buffer_size 256k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;

}

 

## Disable viewing .htaccess & .htpassword
    location ~ /\.ht {
        deny  all;
    }
}

 

最後啟動相關服務

QUOTE:

service mysqld start

service php-fpm start

service nginx start

 

這樣就大功告成啦~~

 

相關文件參考:

http://www.howtoforge.com/installing-php-5.3-nginx-and-php-fpm-on-ubuntu-debian
http://wangchengtai.blog.hexun.com.tw/42855094_d.html

 

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

本文為 21andy 原创,轉載請以超鏈結方式注明出處 http://www.21andy.com

 

先新建一個 repo

QUOTE:

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

 

放入如下内容

QUOTE:

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

 

啟用 EPEL repo
i386

[attach]4958[/attach]

 

x86_64

QUOTE:

rpm -ihv http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-5.noarch.rpm

 

接著導入key

QUOTE:

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

 

好了,一鍵安裝

QUOTE:

# yum install nginx php-fpm mysql-server

 

爽吧!

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

 

更完整的安裝,只要一句

QUOTE:

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

 

安裝結果,全自動

QUOTE:

Dependencies Resolved

==========================================================
Package Arch Version Repository Size
==========================================================
Installing:
mysql x86_64 5.0.89-1.el5 21Andy.com 3.5 M
mysql-server x86_64 5.0.89-1.el5 21Andy.com 10 M
nginx x86_64 0.8.33-3.el5 21Andy.com 422 k
php-cli x86_64 5.3.1-2.el5 21Andy.com 2.4 M
php-eaccelerator x86_64 2:0.9.6-1.el5 21Andy.com 118 k
php-fpm x86_64 5.3.1-2.el5 21Andy.com 1.2 M
php-gd x86_64 5.3.1-2.el5 21Andy.com 110 k
php-mbstring x86_64 5.3.1-2.el5 21Andy.com 1.1 M
php-mcrypt x86_64 5.3.1-2.el5 21Andy.com 27 k
php-mysql x86_64 5.3.1-2.el5 21Andy.com 84 k
php-pdo x86_64 5.3.1-2.el5 21Andy.com 91 k
php-pear noarch 1:1.9.0-1.el5 21Andy.com 420 k
php-pecl-memcache x86_64 2.2.5-3.el5 21Andy.com 44 k
php-tidy x86_64 5.3.1-2.el5 21Andy.com 31 k
php-xml x86_64 5.3.1-2.el5 21Andy.com 115 k
php-xmlrpc x86_64 5.3.1-2.el5 21Andy.com 48 k
Installing for dependencies:
gmp x86_64 4.1.4-10.el5 base 201 k
libXaw x86_64 1.0.2-8.1 base 329 k
libXmu x86_64 1.0.2-5 base 63 k
libXpm x86_64 3.5.5-3 base 44 k
libedit x86_64 2.11-2.20080712cvs.el5 epel 80 k
libmcrypt x86_64 2.5.8-4.el5.centos extras 105 k
libtidy x86_64 0.99.0-14.20070615.el5 epel 140 k
php-common x86_64 5.3.1-2.el5 21Andy.com 554 k
sqlite2 x86_64 2.8.17-5.el5 21Andy.com 165 k
t1lib x86_64 5.1.1-7.el5 epel 208 k
Updating for dependencies:
libevent x86_64 1.4.12-1.el5 21Andy.com 129 k

Transaction Summary
==========================================================
Install 26 Package(s)
Update 1 Package(s)
Remove 0 Package(s)

 

 

最後只要 yum -y update 一下,全是最新的
別忘了開機啟動

QUOTE:

chkconfig --level 345 mysqld on
chkconfig --level 345 php-fpm on
chkconfig --level 345 nginx on

 

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

 

網站目錄 /var/www/html

# vi /etc/nginx/nginx.conf

QUOTE:

user nobody nobody;
worker_processes  10;    啟動進程,若是是256MB的VPS最好設定在4-8之間。
worker_rlimit_nofile 100000; 開啟文件數

error_log   /var/log/nginx/error.log;  錯誤信息日誌路徑
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;


events {
    worker_connections  51200;  規定進程的最大連接數
    use epoll;  利用I/O複用模式
}


http {
    include       /etc/nginx/mime.types;  定義文件類型
    default_type  application/octet-stream;

 

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

 

    access_log  /var/log/nginx/access.log  main;  設定訪問日誌

    server_names_hash_bucket_size 128;
    client_header_buffer_size 16k;
    large_client_header_buffers 4 16k;
    client_max_body_size 8m;

    fastcgi_connect_timeout 180;
    fastcgi_send_timeout 180;
    fastcgi_read_timeout 180;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 8 128k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;

 

    sendfile        on;  開啟網路傳輸加快模式

    tcp_nopush      on;  改進TCP的傳輸速率BSD上的好東西
    tcp_nodelay     on;
    server_tokens   off;
    gzip            on;  啟動Gzip傳輸數據
    gzip_static     on;
    gzip_comp_level 5;
    gzip_min_length 1024;
    keepalive_timeout  60;
    #limit_zone   myzone  $binary_remote_addr  10m;

    # Load config files from the /etc/nginx/conf.d directory
    include /etc/nginx/conf.d/*.conf;

}

 

# vi /etc/nginx/conf.d/server.conf

QUOTE:

server {
    listen   80;
    server_name  www.adj.idv.tw;
    access_log  /var/log/nginx/www.adj.idv.tw.access.log;
    error_log   /var/www/html/adj/error.log error;
    charset utf8;

## Default location
    location / {
        root   /var/www/html/adj;
        index  index.php;
    }

 

## Images and static content is treated different
    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
      access_log        on;
      expires           30d;
      root /var/www/html/adj;
    }

## Parse all .php file in the /var/www/html/adj directory
    location ~ .php$ {
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/html/adj$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_param  QUERY_STRING     $query_string;
        fastcgi_param  REQUEST_METHOD   $request_method;
        fastcgi_param  CONTENT_TYPE     $content_type;
        fastcgi_param  CONTENT_LENGTH   $content_length;
        fastcgi_intercept_errors        on;
        fastcgi_ignore_client_abort     off;
        fastcgi_connect_timeout 120;
        fastcgi_send_timeout 180;

        fastcgi_read_timeout 180;
        fastcgi_buffer_size 256k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;

}

 

## Disable viewing .htaccess & .htpassword
    location ~ /\.ht {
        deny  all;
    }
}

 

最後啟動相關服務

QUOTE:

service mysqld start

service php-fpm start

service nginx start

 

這樣就大功告成啦~~

 

相關文件參考:

http://www.howtoforge.com/installing-php-5.3-nginx-and-php-fpm-on-ubuntu-debian
http://wangchengtai.blog.hexun.com.tw/42855094_d.html

最新回復

jordan7372 at 2010-6-23 14:31:01