安装Laravel5 前配置

安装Laravel5 前配置

在 Windows 上进行 Laravel Homestead 安装、配置及测试

| 基于 VirtualBox 4 + Vagrant 1.7 使用 Laravel Homestead。

1、准备
先下载安装VirtualBox和Vagrant。
安装 VirtualBox
安装Vagrant https://www.jianshu.com/p/c88c8888b51a

安装完成后需要将vagrant/vagrant.exe所在目录放到系统路径中(这个需要根据Vagrant安装目录来,比如我的是D:\HashiCorp\Vagrant\bin)。(如果是win系统图形化安装 都默认的话 会自动加入到系统变量)

2、使用Vagrant安装Homestead盒子
在控制台中执行如下命令(先进入到项目所在根目录 如 D:\www):
vagrant box add laravel/homestead
上面的命令如果报错 则修改一下用远程地址
vagrant box add https://app.vagrantup.com/laravel/boxes/homestead

然后会出来一个选项:

看你安装的是什么虚拟机咯,上面安装的是 Virtualbox 所在 输入 3 回车,等待下载吧

配置composer 中国镜像
修改 composer 的全局配置文件(推荐方式)
composer config -g repo.packagist composer https://packagist.phpcomposer.com

全局安装,先安装 composer
composer global require “laravel/installer”

当前目录安装
composer require “laravel/installer”

composer create-project --prefer-dist laravel/laravel blog
// blog 目录为项目目录,如果是当前目录 可以不写

访问:http://192.168.1.75/laravel/blog/public/

其中 blog可直接放到根目录下。
安装好的 目录结构如下:

本地开发的话 我们可以配置一个虚拟目录:
– 修改host
添加一条 127.0.0.1 www.lavarel.local
– apache服务 修改vhosts.conf
添加一条


DocumentRoot “D:\wwwroot\xiushe\public”
ServerName www.lavarel.local
ServerAlias

Options FollowSymLinks ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted

安装好Lavarel后,默认访问的是public/index.php

那如何隐藏index.php呢 这就要配置了

------------------------Web 服务器配置
优雅链接
Apache
Laravel 框架通过 public/.htaccess 文件来让 URL 不需要 index.php 即可访问。在 Apache 启用 Laravel 之前,请确认是否有开启 mod_rewrite 模块,以便 .htaccess 文件发挥作用。
如果 Laravel 附带的 .htaccess 文件在 Apache 中无法使用的话,请尝试下方的做法:
Options +FollowSymLinks
RewriteEngine On

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

Nginx
如果你使用 Nginx ,在你的网站配置中加入下述代码将会转发所有的请求到 index.php 前端控制器。
location / {
try_files $uri u r i / / i n d e x . p h p ? uri/ /index.php? uri//index.php?query_string;
}

当然如果你使用了 Homestead 或者 Valet 的话, 它会自动的帮你设置好优雅链接。

--------------------------添加本地虚拟目录
然后服务器配置将public目录设置为默认访问根目录,以apache配置为例 , 修改文件 Apache/conf/extral/httpd-vhosts.conf


ServerAdmin [email protected]
DocumentRoot “D:/www/laravel/public”
ServerName www.laravel.loc
ErrorLog “logs/www.laravel.loc-error.log”
CustomLog “logs/www.laravel.loc-access.log” common

hosts 添加一条
127.0.0.1 www.laravel.loc

laravel-nginx 配置隐藏index.php
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
root “D:/www/laravel/public”;
location / {
index index.html index.htm index.php default.php;
autoindex on;
if (!-e KaTeX parse error: Expected '}', got 'EOF' at end of input: … rewrite ^/(.*) /index.php/$1;
}
}
}

你可能感兴趣的:(lavarel)