ubuntu nginx环境下的laravel配置与安装

ubuntu nginx环境下的laravel配置与安装


安装composer

#安装php7.1
$ sudo apt-get install php7.1
#安装php必须扩展
$ sudo apt-get install php7.1-zip php7.1-dom php7.1-mbstring php7.1-fpm

#下载composer
$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer
$ sudo chmod +x /usr/local/bin/composer

#给.composer目录授权 此处以etone用户为例
$ chown -R etone:etone ~/.composer

#使用国内镜像	
$ composer config -g repo.packagist composer https://packagist.phpcomposer.com

安装Laravel与环境变量配置

$ composer global require "laravel/installer"
# $ composer global require "laravel/installer=~1.1"
$ vi /etc/profile
# 添加laravel的环境变量
export PATH=$PATH:$HOME/bin:~/.config/composer/vendor/bin
# 或者直接控制台执行命令
$ echo 'export PATH=$PATH:$HOME/bin:~/.config/composer/vendor/bin' >> /etc/profile
#使配置生效
$ source /etc/profile

在nginx中laravel的配置

server
{
    listen 80;
    server_name _;
    index index.html index.htm index.php;
    root  /var/www/blog/public;

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

    location ~ /\.ht {
        deny all;
    }

    location ~ .php$ {
          fastcgi_pass unix:/run/php/php7.1-fpm.sock;
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_connect_timeout 300;
          fastcgi_read_timeout 300;
          fastcgi_send_timeout 300;

          include fastcgi_params;
    }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
    }

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

    access_log off;
}

nginx和php-fpm配置问题

nginx常用命令
启动:sudo nginx
重启:sudo service nginx reload
关闭:sudo nginx -s stop
查看版本:sudo nginx -v
检查配置文件:sudo nginx -t

创建laravel项目

# 添加运行权限
$ cd ~/.config/composer/vendor/laravel/installer/
$ chmod +x laravel
 
# 创建项目
$ cd /var/www
# 分配用户组以便laravel能读写
$ chown -R www:www /var/www

$ laravel new blog

#访问出错 storage没有访问权限,修改storage以及vendor的所有者
$ chown -R www:www storage
$ chown -R www:www vendor

编写不易,如若转载请联系作者。
https://blog.csdn.net/qq_34461600/article/details/91827839

你可能感兴趣的:(Laravel)