1. 程式人生 > >lnmp 一鍵安裝包

lnmp 一鍵安裝包

lnmp官網有詳細的安裝教程:https://lnmp.org/install.html

  1. 1, 安裝命令:

建立資料夾指向命令

wget http://soft.vpser.net/lnmp/lnmp1.5.tar.gz -cO lnmp1.5.tar.gz && tar zxf lnmp1.5.tar.gz && cd lnmp1.5 && ./install.sh lnmp

第一步選擇MySQL版本:

選擇:4

輸入資料庫密碼:*****

詢問是否需要啟用MySQL InnoDB,InnoDB引擎預設為開啟,一般建議開啟,直接回車或輸入 y ,如果確定確實不需要該引擎可以輸入 n,(MySQL 5.7+版本無法關閉InnoDB),輸入完成,回車進入下一步。

第二部選擇:PHP版本

注意:選擇PHP 7+版本時需要自行確認PHP版本是否與自己的程式相容。

輸入要選擇的PHP版本的序號,回車進入下一步,選擇是否安裝記憶體優化:

不用輸入直接回車就可以了

之後就等待安裝完畢就可以了

安裝完畢

  1. 2,配置專案

把專案搬到  /home/wwwroot/default/

給專案目錄全部的許可權   chmod -R 777  專案目錄名稱

##新增網站(虛擬主機)##

  • 尋找nginx 執行環境 ps -ef|grep nginx

nginx的配置文建目錄/usr/local/nginx/conf/nginx.conf  

nginx  啟動命令 /usr/local/nginx/sbin/nginx -s reload

  • 配置虛擬主機

nginx 配置檔案中的 server{

********

}

這個裡面就是專案訪問配置項

在檔案的最後找到

呼叫vhost 目錄下的 所有.conf結尾的檔案,所以我們多個專案配置就在vhost下面建立配置檔案就可以了

  • 新增配置項

檔案都.conf結尾就可以了

貼上一個thinkPHP專案的配置內容

需要複製的

server {
            listen       80;
            server_name  *****.cn;
            index index.shtml index.html index.htm index.php;
            root  /home/wwwroot/default/yd_api/www;

            fastcgi_connect_timeout 600;
            fastcgi_send_timeout 600;
            fastcgi_read_timeout 600;
            error_page 405 =200 $uri;
            error_page   500 502 503 504  /50x.html;

            client_max_body_size 50M;

            location = /50x.html {
                    root   html;
                }
            location ~ \.php$ {
                #fastcgi_pass    127.0.0.1:9000;

                fastcgi_pass    unix:/tmp/php-cgi.sock;
               fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
            }
            location / {
                    #ThinkPHP Rewrite
                if (!-e $request_filename){
                    rewrite ^/(.*)$ /index.php?s=$1 last;
                }
            }
            location ~* ^.+\.(jpg|jpeg|gif|png|css|bmp|js)
            {
                access_log   /home/wwwlogs/*****.cn.log;
                expires      30d;
            }
    }
 

一下是laravel專案的配置項

server
    {
        listen 80;
        #listen [::]:80;
        server_name   *****.cn ;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /home/wwwroot/default/v3.3.1/public;
        try_files $uri $uri/ @rewrite;

        location @rewrite {
            rewrite ^/(.*)$ /index.php?_url=/$1;
        }
        location ~ \.php$ {
                fastcgi_pass   unix:/tmp/php-cgi.sock;
               # fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                 fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

                include        fastcgi_params;
        }

        location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
                root /home/wwwroot/default/v3.3.1/public;
         }
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
            allow all;
        }
        location ~ /\.ht {
                deny  all;
         }
        location ~* \.env {
           allow all;
        }
        location ~* ^.+\.(jpg|jpeg|gif|png|bmp|css|js|swf|txt|ttf|woff)$ {
              access_log off;
                 break;
         }
        access_log  /home/wwwlogs/*****.cn.log;
        error_log   /home/wwwlogs/****.error.log;
    }

 

  • 配置好之後可以重啟 lnmp:lnmp restart

這個可以重啟lnmp上安裝的所有的環境

之後訪問專案目錄就可以了。

如果訪問失敗  報505  404 錯誤之類的,可以去專案配置檔案的列印log中就看具體的報錯原因,

  • log

 

 

檢視最新的5條報錯log

這邊報了一個open_basedir 目錄訪問許可權的問題,解決方案是:

lnmp 新增虛擬機器會給你建立一個.usr.ini 的目錄訪問許可權的檔案,把裡面的內容修改成  到專案上一級就可以了,不用指定某一個具體的專案,這樣就不會產生訪問不了的情況

這個是個舉例子,要學會打入log