Laravel Series Tutorial One: Installation and Environment configuration

Source: Internet
Author: User
Tags php server how to install laravel laravel tutorial

Free Video Tutorial Address Https://laravist.com/series/laravel-5-basic

Recently on the SF saw more and more laravel related problems, and as a laravel of the brain residue, originally intended to have the opportunity to record video tutorials, but this plan seems to be for some reason must be postponed for some time, so now first write the series of the article.

The first thing to note is that this tutorial is for people who are completely laravel, I try to make some concepts and focus clear, but you do not need to worry about it takes a lot of time to follow this tutorial to learn laravel, I believe that if you seriously follow the tutorial to the code to knock over again, I believe you will have a clear understanding of the laravel.

Before you begin: This tutorial is intended to be a daily article, first of all to cover a lot of laravel basics. Then I also plan to say laravel eloquent and some of its great features such as Schedule command and so on, as is the form of the blog or video format, see the situation behind it, so now is the beginning of our Laravel tutorial.

The content of this section:

    1. I'll start by explaining how to install Laravel.
    2. Talk about homestead This development environment
Installing Laravel

This series of textbooks is based on Laravel 5.1 stable version

Well, like the beginning of almost every frame, we need to know how to install Laravel.

Here is the most recommended is to use composer installation Laravel, if you have not touched composer, you can visit the official website here to see:

Installation: https://getcomposer.org/download/

Document: https://getcomposer.org/doc/

The advice here is that if you want to go down this path in PHP, then you have to learn to use composer, and don't put PHP's impressions before 10, and we (PHP developers) have great tools!

If you have a composer installed on your machine, please ignore the above.

The above nonsense is finished, go straight to the point:

The blogger's code is placed ~/Code under the directory, that is, open the command-line tool, you cd Code/ can directly access to my project code directory

Execute the composer installation command in the code/directory:

create-project laravel/laravel blog

The above command usually takes some time to complete the installation of Laravel (please use a VPN), take this opportunity to say composer a little bit of knowledge.

The above command is to use the composer create-project command to create a new project, the name of this project is a blog, that is, we will be in the Code/ directory to get a blog/ folder, as for laravel/laravel the Laravel provided by the package name, If you want to know what packages composer actually have, you can just come here to see:

Https://packagist.org/explore/

For example, some of the most commonly used packages: Phpspec,phpunit,behat,yii .... You can find it here:

You can find almost anything related to PHP development, such as you can search a password, you can get a lot of password processing packages:

After the installation is ready, Code/ you can see our project in the directory blog/ :

After installing Laravel, how do we use it? How do we enter a relative entitlement URL in the browser to visit our laravel? Here you have three options:

    1. Use a server that comes with PHP

Go to the corresponding directory of the project cd blog/ and open the PHP server:

php -S localhost:8999 -t public

Then visit localhost:8999 to see the first page of Laravel:

    1. Using artisan

is still blog/ under the directory, the command line executes:

php artisan serve

Then visit localhost:8000, you can also see the corresponding laravel default page:

This is actually using PHP's own server, but Laravel has encapsulated a command-line tool: Artisan. If you do not want to use the third method, it is recommended that you use this one directly during development.

In the blog/ directory under the command artisan, you can see Laravel artisan can actually do a lot of things, we will talk about later.

    1. Using Homestead

Homestead is a laravel official out of a virtual development environment, in this environment, you do not have to worry about server configuration and folder permissions configuration, etc., because in the homestead, these are already ready for you. And the big advantage is that if you're working on a multi-person team development, your team's development environment can be exactly the same, so you don't have to worry about upgrading to the latest version of the operating system and destroying your development environment. So, I recommend you to use homestead, although the first contact with these may feel a bit of trouble, but once you get used to and configure the virtual development environment, in the future development, you can avoid many unnecessary problems.

So, the next series of tutorials will be based on homestead, and you can use the second method directly.

The first is to install HOMESTAED, because homestead relies on vagrant, I use the virtual machine here is VirtualBox so, first we need to install these two things:

Virtualbox:https://www.virtualbox.org/wiki/downloads

Vagrant:https://www.vagrantup.com/downloads.html

Above these two download chain inoculation, choose the version suitable for your own operating system to download, install.

After installing these two, we can install our homestead:

vagrant box add laravel/homestead

After a while, you'll see a page like this:

 ~ vagrant box Add laravel/homestead==> box:loading metadata for box  ' laravel/ Homestead ' box: url: https : //atlas.hashicorp.com/laravel/homesteadthis box can work  With multiple providers! The providers that Itcan work with is listed below. Review the list and choosethe provider you'll be working  With. 1) virtualbox2) Vmware_desktopenter your choice: 1         

Choose 1, then wait for the installation, this process may take a while (teenager, open VPN!) )

Once the installation is finished, we can make a simple configuration of homestead, the command line execution:

homestead edit

Then you can see the contents of our Homestead.yaml configuration file:

We need to pay attention to the contents of the Red box:

folders:    map: ~/Code      to: /home/vagrant/Codesites:    - map: blog.dev      to: /home/vagrant/Code/blog/public

Folders is the configured vagrant mapping folder, here is our ~/Code mapping to the Homestead virtual Machine /home/vagrant/Code folder, the simple understanding is that if we ~/Code make any changes in this folder, vagrant will immediately sync to /home/vagrant/Code the , (后面我们可以ssh登录到Honestead中去看看这个文件夹) and then sites is our site configuration, here we will blog.dev this domain name map to the /home/vagrant/Code/blog/public directory, this is because we mapped the folders folder above /home/vagrant/Code , we can imagine that the folder below there is a blog/ directory, And this is our project directory, so what we specify here is actually the equivalent of using PHP to bring our own server and specify the root directory one effect:

php -S localhost:8999 -t public

To modify the Hosts file for this machine:

sudo vim /etc/hosts

Add the following line after this file:

192.168.10.10  blog.dev

Here, homestead configuration has been completed, this time, you only need to execute the command line:

homestead up

Wait for the virtual machine to start up and then visit http://blog.dev/ , and you'll be able to see the familiar page:

Login Homestead

Execute directly at the command line:

homestead ssh

Then you can log in to the Homestead virtual machine:

The folders in the diagram are the Code/ Homestead.yaml mapped folders we have configured above, and we have our blog/ projects in them. Follow-up development is based on this virtual machine, of course, you can also directly usephp artisan serve

Laravel Series Tutorial One: Installation and Environment configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.