In this brand new tutorial i am going to discuss that how we can deploy laravel project with apache and linux server. Laravel deploy project on linux ubuntu server tutorial you will learn it from scratch.
Millions of web applications on the internet are developed by Laravel. But there are very few articles in the internet arena that can properly explain to you how exactly you can deploy Laravel application with Apache on Ubuntu server. In this example tutorial, I will show you how to do that.
In this example, i will show you two ways that you can deploy your laravel application on linux server. You have to follow just some step by step instruction to do that.
If you are all right on prerequisites, you can continue to next step to deploy laravel project on linux ubuntu server.
There are some few steps that we can follow to deploy Laravel on Apache. The first one is to install all the required dependencies on the server. The second one is to clone the git repository or create a new Laravel project inside our project directory.
So, Let’s get started with the first step.
If we are going to clone a git repo, then we have to install git on our server. It is very easy. And, we also have to install composer on the server because we have to install Laravel’s dependencies using
composer update or
composer install command. So, Let’s first of all install the git and composer on our server.
Execute the following commands to install git and composer on Ubuntu server.
Once the installation is completed, it’s time to clone the git repository containing our Larvel project.
I am going to deploy it inside the default document root of Apache webserver. It means that I will navigate to
/var/www/html and execute the git clone command, just like this.
For the sake of learning purpose, I am cloning the Laravel project from the official git repository of Laravel. You can clone your project from the repository you desire. Just replace the URL and you are good to go.
OPTION 2: DEPLOY A NEW LARAVEL PROJECT
If you choose option one, you can skip this option two. But if you want to deploy a new Laravel project on your server, you can use the composer. Execute the following commands in your DocumentRoot for deploying a new Laravel application.
Recommended : Getting Started with Git and GitHub | Complete Beginner's Guide
If you are using Virtual hosts in your server, make sure that you have created a project inside the DocumentRoot of your server.
Having cloned the git repository or creating a new Laravel project, we have to create an
.env file. Now, you will see that a
.env.example file. Now copy the
.env.example file and then update the contents inside the copied
After copy the file from
.env and generate an encryption key, execute the following commands.
We also have to create and migrate your database. Make sure that the environment variables in your
.env file are correct at this point
This is the final steps, now you need to adjust vertualhost in your linux server. To open your virtual host file in edit mode, execute the following command.
Make sure that you do not forget to replace 000-default.conf with the name of your virtual host file if you are using multiple virtual hosts on your server. Now, add
/public at the end of the document root so that Apache will route all the traffic inside the
/public route that holds the main
index.php file of our project.
For example, you can see the updated default virtual host configuration file without comments
After updating your virtual host file, press CTRL+X followed by Y followed by the Enter key to save the updated virtual host file.
We are almost set to to test our deploying laravel app on linux server. Now, we time to restart the Apache server to apply the changes. Execute the below command to restart the Apache server.
After restarting the Apache server, you will be able to access your Laravel project in the browser. In this example, you have learned how to deploy laravel project app on linux server. As well as how to adjust vertualHost file.
#laravel #deployment #deploy-laravel #linux-server #apache