Quick Summary:
Laravel Homestead has taken up the web application development market by the storm. Whether it is its efficiency, efficacy or implementation ability in every aspect it takes on the full sweep for developers. Therefore, in this blog post we have covered the all-round aspects of Laravel Homestead including the overview of the topic and Vagrant Box along with a step-by-step guide to use it for your next project.
In simple words, Laravel Homestead is a pre-packaged Vagrant box that enables a development environment for Laravel projects eliminating the needs for installing PHP, a web server, and any other server software to your local machine. It is precisely built to offer consistent and portable development environment that are easy to set up and can be used across different operating systems.
Homestead comes with inbuilt pre-installed tools and packages including PHP, Nginx, MySQL, Redis, and more that are commonly beneficial for Laravel development. Also, it includes config files making it easy to set up the virtual hosts and databases and develop amazing laravel applications.
Using Homestead requires Vagrant and VirtualBox in your system. After the installation process is complete you can download and configure the Homestead box based on the instructions provided in the official documentation.
Vagrant Laravel or Vagrant Box can be referred to a pre-built, pre-configured, lightweight and portable virtual machine that allows creating and managing consistent development environments across multiple machines and OS. Vagrant boxes include pre-installed software, configurations, and dependencies that are commonly used in development projects, allowing developers to work in a standardized and reproducible environment. It is managed via a tool (Vagrant) that automates the setup and configuration of the virtual machines.
Now, that we are aware of the details of both Laravel Homestead and Vagrant, let us jump to our detailed guide on implementing Homestead Laravel for Local Development.
The very first step to install Vagrant is installing the Vagrant command line utility to manage the virtual machine lifecycle. Then, isolate the dependencies and their configuration within a single disposable and consistent environment. When using Vagrant you can run various commands and access the code directory along with the MySQL database. Then, for installing and downloading Vagrant to your systems refer Vagrant Download Page.
In the next step you are required to install the VirtualBox as it is a mandate for running Vagrant into your systems. Talking about VirtualBox it is cross-platform virtualization software that allows users to extend their existing computers to run multiple operating systems. For installing and downloading VirtualBox refer to the VirtualBox Download Page.
Are you tired of manual development environment setup and inconsistencies across machines?
Look no further. Our team of experienced Laravel developers are ready to turn your ideas into reality. Hire Laravel developer today and take the first step towards creating your dream web application.
After that we need to add Homestead to VagrantBox so we can run the Homestead in the Virtualbox. Open terminal and run the following command:
The output looks like:
This box can work with multiple providers! …
We are using VirtualBox, so enter Option-3. This will take some time to add. Sometimes it may also take a long time.
After that run the below command to check if it has been successfully added to our box.
You should see something like this:
Start installing Homestead. Now we need to download the laravel homestead files into our system. Choose a directory where you would like to keep it and modify the path in the code accordingly. For me, I have chosen a folder named laravel inside my Documents folder. So run the below command
After successfully cloning the laravel files, go inside this folder.
Run below command to initialize Homestead that will create some files that are necessary for the Homestead. For Mac/Linux run the below command
For Mac, Ubuntu
For Windows…
After successful, you should see a response like this: Homestead initialized!
Now configure Homestead, navigate back one step in the terminal so that you are inside the Documents/laravel folder.
After that run the below command to create a folder named code. This folder has all your projects/coding files and folders.
Now after completing the all steps you should have this folder structure
> Documents
> laravel
> code
> Homestead
Go back to your text editor where you opened the Homestead.yaml file. Homestead.yml file holds the directory path and hosts names for your projects. Locate the folders path and modify it to map to the folder that you just created.
Folders:
And then save the file.
To start the Homestead machine goto terminal and run the below command so this will up the vagrant machine and running. If you are getting any errors then restart the system and try again.
If you make any changes to the Homestead.yaml file, you must restart the server by calling the below commands otherwise your changes will not reflect and will not work.
and then to re-running the Homestead
Same way, below command also able to reprovision your server but I will suggest below one:
To suspend vagrant run below command
Connect With SSH
Now run this command to ssh into the machine. By running the below command you can login into the machine. After login to the machine you can go inside your projects.
Above command will bring up the command line which looks like below. In the ssh you can access your project folders and files.
Enter the command ls to check if our configuration was correct and you should see our newly created code directory listed there.
– code
To logout from the ssh write below command.
Install Laravel installer in Homestead so you can create multiple Laravel projects. Make sure you are still logged in to the vagrant machine. Navigate into the code directory by running below command
To download the Laravel installer using Composer run the below command:
To create fresh laravel project run the below command
Now we have to configure the newly created laravel project in our Homestead.yaml file. First of all, add the name of the new project-website or you can say specific url (domain), url can be anything whatever you want and also set the database to the respective places.
sites: - map: myproject1.test to: /home/vagrant/code/myproject1/public - map: myproject2.test // For another project2 to: /home/vagrant/code/myproject2/public
Databases:
Second thing, go to myproject1/.env file and set the following values to set the database name, default username and password used by homestead to make the connection with the database.
Save the file. Your project is configured now.
Map the hosts file, The domain/url that we have set which is ‘myproject.test’. In order to be able to open this in our browser we need to add it to the system hosts file. Open a new window in your terminal, and type the following command.
For Mac and Ubuntu
For Window
This will open up the hosts file in your terminal in edit mode. It should look like the code below. At the end of the file, add a line with the local address and our project site domain/url that we have set.
## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost 127.0.0.1 myproject1.test //(This line is the one that we added.)
Save and close the file. Ctrl+O -> Enter to save, and Ctrl+X to close.
Open your browser and enter the website address/url, postfixed with :8000. Our project point out the port 8000 so it should look like this: http://myproject1.test:8000/. You should see a fresh Laravel website up.
Congratulations! Your fresh Laravel website is up and running.
Laravel Homestead is a pre-packaged virtual machine that provides a development environment for Laravel web applications. There are a number of reasons why developers prefer Laravel Homestead, a few of them are given below:
So, this is the step-by-step guide on Laravel Homestead for Local Development and the other aspects revolving around it. With this guide we can infer that it can help developers save time and effort offering a pre-configured environment that is ready to use. It is also beneficial to improve the code quality ensuring developers are using the same configuration and development workflow. Therefore, If you are also a business owner and confused if Laravel Homestead is your ideal choice for your upcoming project and how it can benefit your business then Hire Laravel Development Company like Bacancy to help you at every step of your web application development project.
Your Success Is Guaranteed !
We accelerate the release of digital product and guaranteed their success
We Use Slack, Jira & GitHub for Accurate Deployment and Effective Communication.