【Linux系列】Centos 7部署Laravel項目(七)

目的


本文主要介紹如下五點:php

一. Composer安裝html

二. SSH設置nginx

三. Git安裝laravel

四. Laravel部署git

五. 上傳GitHubgithub

演示


一. Composer安裝
# cd /usr/local/bin
php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');" # 刪除安裝文件
mv composer.phar composer

配置鏡像bash

composer config -g repo.packagist composer https://packagist.phpcomposer.com

添加composer環境變量php7

composer global config bin-dir --absolute # 查看composer安裝目錄

1

# vi ~/.bashrc
PATH=$PATH:/root/.config/composer/vendor/bin

保存後,執行source ~/.bashrc,使其生效app

二. SSH設置
ssh-keygen -t rsa -b 4096 -C "sexyphoenix@163.com"
cat ~/.ssh/id_rsa.pub # 複製公鑰

打開github SSH,配置SSH keycomposer

2

三. Git安裝
yum install -y git

配置git基本信息

git config --global user.name "SexyPhoenix" # 帳號
git config --global user.email "sexyphoenix@163.com"# 郵箱
git config --global push.default simple
四. Laravel部署

安裝下zip、unzip

yum install -y zip unzip

下載Laravel5.8

composer create-project --prefer-dist laravel/laravel App

5.8版本會自動建立.env,應用key。用低版本能夠根據官網操做

修改.env

# vi .env
APP_NAME=App
APP_URL=http://app.plat.goods

配置nginx config

# cd /etc/nginx/config.d
# touch app.plat.goods.conf

server {
   listen       80;
   server_name  app.plat.goods;

   index index.html index.htm index.php;

   location / {

        rewrite ^/(.*)$ /index.php/$1 last;
        try_files $uri $uri/ /index.php?$query_string;
   }

   location ~ (.+\.php)(.*)$ {
        root "/var/www/App/public"; # app應用
        fastcgi_split_path_info ^(.+\.php)(.+)$;
        fastcgi_pass unix:/var/run/php-fpm/php7-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;

        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
   }
}

物理主機訪問虛擬機站點,須要配置物理機的hosts

C:\Windows\System32\drivers\etc\hosts

192.168.10.18 app.plat.goods

訪問 http://app.plat.goods/

3

storage 須要寫入權限

chmod -R 0777 storage # 測試環境就0777了

4

部署成功

到這裏能夠將項目更新到github

五. 上傳GitHub

到github上新建倉庫

5

# cd /var/www/App
git add . 
git commit -m 'app init' # 提交到本地倉庫
git remote add origin git@github.com:SexyPhoenix/App.git # 遠程倉庫
git push -u origin master # 推送
相關文章
相關標籤/搜索