Installing Laravel With Homestead
To get started first we need to install Laravel.
There are multiple ways you can install Laravel, the easiest way you can install Laravel is by using composer.
composer global require "laravel/installer"
Once Laravel is installed it will have a command of
laravel new which you can use to create your new project.
laravel new todo-list
This will add a fresh Laravel installation into the directory you're in.
Local Development Server
With the local development setup you can either use your local machine or go for virtual machines. To use PHP built-in development server you can use the Artisan command
php artisan serve
But you will need to make sure that you have all the required PHP modules installed.
- PHP >= 5.6.4
- OpenSSL PHP Extension
- PDO PHP Extension
- Mbstring PHP Extension
- Tokenizer PHP Extension
- XML PHP Extension
I would recommend you go for the Homestead approach for your local development as this will create a new local environment using Vagrant, this will install all the required PHP modules and setup your Laravel directory permissions for you.
Before you're able to install Homestead you first need to setup Vagrant, for more information on setting up Vagrant you can view a previous tutorial about adding Vagrant to the workflow.
Homestead will then create a new virtual machine with the following software installed.
- Ubuntu 16.04
- PHP 7.0
- Node (With PM2, Bower, Grunt, and Gulp)
There are two ways you can setup Homestead either globally or per project. If you're planning on changing the configuration of the box then go for the per project config. Else go for the global box as you can easily reuse this on your other Laravel projects.
First add the homestead box to your vagrant installation.
vagrant box add laravel/homestead
You can then clone the Homestead project from github.
git clone https://github.com/laravel/homestead.git Homestead
Install it into a global location so that you can easily reuse this on your other projects. Once Homestead was installed cd to you Homestead directory.
Then run the
bash init.sh command, this will create your Homestead config file
Homestead.yaml in your home directory
Now you can open this config folder and setup the Homestead box.
First you need to select the provider for your Homestead box, if you're using Vagrant like above then make sure this setting is set to virtualbox.
The shared folder is your local folders that will be shared with your Homestead environment.
folders: - map: /var/www/todo-list to: /home/vagrant/Code
To setup the sites on your nginx server you will do change the sites: property on the Homestead.yaml. This will the parameters added to Nginx virtual hosts, for the local domain you're going to use and the document root of the location of the files on the virtual machine.
sites: - map: todolist.dev to: /home/vagrant/Code/Laravel/public
With the nginx sites setup we can add them to our hosts files if you're using Linux or Mac then then your hosts file is located
Launch The Vagrant Box
To launch the box and see your site running you now need to navigate to your Homestead folder on the command line and run the
vagrant up command.
This will boot up your Vagrant box and install your sites from the information in your config file.
You can now navigate to the domain you put in your Homestead.yaml file and you'll be able to see your Laravel site.
Connecting To The Database
To configure the database connection on your local environment you'll need to edit your
.env file, the host for your database is relational to your virtual machine so it will be
The username for your Homestead database is
homestead and the password is
With your local environment setup we can now start with the Todo list application project.
With the site setup you can navigate to
http://todolist.dev and see the default Laravel page located in
The first thing you need to to when setting up Laravel is to set your application key to a random string this is used as the salt for any encrypted data or user sessions your application uses.
php artisan key:generate
Subscribe To Newsletter
Get weekly updates to your email