Select Page

The aim of this article is to show, in a step by step approach, how to install and configure a Laravel application. At the time of this writing Laravel is at version 5.4.

Requirements:

The following requirements must be installed in your computer. If you don’t already have them installed please go ahead and do so.

Step 1 – Install Laravel Installer:

Run the following command to install the Laravel Installer;

composer global require "laravel/installer"
Step 2 – Create New Project:

The next step is to create a new project that will house the source files for your application. So lets create a new project called my-laravel-app by running the following command;

laravel new my-laravel-app

After the command has finished running cd into the my-laravel-app, or open it with an IDE of your choice, the project directory structure should look like this;

my-laravel-app/
├── app
│   ├── Console
│   │   └── Kernel.php
│   ├── Exceptions
│   │   └── Handler.php
│   ├── Http
│   │   ├── Controllers
│   │   │   ├── Auth
│   │   │   │   ├── ForgotPasswordController.php
│   │   │   │   ├── LoginController.php
│   │   │   │   ├── RegisterController.php
│   │   │   │   └── ResetPasswordController.php
│   │   │   └── Controller.php
│   │   ├── Kernel.php
│   │   └── Middleware
│   │       ├── EncryptCookies.php
│   │       ├── RedirectIfAuthenticated.php
│   │       ├── TrimStrings.php
│   │       └── VerifyCsrfToken.php
│   ├── Providers
│   │   ├── AppServiceProvider.php
│   │   ├── AuthServiceProvider.php
│   │   ├── BroadcastServiceProvider.php
│   │   ├── EventServiceProvider.php
│   │   └── RouteServiceProvider.php
│   └── User.php
├── artisan
├── bootstrap
│   ├── app.php
│   ├── autoload.php
│   └── cache
│       └── services.php
├── composer.json
├── composer.lock
├── config
│   ├── app.php
│   ├── auth.php
│   ├── broadcasting.php
│   ├── cache.php
│   ├── database.php
│   ├── filesystems.php
│   ├── mail.php
│   ├── queue.php
│   ├── services.php
│   ├── session.php
│   └── view.php
├── database
│   ├── factories
│   │   └── ModelFactory.php
│   ├── migrations
│   │   ├── 2014_10_12_000000_create_users_table.php
│   │   └── 2014_10_12_100000_create_password_resets_table.php
│   └── seeds
│       └── DatabaseSeeder.php
├── .env.example
├── package.json
├── phpunit.xml
├── public
│   ├── css
│   │   └── app.css
│   ├── favicon.ico
│   ├── index.php
│   ├── js
│   │   └── app.js
│   ├── robots.txt
│   └── web.config
├── readme.md
├── resources
│   ├── assets
│   │   ├── js
│   │   │   ├── app.js
│   │   │   ├── bootstrap.js
│   │   │   └── components
│   │   │       └── Example.vue
│   │   └── sass
│   │       ├── _variables.scss
│   │       └── app.scss
│   ├── lang
│   │   └── en
│   │       ├── auth.php
│   │       ├── pagination.php
│   │       ├── passwords.php
│   │       └── validation.php
│   └── views
│       └── welcome.blade.php
├── routes
│   ├── api.php
│   ├── channels.php
│   ├── console.php
│   └── web.php
├── server.php
├── storage
│   ├── app
│   │   └── public
│   ├── framework
│   │   ├── cache
│   │   ├── sessions
│   │   ├── testing
│   │   └── views
│   └── logs
├── tests
│   ├── CreatesApplication.php
│   ├── Feature
│   │   └── ExampleTest.php
│   ├── TestCase.php
│   └── Unit
│       └── ExampleTest.php
├── vendor
├── webpack.mix.js
└── yarn.lock
Step 3 –  Create .env file:

Rename.env.examplefile to .env

Step 4 – Generate the App Key

Run the following command to generate a base64 key for your app. This key needs to be generated before the laravel app can run. After you run this command you will notice that the APP_KEY config in the .env file now has a value.

php artisan key:generate
Step 5 – Install Laravel Homestead:

In this step we install Laravel Homestead as a dependency using composer. Laravel Homestead is an official, pre-packaged Vagrant box for Laravel applications.  It gives us a development environment without requiring the installation of PHP, a web server, and any other server software on your local machine. One of the advantages of virtual boxes is that they are disposable, you can destroy it and recreate it as quickly.

Run the following command in your project root to install Homestead in your project

composer require laravel/homestead --dev

After the command is completed you would notice that in your composer.json file you now have this "laravel/homestead": "^5.1"

{
    ...
    ...
    ...
"require-dev": {
        "fzaninotto/faker": "~1.4",
        "laravel/homestead": "^5.1",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~5.7"
    },
    ...
    ...
    ...
}

Once Homestead has been installed, use the make command to generate the Vagrantfile and Homestead.yaml file in your project root. The make command will automatically configure the sitesand folders directives in the Homestead.yaml file.

Mac / Linux:

php vendor/bin/homestead make

Windows:

vendor\\bin\\homestead make
Step 6 – Run the Application:

Before running the application lets map the ip address to the name of our app. Open the Homestead.yaml file and copy the ip address. Open your hosts file (In Mac/Linux the hosts file is located in the /etc  directory while in Windows it is located in c:\Windows\System32\Drivers\etc folder) and on a new line paste in the ip address and then give some spaces and then type my-laravel-app.app . It should look something like below, then save and close the file.

192.168.10.10   my-laravel-app.app

Finally, run vagrant up

Then browse to http://my-laravel-app.app/ . The app should be up and running.

Conclusion:

I hope this article was helpful. In a few days I will write another article on how to setup/configure a database for this application. In the mean time here is the link to the project in github https://github.com/sibenye/my-laravel-app