[Linux]安裝LEMP環境

linux指令, 架設等
回覆文章
頭像
tim
文章: 1379
註冊時間: 2008年 11月 26日, 00:49

[Linux]安裝LEMP環境

文章 tim »

這篇是以 ubuntu 為例, 安裝 nginx, mysql, php 也就是 LEMP 環境的介紹, 其中原來就悉的 LAMP 將 Apache 換成 nginx
http://blog.gtwang.org/linux/ubuntu-lin ... mp-server/

另外超便宜雲端主機商 digital ocean 也有介紹安裝方式
https://www.digitalocean.com/community/ ... untu-12-04
https://www.digitalocean.com/community/ ... n-centos-6

若是在 RHEL/CentOS7 安裝 LEMP 可以參考:
http://www.phpini.com/linux/rhel-centos ... l-php-lemp

由於 RHEL/CentOS 沒有在 repo 裡有 nginx, 必須手動自行加入:

代碼: 選擇全部

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
其中後面的 package 連結, 可以參考 nginx 官網:
http://nginx.org/en/linux_packages.html#stable

nginx + php-fpm 教學
http://blog.toright.com/posts/3890

若有需要便宜主機 digital ocean, 可以利用推薦連結來獲得免費的 $10 (10元美金)
https://www.digitalocean.com/?refcode=c5fa03fa1aa6
最後由 tim 於 2015年 10月 29日, 16:17 編輯,總共編輯了 1 次。
多多留言, 整理文章, 把經驗累積下來.....
頭像
tim
文章: 1379
註冊時間: 2008年 11月 26日, 00:49

Re: [Linux]安裝LEMP環境

文章 tim »

php fast cgi 問題, 因為預設的 php root 指向會是特定目錄, 若是用 server 區塊內放的 php 可以將其 root html 移除, 解決設定 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name 使用.

參考:
http://my.oschina.net/zhichi2011/blog/118409

官方資料:
https://www.nginx.com/resources/wiki/st ... s/phpfcgi/
多多留言, 整理文章, 把經驗累積下來.....
頭像
tim
文章: 1379
註冊時間: 2008年 11月 26日, 00:49

Re: [Linux]安裝LEMP環境

文章 tim »

nginx 在多重虛擬主機設定的方式如下:

listen 80 後若多加 default_server 為若沒有 match server_name 的預設虛擬主機, 另外都可以自定 error_log 與 access_log 的 log file.


abc.com

代碼: 選擇全部

server {
    listen       80 default_server;
    server_name  abc.com;
 
    error_log  /var/log/nginx/abc.com-error.log warn;
    access_log  /var/log/nginx/abc.com-access.log  combined;

    root   /var/www/abc.com;
    index  index.html index.htm;

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        #root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny  all;
    }
}
def.com

代碼: 選擇全部

server {
    listen       80;
    server_name  www.def.com def.com;
 
    error_log  /var/log/nginx/def.com-error.log warn;
    access_log  /var/log/nginx/def.com-access.log  combined;

    root   /var/www/def.com;
    index  index.html index.htm;

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        #root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny  all;
    }
}
多多留言, 整理文章, 把經驗累積下來.....
回覆文章