PHP Development

How To Install And Configure Laravel In Windows?

Laravel Installation and Configuration

Well a step by step tutorial for installing for which some of you PHP developers or beginners are waiting for a while now. Read the full article below to get full depth knowledge about Laravel and its installation process.

Since Laravel is released from 2011, Laravel is evolving and has emerged as a go-to framework for developers to write a secure and robust fast web application. Laravel is one of the most powerful MVC PHP frameworks which focuses on keeping the syntax expressive, elegant, and simple to use possible which makes it possible for developers to launch and can deploy their PHP app at a faster speed.

How To Install And Configure Laravel In Windows

Now getting onto Installing Laravel on Windows

Installing Laravel framework on Windows, there are two ideal ways:

  1. Using Composer

It is one of the PHP dependency managers which is used by Laravel to manage all its dependencies. To use Laravel framework on your windows you must have composer installed on your Windows or Mac OS. Also, check for the server requirements before installing the Laravel components.

Check for the listed requirements below:

  • PHP version should be above 7.1
  • Check for XML PHP extension
  • Check for PDO PHP extension
  • Check for CType PHP extension
  • You should have JSON PHP extension
  • Mbstring PHP should be available
  • Open SSL PHP is a must

If the server requirements are matched the above-listed requirements then you will be needing a Laravel installer using Composer by giving the command input:

composer global require Laravel/installer”

Once you have installed the Laravel installer, you can use the Laravel command to start fresh with the installation in the directory you specify. For an e.g. 

Command:Laravel new project” this command will create a directory named project containing a fresh Laravel installation in which all the Laravel dependencies of Laravel are already installed.

Another command to install Laravel via composer is create-project”.

Command: composer create-project –prefer-dlist Laravel/Laravel project

If you have already installed PHP on your PC, then you can start the localhost server on your server using the artisan command to start the built-in PHP development.

Localhost server: http://localhost:8080:
Artisan Command: “php artisan serve”
  1. Using Laravel Homestead

Laravel Homestead is an official, pre-packaged box, is the most recommended way to install Laravel on any Windows, Mac OS, or Linux System.

Laravel Homestead fulfils the system needs and requirements of the Laravel framework, it provides the facilities to the developers a much better way to create a local development environment without installing PHP, a web server, or any other server software.

How to install Laravel using Homestead on your Windows PC?

#Step 1: Hardware Virtualization

Installing Laravel framework on a Windows PC, the first step which is required for you to do is to enable Hardware Virtualization (VT-x). You need to download the utilities from the manufacturer of your processor.

  • For the users using the AMD processors, download the AMD-V Technology.
  • For the users or developers using the Intel processor, you need to download the Intel Processor Identification Utility.

Well, installing these technologies will determine whether the hardware virtualization is enabled on your PC.

#Step 2: Installing the Required

After you are done with Step 1, you need to download the latest versions of the software which are listed down below:

  • Git Bash for windows
  • VirtualBox for Windows
  • Vagrant Installer for Windows

After you are finished installing the above-listed software one by one, be sure to install the Virtual Box at first because the other software listed above depends upon the VirtualBox environment.

#Step 3: Installing the Homestead Vagrant Box

Once you have installed the VirtualBox, Vagrant and Git, you have to add Laravel/homestead box to your Vagrant installation.

Just input the following command in your terminal and just hit the enter button:

Command: “vagrant box add laravel/homestead”

Also, if the command above doesn’t work then the vagrant you have installed is not up to date.

#Step 4: Installing the Homestead

In this step running the command given below you  can change the directory of your project to C:\Users\USER_NAME\Homestead

Command: “cd Homestead”

Then you have to run the command from the Homestead directory

Command: “init.bat”

With this command running from the directory it will create the Homestead.yaml configuration file in the C:\Users\USER_NAME\Homestead directory which you created.

#Step 5: Create an SSH Key

The Vagrant Folder Synchronization helps you to edit your project files on the host machine or windows and it reflects the changes on the guest virtual machine. If you want to run some advanced tasks like migration you need to log into the guest with the help of terminal and for that, you will require an SSH key.

Now to check if the SSH key pair exists on your Windows PC, go to C:\Users\USER_NAME\Homestead directory and find the folder which should be named as .ssh.

If the Key exists, click on the folder and check if the two files named id_rsa.pub files are present there. If they exist then move on the next step and if they do not then create a new SSH key by running the command given below by providing your email id from the Git Bash.

Command: “ssh-keygen -t rsa –C” “your email here”

And you will see a message which says: Generating public/private rsa key pair

And you just have to keep pressing enter button whatever command line asks you to do and finally, a new .ssh folder containing the tow files named id_rsa.pub will be created.

#Step: 6 Editing the Configuration File

Now get back to your Homestead directory and edit the Homestead.yaml configuration file with any of the source code editor you are using. In the Homestead.yaml the only things you will need to focus are on sites, folders and databases. 

#Step: 7 Configuring the Host File

You will not be able to run .test files in your browser unless adding them to your windows hosts files. You need to configure shared folder and Nginx sites and likewise, you can create databases for multiple sites like-

-homestead

-example (if you need an extra database)

You need to navigate to C:\Windows\System32\drivers\etc\hosts and add some of the following lines at the end of your host’s file.

Which are: 192.168.10.10 homestead.test

                     192.168.10.10 example.test

Just make sure that you keep the IP address same as the one that you set in your Homestead.yaml file otherwise the terminal could not launch the files on the browser and things won’t run.

#Step: 8 Launch the Homestead Vagrant Box

Once the Homestead.yaml is configured according to the developers need and added the domains according to the needs then you can launch the Homestead Vagrant Box by the command given below:

Command: “vagrant up”

Now just make sure to use the command only from the C:\User\USER_NAME\Homestead directory folder which contains all the required repository. Use can use the command to run the terminal machine.

Command: “vagrant destroy –force”

And if you want to launch the Homestead Vagrant Box from anywhere using Git Bash you need to create a file which is named as .bash_profile in the C:\Users\USER_NAME\Homestead and type the following lines of code in the file and save it.

alias..=”cd..”

alias vm=”ssh [email protected] –p 2222”

function homestead(){

(cd ~/Homestead && vagrant $*)

}

Save the code and restart the Git Bash for changes to take effect.

Run the command through Git Bash to run the Homestead Vagrant Box from anywhere.

Command: “homestead up”

These are all the steps you need to run and install the Laravel Framework in your PC.

Conclusion:

Follow all the steps described above and install the laravel framework for different OS such as Windows and Linux or Mac OS. There is more to Laravel then just installing and using it you can also create your first project application using the powerful MVC of PHP framework and get such amazing results. Get to know more about Laravel Web Application Development Services.

Rachit Mathur
About author

Rachit Mathur, being a Digital Marketer, he has an tremendous passion for writing. He found his way in Content Marketing. Curious about the tech world and having a technical background he love to explore and write about different technologies which also helps the company to grow faster.
    Related posts
    PHP Development

    Top PHP Development Trends Of 2020, Details Inside

    PHP Development

    The Benefits of Using NodeJS And Reasons To Choose It For Web App Development

    PHP Development

    10 Reasons Why To Choose Laravel Framework For Web Development