Setting Up Laravel on XAMPP

In this tutorial we’ll be going through steps that’ll allow you to run Laravel under XAMPP, you won’t have to run the artisan serve command every time, all you need to do is just run XAMPP and that’s it.

Requirements

Download and install these 2 applications, when you’re done go to the next step.

Creating a Laravel Project

If you are installing composer for the first time then, open your command prompt and issue the following command

composer global require “laravel/installer”

Then navigate to C:/xampp/htdocs folder by issuing the following command

cd C:/xampp/htdocs

htdocs is your web servers directory, all your files that you want to be accessible on the domain, in our case localhost, are available here. So we’ll be creating a new Laravel Project here. I’ll be naming my project test, so here’s the command to make a new laravel project

laravel new test

So to this point we are done creating our laravel project, now we’ll configure XAMPP

Configuring XAMPP

In this part we need to edit 2 file

  • Windows HOSTS File ( C:/Windows/System32/drivers/etc )
  • Apache’s HTTPD.CONF File ( C:/xampp/apache/conf )

First we’ll configure the httpd.conf file, so navigate to the file’s directory and open the file in your favorite editor.

What we’ll be doing is to add a Virtual Host, it means that I can have multiple domains on my system for different project. Like for test I’ll have a domain like test.dev while for another project wordpress I could have a domain like wordpress.dev

So to add a virtual host, we need to add a piece of code to the httpd.conf file

<VirtualHost YOUR_CUSTOM_DOMAIN_NAME:80>
    DocumentRoot "YOUR_DOMAIN_ASSOCIATED_PROJECT_FOLDER_IN_HTDOCS"
    ServerAdmin YOUR_CUSTOM_DOMAIN_NAME
    <Directory "HTDOCS_LOCATION">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

So this is a general template for setting a virtual host, Now lets edit this template to create a virtual host for our project called test. 

<VirtualHost test.dev:80>
    DocumentRoot "C:\xampp\htdocs\test\public"
    ServerAdmin test.dev
    <Directory "C:\xampp\htdocs\test">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

REMEMBER always point your DocumentRoot to the Public directory of your laravel project.

Add the above piece of code to the bottom of your httpd.conf file and save it, Next we will introduce a small change in the host file to make things work. Restart your Apache Service from the XAMPP Control Panel.

Editing the HOSTS File

Till now the Apache Web Server is listening on our new domain but we haven’t redirected it to the localhost hence we’ll add an entry for our domain in the HOSTS file to allow our new domain to be redirected to the localhost.

What we need  to add is this line

127.0.0.1                  YOUR_CUSTOM_DOMAIN_NAME

Every time you add a new Virtual Host for a project, you must introduce this line along with your custom domain that you’ve set previously, So for our test.dev project this will be

127.0.0.1                  test.dev

To edit the HOSTS file we need Admin Privileges, so press the Windows Button on your keyboard and type Notepad, Then right click the Notepad icon and select Run As Admin.

Admin

 

Then with the Notepad open the hosts file from the directory mentioned in the beginning of this tutorial and at the end add this line

127.0.0.1                  test.dev

Save and exit, Restart your Apache Web Server again, Open your browser and goto test.dev

Laravel on XAMPP

Congrats, You are now running Laravel on XAMPP, Have fun developing with Laravel Framework 🙂

Regards,
Ex094

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s