How to Deploy Laravel Project on Linux Server

How to Deploy Laravel Project on Linux Server

Laravel deploy project on linux ubuntu server. In this tutorial, you have learend how to deploy laravel project app on linux ubuntu server.

This tutorial demostrate you two solutions for deploy laravel project apps on linux server. The first solution is deploy laravel project using git repo. And second solution is to create a new Laravel project inside our project directory. And at the end of these solutions, adjust vertual host file.

Now let’s start to deploy laravel project apps on linux ubuntu server. Using the below solutions.

Deploy Laravel Project App with Apache on Linux Ubuntu Server

The below have two solutions to deploy laravel project on linux ubuntu server.

The first one soultion to git clone repo for deploy laravel project on linux ubuntu server. And the second solution is to clone the git repository or create a new Laravel project inside our project directory.

And at the end of these two solutions, adjust our Virtual host configuration file to support Laravel’s directory structure.

So first of all, you need to install all the required dependencies on the linux ubuntu server. So use the following command to install all dependencies on linux ubuntu server:

$ sudo apt-get update
$ sudo apt-get install git composer -y

These commands are installed composer on the linux server because install Laravel’s dependencies using composer update or composer install command.

SOLUTION 1: USING CLONE A GIT REPOSITORY

Now deploy Laravel from it’s official GitHub repository. And deploy laravel inside the default document root of Apache webserver. That means, navigate to /var/www/html and run the git clone command, as follow:

cd /var/www/html
git clone https://github.com/laravel/laravel.git .
composer install

SOLUTION 2: DEPLOY A NEW LARAVEL PROJECT

If you leave solution one. Then you have solution two here, So deploy a brand new Laravel project on your linux server. At that time, you can use the composer and run the following command on your terminal as follow:

cd /var/www/html
composer create-project --prefer-dist laravel/laravel .

After that, you need to update .env file and generate an encryption key. So use the following command for that:

cd /var/www/html
cp .env.example .env
php artisan key:generate

These commands will copy the file from .env.example to .env and generate an encryption key, execute the following commands.

Setup VertualHost On Linux Server

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.

$ 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.

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/html/public
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

After updating your virtual host file, press CTRL+X followed by Y followed by the Enter key to save the updated virtual host file.

Finally, restart the Apache server to apply the changes. Execute the following command to restart the Apache server.

sudo service apache2 restart

If your apache server successfully restarts, you will be able to access your Laravel project in the browser.

Conclusion

In this tutorial, you have learned how to deploy laravel project apps on linux server. As well as how to adjust vertualHost file.

AuthorTuts Make

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Javascript, JQuery, Laravel, Livewire, Codeigniter, Vue JS, Angular JS, React Js, WordPress, and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *