lnmp+laravel 建置紀錄 ( GCP + centOS7 + lnmp1.6一件安裝包 + laravel 6)
第一步 : 安裝 LNMP
按照連結安裝LNMP一鍵包 : https://lnmp.org/install.html
虛擬機位置 : /usr/local/nginx/conf/vhost/
網站絕對路徑 : /home/wwwroot/我的網站名稱
sftp連線教學 : https://digital-transformation.media/google-cloud-platform/gce-linux-sftp-setting/
遠端mysql (通常不會開3306)
- gcp防火牆要開啟 3306port
- phpmyadmin要新增一個為%的使用者
- lnmp要關掉3306防火牆
- 使用工具遠程登入 (帳號密碼為第二點的 使用者)
遠端mysql連線 教學連結 : https://www.itread01.com/content/1547255118.html
第二步 : 建置laravel環境
composer全局安裝:
- 先上composer下載最新版 : https://getcomposer.org/download/
- CentOS 7全局使用composer的方式 : sudo mv composer.phar /usr/bin/composer
PHP配置文件:
- 進入此檔案位置 : /usr/local/php/etc/php.ini
- 搜尋 disable_functions 後刪除proc_get_status和proc_open
因為 LNMP 默認是不允許跨目錄訪問(下方為解決方式):
- 進入 /usr/local/nginx/conf/fastcgi.conf
- 註解調最後一行 ( 加上 # ), 如下
#fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";
php-fpm配置文件位置:
- /usr/local/php/etc/php-fpm.conf
將root修改成laravel的路徑:
- 進入目錄 : cd /usr/local/nginx/conf/vhost
- vim 自己的網域.conf
- 修改root路徑增加public, 如 root /home/wwwroot/12.223.214.222/test/public;
記得開啟權限:
- cd into your Laravel project.
- sudo chmod -R 777 storage
- sudo chmod -R 777 bootstrap/cache
- sudo chmod -R 777 public
每個頁面都出現404錯誤 :
- 路徑: /usr/local/nginx/conf/vhost/
- 然後找到需要修改的檔案增加下列程式碼
location / { try_files $uri $uri/ /index.php?$args; }
刪除user.ini
- chattr -i /home/wwwroot/你的網站目錄/.user.ini
- 然后再用rm -rf命令或者FTP去删除就可以了。
第三部 : http強制跳轉https
1.路徑 : /usr/local/nginx/conf/vhost->conf檔案設定
server
{
listen 80;
#listen [::]:80;
server_name www.test.com test.com; #這兩個網址都必須會跳轉
return 301 https://$server_name$request_uri;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/www.test.com;
…...
……
…...
}
server
{
listen 443 ssl http2;
#listen [::]:443 ssl http2;
server_name www.test.com;
if ($host = 'test.com') {
return 301 https://www.test.com;
}
if ($host = '13.84.99.203') { #如果使用者打IP強制跳轉
return 301 https://www.test.com;
}
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/www.test.com/test/public;
………..
………..
………..
}
2.路徑 : /usr/local/nginx/conf/niginx.conf
server
{
listen 80 default_server reuseport;
#listen [::]:80 default_server ipv6only=on;
server_name _;
return 301 https://www.test.com;
index index.html index.htm index.php;
root /home/wwwroot/default;
........
…....
.......
}
留言
張貼留言