網(wǎng)站項(xiàng)目:Ubuntu 16.04 + LNMP 1.4 + Laravel 5.3
默認(rèn)服務(wù)器系統(tǒng)已經(jīng)安裝好了,在接下來先安裝LNMP一鍵安裝包1.4版本。
- 安裝LNMP穩(wěn)定版
在本地安裝的話,直接運(yùn)行一下代碼就行:
wget -c http://soft.vpser.net/lnmp/lnmp1.4.tar.gz && tar zxf lnmp1.4.tar.gz && cd lnmp1.4 && ./install.sh lnmp
選擇好mysql版本和php版本安裝好,創(chuàng)建好虛擬主機(jī)。
- 添加虛擬主機(jī)
lnmp vhost add
以上過程按提示就很容易完成。
- 導(dǎo)入數(shù)據(jù)庫
登入數(shù)據(jù)庫:
mysql -u root -p //執(zhí)行后,輸入密碼訪問
創(chuàng)建一個(gè)新的數(shù)據(jù)庫:
create database demo_sfabric;
進(jìn)入剛剛創(chuàng)建的數(shù)據(jù)庫:
use demo_sfabric;
取消外鍵約束:
SET FOREIGN_KEY_CHECKS=0;
導(dǎo)入sql數(shù)據(jù)庫文件:
source /home/zhangshu/0830.sql;
接下來主要記錄下在部署laravel的過程中遇到的問題:
1、首先進(jìn)入nginx下的vhost目錄,修改配置文件
找到下面這行
root /home/wwwroot/sfabric.nginx;
修改為:
root /home/wwwroot/sfabric.nginx/public; //整個(gè)項(xiàng)目代碼放在sfabric.nginx目錄下
2、配置好虛擬主機(jī)文件后,輸入域名訪問,出現(xiàn)空白頁面和500錯(cuò)誤

這時(shí),我們進(jìn)入PHP目錄/usr/local/php/etc,找到php.ini文件,先把錯(cuò)誤提示打開
display_errors = On;
保存退出后,重啟下lnmp
lnmp restart
3、再次訪問的時(shí)候,沒有500錯(cuò)誤了,顯示了另外一個(gè)錯(cuò)誤提示:
Warning: require(): open_basedir restriction in effect. File(/home/wwwroot/sfabric.nginx/bootstrap/autoload.php) is not within the allowed path(s): (/home/wwwroot/sfabric.nginx/public/:/tmp/:/proc/) in /home/wwwroot/sfabric.nginx/public/index.php on line 21
Warning: require(/home/wwwroot/sfabric.nginx/bootstrap/autoload.php): failed to open stream: Operation not permitted in /home/wwwroot/sfabric.nginx/public/index.php on line 21
Fatal error: require(): Failed opening required '/home/wwwroot/sfabric.nginx/public/../bootstrap/autoload.php' (include_path='.:/usr/local/php/lib/php') in /home/wwwroot/sfabric.nginx/public/index.php on line 21
這個(gè)錯(cuò)誤提示是php執(zhí)行權(quán)限的問題:
我們先找到在哪個(gè)文件設(shè)置了open_basedir
進(jìn)入到/usr/local/nginx/conf目錄下,打開fastcgi.conf文件,在這個(gè)文件里面最后一行設(shè)置了open_basedir:

先把這一行注釋掉,在前面加一個(gè)#號(hào):
#fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";
保存退出,重啟lamp.
4、再次刷新頁面訪問,又出現(xiàn)了空白頁和500錯(cuò)誤,簡直崩潰,沒有任何提示。

5、在項(xiàng)目根目錄,找到storage目錄,把這個(gè)目錄和里面的文件全部改為777。
chmod -R 777 storage
再次訪問,又是一個(gè)新的錯(cuò)誤:
ErrorException
in Filesystem.php line 111:
file_put_contents(/home/wwwroot/sfabric.nginx/bootstrap/cache/services.php): failed to open stream: Permission denied
然后繼續(xù)清除緩存配置,重新生產(chǎn)key:
php artisan config:clear
php artisan key:generate
這個(gè)時(shí)候,可以正常訪問頁面了。
But……one more thing……
在前端登陸的時(shí)候,出現(xiàn)了405 Not Allowed:

出現(xiàn)這個(gè)問題后,我們需要修改一下配置文件/usr/local/nginx/conf/vhost,打開conf文件,在文件中加入如下代碼:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
保存退出后,重啟下lnmp,這時(shí)候405錯(cuò)誤消失了。
但是又有一個(gè)新問題出現(xiàn):
前端登陸的時(shí)候,出現(xiàn)登陸失?。?/p>

這個(gè)錯(cuò)誤是因?yàn)閟torage目錄中的oauth-private.key 和 oauth-public.key的權(quán)限問題,
我們需要把這兩個(gè)文件的所有者改為www,然后權(quán)限改為777
chown www:www oauth-*.key
chmod 777 oauth-*.key
執(zhí)行完這些后,就大功告成了!可以正常登錄訪問了。