Laravel 5.3入门

Laravel 5.3入门_第1张图片
laravel

Laravel 5.3安装

开发环境满足以下要求:

  • PHP版本 >= 5.6.4
  • PHP扩展:OpenSSL
  • PHP扩展:PDO
  • PHP扩展:Mbstring
  • PHP扩展:Tokenizer

Laravel 使用 Composer 管理依赖,因此,使用 Laravel 之前,确保机器上已经安装了Composer

通过 Laravel 安装器

首先,通过 Composer 安装 Laravel 安装器:

composer global require "laravel/installer"

PS:我的Composer是window系统exe安装的,执行上面这个命令后,会在我的C:\Users\10113\AppData\Roaming\Composer下下载一堆不明代码。

确保 ~/.composer/vendor/bin 在系统路径中,否则不能在任意路径调用 laravel 命令。

安装完成后,通过简单的 laravel new 命令即可在当前目录下创建一个新的 Laravel 应用,例如,laravel new blog 将会创建一个名为 blog 的新应用,且包含所有 Laravel 依赖。该安装方法比通过 Composer 安装要快很多:

laravel new blog

http://localhost/laravel5.3/blog/public/

通过 Composer Create-Project

你还可以在终端中通过 Composer 的 create-project 命令来安装 Laravel 应用:

composer create-project --prefer-dist laravel/laravel blog

注:如果要下载其他版本,比如5.2版本,可以使用这个命令:composer create-project --prefer-dist laravel/laravel blog 5.2.*

http://laravelacademy.org/post/5744.html

部署 laravel 5.3 (php7.0 + nginx)

phpStudy(我用phpStudy 2016.11.03版本)

server {
        listen       80;
        server_name  l.com ;
        root   "D:/html/laravel/public";
        location / {
            index  index.html index.htm index.php;
            #autoindex  on;
            try_files $uri $uri/ /index.php?$query_string;
        }
      
        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            # fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            try_files $uri /index.php =404;
            
            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;
        }
}

wnmp.2.2.5

编辑php.ini
vi d:/local/wnmp.2.2.5/php/php.ini
;cgi.fix_pathinfo=1修改为cgi.fix_pathinfo=0
编辑nginx配置
vi d:/local/wnmp.2.2.5/conf/nginx.conf

server {
    listen 80;
    server_name l.com;

    access_log logs/l.com_access.log;
    error_log logs/l.com_error.log;

    root d:/local/wnmp.2.2.5/html/laravel5.3/blog/public;
    index  index.php;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
  
    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_pass   php_processes;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

初体验

.env

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=12345

# 验证页面
php artisan make:auth

# 数据迁移
php artisan migrate

http://l.com/login

ORM->Eloquent 处理Model类

php artisan make:model Article

Migration和Seeder

php artisan make:migration create_article_table
php artisan migrate
php artisan make:seeder ArticleSeeder
composer dump-autoload
php artisan db:seed

你可能感兴趣的:(Laravel 5.3入门)