Laravel Series Tutorial One: Installation and Environment configuration

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

Originally from: Https://jellybool.com/post/programming-with-laravel-5-installation-and-settings

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:

  • I'll start by explaining how to install Laravel.
  • 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 under the ~/code directory, that is, open the command line tool, directly on the CD code/can go into my Project code directory

    Execute the composer installation command in the code/directory:

    Composer 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 under the code/directory to get a blog/folder, as for laravel/ Laravel is the package name provided by Laravel, and if you want to know what packages composer have, you can go straight 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 waiting for installation, we can see our blog/project in the code/directory:

    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:

  • Use a server that comes with PHP
  • Go to the corresponding directory of the project CD blog/, open the PHP server:

    Php-s localhost:8999-t Public

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

  • Using artisan
  • Still under the blog/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 artisan, you can see Laravel artisan can actually do a lot of things, we will talk about later.

  • 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://atl As.hashicorp.com/laravel/homesteadthis box can work with multiple providers! The providers that Itcan work with is listed below. Please 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

    You can then 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 mapping folder for configuring vagrant, here is our ~/code map to the/home/vagrant/code folder in the Homestead virtual machine, the simple understanding is that if we make any changes in the ~/code folder, Vagrant will be synchronized to the/home/vagrant/code immediately, (we can SSH login to Honestead to see this folder), and then sites is our site configuration, here we will blog.dev this domain map to/home/ Vagrant/code/blog/public directory, this is because we in the above folders map/home/vagrant/code This folder, we can imagine that this folder has 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, 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 code/folder in the figure is the map folder we configured above in Homestead.yaml, which has our blog/project. Subsequent development is based on this virtual machine, of course, you can also directly use PHP artisan serve

    Next section

    This article is mainly Laravel installation and environment configuration, the next section I will introduce Laravel router,views and controllers, I believe that after this introduction, you will be more clear about the laravel.

    Happy Hacking

  • 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.