laravel5.5 安装

环境要求

  • PHP >= 7.0.0
  • PHP OpenSSL 扩展
  • PHP PDO 扩展
  • PHP Mbstring 扩展
  • PHP Tokenizer 扩展
  • PHP XML 扩展

通过 Laravel 安装器进行安装

首先,使用 Composer 下载 Laravel 安装程序:

composer global require "laravel/installer"

确保 $HOME/.composer/vendor/bin 目录(或你的操作系统的等效目录)已经放在你的环境变量 $PATH 中,以便系统可以找到 laravel 的可执行文件。

安装之后, laravel new 命令会在你指定的目录中创建一个新的 Laravel 项目。例如,laravel new blog 命令会创建一个名为 blog 的目录,其中包含所有已经安装好的 Laravel 的依赖项:

laravel new blog

通过 Composer 进行安装

还可以通过在终端中运行 create-project 命令来安装 Laravel:

composer create-project --prefer-dist laravel/laravel blog "5.5.*"

本地开发服务器

如果你在本地安装了 PHP,并且想使用 PHP 内置的开发服务器来为你的应用程序提供服务,那就使用 Artisan 命令serve。这个命令会在 http://localhost:8000 上启动开发服务器:

php artisan serve

Web 服务器配置

Apache

Laravel 使用 public/.htaccess 文件来为前端控制器提供隐藏了 index.php 的优雅链接。如果你的 Laravel 使用了 Apache 作为服务容器,请务必启用 mod_rewrite模块,让服务器能够支持 .htaccess 文件的解析。

如果 Laravel 附带的 .htaccess 文件不起作用,就尝试用下面的方法代替:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

Nginx

如果你使用的是 Nginx,在你的站点配置中加入以下内容,它将会将所有请求都引导到 index.php 前端控制器:

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

 可以直接使用以下配置:

server {
    listen 80;
    server_name example.com;
    root /example.com/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

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

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php(.*)$  {
         fastcgi_pass   127.0.0.1:9000;
         fastcgi_index  index.php;
         fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
         fastcgi_param  PATH_INFO  $fastcgi_path_info;
         fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
         include        fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

 

posted @ 2019-01-10 13:32  佛系-Coder  阅读(1095)  评论(0编辑  收藏  举报