To deploy and run Laravel application on Ubuntu Apache 2 server, you need to install GIT or Composer on your system. Because with the help of GIT and Composer, you can easily deploy your Laravel application on Apache 2 Ubuntu Linux Server.
This guide demonstrates two options to deploy and run laravel project on Ubuntu Apache 2 Linux server. The first one is using git repo, And the second one is using the composer to deploy and run a new Laravel project on server.
Here are two options to deploy Laravel project on Linux ubuntu apache 2 server.
Option 1: Using Git CLONE Repository
In this option, you need to have installed git on your Apache 2 Ubuntu server, If it is not, simply type the sudo apt-get install git
command on the terminal window and press enter to install git on your system:
sudo apt-get install git -y
After that, To navigate to var/www/html
directory of your apache 2 ubuntu server by using cd /var/www/html
command on terminal window:
cd /var/www/html
Now, deploy laravel application using git, simply type git clone https://github.com/laravel/laravel.git command on terminal window and press enter:
git clone https://github.com/laravel/laravel.git
Once it is deployed on Apache 2 Ubuntu server, To install composer inside Laravel app directory, Use cd laravel composer install
the command for that:
cd laravel composer install
Option 2: Using Composer
To install Composer on apache 2 ubuntu server, simply type sudo apt-get install composer -y
command on terminal window and press enter:
sudo apt-get install composer -y
Once the composer is installed, Start deploying Laravel project on Apache 2 ubuntu server.
To Simple use the composer create-project --prefer-dist laravel/laravel
command on terminal window to install and create a new laravel project directory on ubuntu apache 2 server:
cd /var/www/html composer create-project --prefer-dist laravel/laravel .
Configure Database with Laravel App
Once you deploy Laravel project on apache 2 Ubuntu server, You need to configure database in .env file and generate an encryption key. To type this commands on terminal window 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 Permission and Ownership of Laravel Directory
To set up permission and ownership for laravel directory, simply open your terminal window and type the following comamnd into it to setup correct permission for that:
chown -R www-data.www-data /var/www/html/laravel chmod -R 755 /var/www/html/laravel chmod -R 777 /var/www/html/laravel/storage
Configure Apache 2 with Laravel Application
Finally, you need to create vertualhost in defalut conf file of apache ubuntu server.
Simply type sudo nano /etc/apache2/sites-available/000-default.conf
command on terminal window to open your virtual host file for editing:
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 webmaster@localhost 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.
To restart the Apache server to apply the changes, Simply type sudo service apache2 restart command on terminal window and press enter:
sudo service apache2 restart
Congratulations! Now open your web browser and access the Laravel on apache 2 ubuntu server.
Conclusion
In this tutorial, you have learned how to deploy laravel project on apache 2 ubuntu linux server.
Recommended Tutorials