部署laravel5.2到 Linux CentOS 7

部署laravel5.2到 Linux CentOS 7

前言

距离上一次的laravel学习又过去了N长时期,期间跑去学习了React和React Native…无限的辛酸史。
终于又开始回来学习laravel了,由于时间过长,所以这次计划从零开始,边温习边写个人网站。OK,Let`s go!

我的环境配置以及使用到的工具

环境:Linux centOS 7 + Nginx + MySql + PHP。需使用:git + composer。这里的环境我直接使用了lnmp.org上现成的包,具体的安装流程介绍的很清楚。

第一步、在本地创建laravel项目

在laravel项目的根目录下(以下使用author代替)初始化项目之前记得安装git

git init

第二步、创建远程库

由于github的关系,我将远程仓库设在了oschina上,使用和github基本一致。之后在本地

git remote add origin http://git.oschina.net/xxx/xxx.git
git pull origin master
git add <文件名,可以输入多个用空格隔开>
git commit -m "第一次提交"
git push origin master

以上就完成了项目文件提交至远程库。注:vender文件夹无需提交。

第三步、也是最坑的一步:配置服务器

首先安装git以及composer

yum install git
git config --global user.name "你的名字或昵称"
git config --global user.email "你的邮箱"
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
// 以上将下载并全局安装composer

接下来添加虚拟主机,具体的操作在这个教程里。根据文章里的操作,我们配置好了虚拟主机,接下来打开并修改xxxx.conf文件,这里是要做一些改动以适应laravel。虚拟主机配置文件在:/usr/local/nginx/conf/vhost/域名.conf,修改成以下的样子:

server {
    listen 80;
    root /home/wwwroot/author/public/; #这里是项目根目录,一定要写上public,因为入口index.php在这里
    index index.php;
    server_name your_IP; #your_IP,这里修改你的地址,以下内容无需改动
    location / {
            try_files $uri $uri/ index.php?$query_string;
    }
    location ~ \.php$ {
            try_files $uri /index.php =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass  unix:/tmp/php-cgi.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
    }
}

第四步、Clone并安装项目到服务器上

打开/home/wwwroot/文件夹,输入git clone <your project>,将刚刚提交的程序克隆到这里接着再cd <projiet name>,输入

composer install

这里可能有两个错误提示:

  1. 权限问题、为wwwroot文件添加写的权限chmod -r 775 wwwroot

  2. 安装完成后提示错误

[Symfony\Component\Process\Exception\RuntimeException]                                   
  The Process class relies on proc_open, which is not available on your PHP installation.

打开php.ini,找到disable_functions = ...删掉后面的proc_openproc_get_status

第五步、最后的配置

chown www:www -R /home/wwwroot/author 对网站目录进行权限设置,为storagebootstrap/cache文件夹添加775权限chmod -R 775 <dir>.

最后,浏览器上输入域名

《部署laravel5.2到 Linux CentOS 7》
大功告成!
后续的操作,本地编写网站程序,及时通过git更新至服务器。
如果你也对laravel感兴趣并且刚刚入门,说不定我们可以好好交流一下:lwx12525@outlook.com.

    原文作者:lwx12525
    原文地址: https://segmentfault.com/a/1190000006623138
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞