In this tutorial you will learn about the How to Deploy Laravel Project on Linux Server and its application with practical example.
In this Laravel deploy project on linux ubuntu server tutorial. II’ll show you how to deploy laravel project app on linux ubuntu server.
In this tutorial I’ll demonstrate you two different methods to deploy laravel project on linux server. The first method is deploy laravel project using git repo. And second method is to create a new Laravel project inside our project directory. And at the end of these solutions, adjust vertual host file.
Deploy Laravel Project App with Apache on Linux Ubuntu Server
In this tutorial we will use two different methods to deploy laravel project on linux ubuntu server.
first of all, we are required to install all the required dependencies on the linux ubuntu server. So use the following command to install all dependencies on linux ubuntu server:
1 2 |
$ sudo apt-get update $ sudo apt-get install git composer -y |
Above commands will have installed composer on the linux server because install Laravel’s dependencies using composer update
or composer install
command.
Deploy Laravel Project Using Clone GIT Repository
To deploy Laravel from it’s official GitHub repository. And deploy laravel inside the default document root of Apache webserver. That means, go to /var/www/html
and run the git clone command, as follow:
1 2 3 |
cd /var/www/html git clone https://github.com/laravel/laravel.git . composer install |
Deploy a New Laravel Project
To deploy a fresh Laravel project on your linux server. Now, you can use the composer and run the following command on your terminal as follow:
1 2 |
cd /var/www/html composer create-project --prefer-dist laravel/laravel . |
Now, you need to update .env file and generate an encryption key. So use the following command for that:
1 2 3 |
cd /var/www/html cp .env.example .env php artisan key:generate |
The above commands will copy the file from .env.example
to .env
and generate an encryption key.
Setup VertualHost On Linux Server
Now, you need to adjust vertualhost in your linux server. To open your virtual host file in edit mode, execute the following command.
1 |
$ sudo nano /etc/apache2/sites-available/000-default.conf |
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, Here is the updated default virtual host configuration file without comments.
1 2 3 4 5 6 |
<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/html/public ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> |
Once you done with updating virtual host file, press CTRL+X followed by Y followed by the Enter key to save the updated virtual host file.
Finally, we are good to restart the Apache server to apply the changes. Run the following command to restart the Apache server.
1 |
sudo service apache2 restart |
Now, your apache server successfully restarts, now you can access your Laravel project in the browser.