2014年3月11日 星期二

CentOS 6.4 安裝 Nginx+PHP5.5+PHP-FPM

翻譯、引用來源:http://www.if-not-true-then-false.com/2011/install-nginx-php-fpm-on-fedora-centos-red-hat-rhel/

一、開啟終端機,切換至su權限

二、安裝額外的來源套件
Remi repository
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm 
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
建立Nginx 來源文件
vi  /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
三、 安裝 Nginx, PHP 5.5.9 和 PHP-FPM
yum --enablerepo=remi,remi-php55 install nginx php-fpm php-common -y
四、 安裝 PHP 5.5.9 模組
yum --enablerepo=remi,remi-php55 install php-pecl-apc php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml -y
五、 停止 httpd (Apache) , 並啟動 Nginx HTTP 和 PHP-FPM (FastCGI Process Manager)服務
service httpd stop
service nginx start
service php-fpm start
六、開機時自動啟動啟動 Nginx 和 PHP-FPM ,並關閉httpd(Apache)自動執行
chkconfig httpd off
chkconfig --add nginx
chkconfig --levels 235 nginx on
chkconfig --add php-fpm
chkconfig --levels 235 php-fpm on
七、 設定 Nginx 和 PHP-FPM (建立你的網站目錄)
在此範例使用 testsite.local 做為網站,但你也可以使用自己的網站名稱

建立網站目錄和記錄檔目錄
mkdir -p /srv/www/testsite.local/public_html
mkdir /srv/www/testsite.local/logs
chown -R apache:apache /srv/www/testsite.local
**這裡使用的是apache這個帳號做為目錄權限,如果要使用別的帳號,要記的修改 /etc/php-fpm.d/www.conf  中的user/group 帳號。
於 /etc/nginx/ 建立虛擬主機目錄
mkdir /etc/nginx/sites-available
mkdir /etc/nginx/sites-enabled
編輯 /etc/nginx/nginx.conf ,於 http {  } 這個區塊的 "include /etc/nginx/conf.d/*.conf" 下方新增一行 include /etc/nginx/sites-enabled/*;
vi /etc/nginx/nginx.conf
include /etc/nginx/sites-enabled/*;
於 /etc/nginx/sites-available/ ,建立 testsite.local 虛擬主機設定檔,內容如下
這是很基本的虛擬主機設定檔
 server {
    server_name testsite.local;
    access_log /srv/www/testsite.local/logs/access.log;
    error_log /srv/www/testsite.local/logs/error.log;
    root /srv/www/testsite.local/public_html;

    location / {
        index index.html index.htm index.php;
    }

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /srv/www/testsite.local/public_html$fastcgi_script_name;
    }
建立虛擬主機連結,將 /etc/nginx/sites-available 下的設定檔連結至 /etc/nginx/sites-enabled,並重新啟動 nginx 使其生效
ln -s /etc/nginx/sites-available/testsite.local /etc/nginx/sites-enabled
service nginx restart
於 /etc/hosts 檔案中增加網站域名,讓它看起來像這個樣子
127.0.0.1               localhost.localdomain localhost testsite.local
八、測試網站
於 /srv/www/testsite.local/public_html/ 建立 index.php 文字,內容如下
<?php
    phpinfo();
?>
開啟瀏覽器,輸入 http://testsite.local/ 執行後應該可以看到php的版本資訊。


九、開啟 nginx 的遠端連線服務(放行 Iptables 防火牆的 80 Port)
編輯iptables的設定檔
vi /etc/sysconfig/iptables
新增一條規則於INPUT 區塊,內容如下
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
重新啟動Iptables 防火牆
service iptables restart

在ESXI 5.0上安裝CentOS6.5 和 VMtools

以下是個人的操作筆記,做個備記

一、開啟終端機,並切換至su權限

二、更新perl、gcc、必要套件

yum -y install perl gcc make kernel-headers kernel-devel
三、掛載Vmtools光碟
 四、解壓縮VMwareTools-8.6.0-425873.tar.gz
 cd /tmp
tar xzvf "/media/VMware Tools/VMwareTools-8.6.0-425873.tar.gz"
 五、執行安裝程式,一直按確定即可。
cd vmware-tools-distrib
./vmware-install.pl