【lnmp一鍵安裝包】LNMP一鍵安裝和配置(解決LNMP502和500問題)


寫在前面:所有操作目錄均是在/usr/local/下執行的,拿到值守命令,直接在/usr/local/下執行,無需創建其他文件夾,系統自動創建lnmp1.6

1、去LNMP官網:https://lnmp.org/install.html  直接在服務器wget安裝LNMP1.5版本

2、我選擇的是無人值守版 LNMP:  地址:https://lnmp.org/auto.html

安裝步驟:
1、使用putty或類似的SSH工具登陸VPS或服務器;

登陸后運行:screen -S lnmp
如果提示screen: command not found 命令不存在可以執行:yum install screen 或 apt-get install screen安裝,詳細內容參考screen教程。

2、下載並安裝LNMP一鍵安裝包:

您可以選擇使用下載版(推薦美國及海外VPS或空間較小用戶使用)或者完整版(推薦國內VPS使用,國內用戶可用在下載中找國內下載地址替換),兩者沒什么區別,只是完整版把一些需要的源碼文件預先放到安裝包里。

安裝LNMP穩定版
如需無人值守安裝,請使用 無人值守命令生成工具,或查看無人值守說明教程

生成命令:

 1.5=>php5.6

wget http://soft.vpser.net/lnmp/lnmp1.5.tar.gz -cO lnmp1.5.tar.gz && tar zxf lnmp1.5.tar.gz && cd lnmp1.5 && LNMP_Auto="y" DBSelect="3" DB_Root_Password="lnmp.org" InstallInnodb="y" PHPSelect="5" SelectMalloc="1" ./install.sh lnmp

1.6=>php7

wget http://soft.vpser.net/lnmp/lnmp1.6.tar.gz -cO lnmp1.6.tar.gz && tar zxf lnmp1.6.tar.gz && cd lnmp1.6 && LNMP_Auto="y" DBSelect="3" DB_Root_Password="lnmp.org" InstallInnodb="y" PHPSelect="6" SelectMalloc="1" ./install.sh lnmp

 

  2.1 如果報錯:wget command not found,請直接執行 yum -y install wget 。

 

3、安裝完畢,查看是否成功:

4、錯誤排查:解決LNMP502和500問題,請查看下面地址  https://lnmp.org/faq.html

首先查看LNMP常見錯誤和解決方案,至少能節省你三分之二的拍錯時間(地址:https://lnmp.org/faq.html)

5、開始配置:

我沒有使用它的腳本進行配置的。我是直接配置 vhost/項目.conf文件 (必須先查看php-fpm.conf的listen)

6、重點提醒:如果你的PHP項目是laravel、tp5等 項目根目錄指向/public/ 下的,一定要執行下面步驟,否則網站一直報錯 500.(.user.ini直接刪除)

##防跨目錄設置##
LNMP 1.1及之前的版本使用php.ini里面,open_basedir設置

LNMP 1.2及更高版本防跨目錄功能使用.user.ini,該文件在網站根目錄下,可以修改.user.ini 里面的open_basedir的值來設置限制訪問的目錄或刪除來移除防跨目錄的設置。

.user.ini文件無法直接修改,如要修或刪除需要先執行:chattr -i /網站目錄/.user.ini
可以使用winscp文件管理、vim編輯器或nano編輯器進行修改。
刪除的話rm -f /網站目錄/.user.ini 就可以。
修改完成后再執行:chattr +i /網站目錄/.user.ini
.user.ini不需要重啟一般5分鍾左右生效,也可以重啟一下php-fpm立即生效。
如果要更改網站目錄必須要按上述方法修改防跨目錄的設置,否則肯定報錯!!

LNMP 1.4上如果不想用防跨目錄或者修改.user.ini的防跨目錄的目錄還需要將 /usr/local/nginx/conf/fastcgi.conf 里面的fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/"; 在該行行前添加 # 或刪除改行,需要重啟nginx。

LNMP 1.4上也可以直接使用lnmp1.4/tools/ 目錄下的 ./remove_open_basedir_restriction.sh 進行移除。
在Thinkphp、codeigniter、Laravel等框架下,網站目錄一般是在public下,但是public下的程序要跨目錄調用public上級目錄下的文件,因為LNMP默認是不允許跨目錄訪問的,所以都是必須要將防跨目錄訪問的設置去掉,有時候這些框架類的程序提示500錯誤也可能是這個問題引起的。

 

7、其他的偽靜態和pathinfo ,按照nginx的慣例配置進行設置即可。

通用版:tp5、laravel5都可以使用下面的nginx配置(使用ip:port訪問或者域名:port)

server {

        listen       8054;
        server_name  localhost;
        root /home/wwwroot/default/erpv31/public/;
        #index index.php index.html index.htm;

        location / {
            index  index.html index.htm index.php;
            autoindex  off;    
            if (!-e $request_filename) {     
                rewrite  ^(.*)$  /index.php?s=$1  last;          
                break;
            }
        }

        location ~ \.php(.*)$ {
            fastcgi_pass     unix:/tmp/php-cgi.sock;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
                expires      30d;
        }

        location ~ .*\.(js|css)?$ {
                expires      12h;
        }
    access_log /home/wwwlogs/erpv31-access.log;
    error_log  /home/wwwlogs/erpv31-error.log;
}

 

 

thinkcmf5的nginx慣例配置:

server
    {
        listen 80;
        server_name api.***.xin;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /home/wwwroot/api.***.xin/public;
    
    location / {
          index  index.php index.html index.htm;
          #如果請求既不是一個文件,也不是一個目錄,則執行一下重寫規則
          if (!-e $request_filename)
          {
             #地址作為將參數rewrite到index.php上。
             rewrite ^/(.*)$ /index.php?s=$1;
             #若是子目錄則使用下面這句,將subdir改成目錄名稱即可。
             #rewrite ^/subdir/(.*)$ /subdir/index.php?s=$1;
          }
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   unix:/tmp/php-cgi.sock;
            fastcgi_index  index.php;
            #fastcgi_split_path_info ^(.+\.php)(.*)$;
            #fastcgi_param   PATH_INFO $fastcgi_path_info;
            fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            #deny all;
        }

        access_log  /home/wwwlogs/access.log2.log;
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM