Laravel 项目上新服务器基础配置流程

阅读 (1910)
一直没空写,只是简单记录一下,已经配过N次,虽然早已了然于心,但还是记录一下,就防年纪大了健忘

以 lnmp1.4 集成包安装为例

一、Nginx配置:

1. /usr/local/nginx/conf

vi nginx.conf

删除 server 整段代码

后面在vhost中创建对应项目server

2.创建 共用 location.conf 配置文件

vi location.conf
    #error_page   404   /404.html;

    # Deny access to PHP files in specific directory
    #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

    include enable-php.conf;

    location /nginx_status
    {
        stub_status on;
        access_log   off;
    }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires 12h;
        access_log off;
    }

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

    location ~ .*\.(json)?$
    {
        access_log off;
    }


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

    location ~ /\.
    {
        deny all;
    }

3. vhost

cd /usr/local/nginx/conf/vhost
vi project.conf
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
                '$status $body_bytes_sent "$http_referer" '
                '"$http_user_agent" $http_x_forwarded_for '
         '"$upstream_addr" "$upstream_status" "$upstream_response_time" "$request_time"';

server
{
   listen 80;
   server_name www.laravel.org;


   root  /home/wwwroot/laravel/union/public;

   index index.php index.html index.htm;

   location / {
        try_files $uri $uri/ /index.php?$query_string;
   }


   include location.conf;


   location = /heart.html {
        access_log off;
   }

   if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})") {
    set $date $1$2$3;
   }

   access_log  /home/wwwlogs/laravel/$date-access.log;


}

4. 编辑 fastcgi.conf,这个一定要加,不然怎么访问都是 500 错误

vi /usr/local/nginx/conf/fastcgi.conf
#PHP_ADMIN_VALUE 引号内加入 :/home/wwwroot/

fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/:/home/wwwroot/";

5. 日志创建目录,这里的目录是 vhost 中写的对应的log目录

cd /home/wwwlogs

mkdir laravel

chown -R www:www laravel

6.重启nginx 服务

service nginx restart

 

二、PHP相关配置

1. 添加fileinfo拓展

#我的lnmp1.4安装包在root目录,所以
cd ~ 
cd /lnmp1.4/src
tar -xjvf php-7.0.21.tar.bz2
cd php-7.0.21/ext/fileinfo   // 绝对路径是 /lnmp1.4/src/php-7.0.21/ext/fileinfo

/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install

修改php.ini文件

vi /usr/local/php/etc/php.ini

添加fileinfo扩展 extension = fileinfo.so

顺便再修改 disable_functions

#去除以下四个函数,laravel各命令可能会用到以下命令
proc_open,proc_get_status,readlink,symlink

#所以最后的 disable_functions 可能是下面这样的,但不管是不是以下这些,反正上面四个要去除
disable_functions = passthru,exec,system,chroot,chgrp,scandir,chown,shell_exec,popen,ini_alter,ini_restore,dl,openlog,syslog,popepassthru,stream_socket_server

重启服务

service php-fpm restart

 

三、 最后就是laravel 项目文件是部署了

不管是用git、svn 还是怎么打包上传等操作,项目放到 /home/wwwroot/ 目录下

例如项目目录为 laravel/union

则进入laravel 目录 再执行以下操作

cd /home/wwwroot/laravel
chown -R www:www union
cd union

chmod -R 777 storage
chmod -R 777 bootstrap

php artisan storage:link

composer dumpautoload

 

最后的最后,配置好.env 文件,修改其中的数据库等配置即可

基本流程就是这样

 

 

更新于:2018-07-02 11:07:37
返回顶部