Contents
How to Install Laravel on Ubuntu
Before we start, you’ll need to SSH into your virtual private server. Here’s a helpful tutorial to help you along!
Following the steps below will walk you through the easiest way to install Laravel on Ubuntu:
1. Install Apache Web Server
For Laravel to work, you’ll need Apache. It is one of the most popular HTTP server tools, so it’s likely that your VPS has it installed. Luckily, you can check easily! Once you connect to your server using SSH, verify that an Apache system service exists. To do so, we have to run this command.
1 |
sudo systemctl status apache2 |
As you can see, on our VPS there is no Apache service, so we have to install it. To do this, execute the following command.
1 |
sudo apt install apache2 |
Ubuntu by default, starts the Apache service and makes it boot during system loading.
Now, if you’re using a firewall, it is necessary to establish a rule in the Ubuntu firewall so that Apache can run smoothly. If you have no firewall installed, feel free to skip this step.
1 |
sudo ufw allow “Apache Full” |
After that, we can check the Apache service status again.
1 |
sudo systemctl status apache2 |

Finally, open a web browser and we go to the IP address of your server or its domain name.
If you see this screen, that means Apache is up and running.

2. Install PHP
The next step is to install PHP. Fortunately, PHP 7 comes by default in Ubuntu’s official repositories, which makes the installation very easy. You will need to install the language itself and some extra module. To do this, execute the following command:
1 |
sudo apt install php libapache2-mod-php php-mbstring php-xmlrpc php-soap php-gd php-xml php-cli php-zip php-bcmath php-tokenizer php-json php-pear |
If the following command produced an output saying some packages were not found, simply update your Ubuntu by running the following command, and rerun the previous one:
1 |
apt-get update |
Now, we can test if PHP is working correctly. To do this, we need to create a file in Apache’s root directory. Let’s call it test.php. Run the following command:
1 |
sudo nano /var/www/html/test.php |
And add the call to the phpinfo function.
1 2 3 |
<?php phpinfo(); ?> |
We have to save it and close it. To save, hit CTRL+O, and to exit, hit CTRL+X Then, open the web browser and go to http://Your-serverIP/test.php.
If you see this screen, you can be sure that PHP is working as it should.

3. Download and Install a Database Manager
If we are going to develop using Laravel in Ubuntu 18.04, for that it is necessary to install a database manager. Laravel supports PostgreSQL, MySQL, MariaDB, SQLite and SQL server. We can install and configure the one we want. For this tutorial we will install MariaDB.
1 |
sudo apt install mariadb-server |
After that, you can set a password for the root. To do this, you need to use the mysql_secure_installation script. Keep in mind that this step is optional, but recomended for security reasons.
1 |
sudo mysql_secure_installation |
After we define the root password, we will be asked several MariaDB configuration questions. The answers you should input are next to the lines of code:
1 2 3 4 |
Remove anonymous users? [Y/n] y Disallow root login remotely? [Y/n] n Remove test database and access to it? [Y/n] y Reload privilege tables now? [Y/n] y |

Congratulations, MariaDB was installed successfully.
If you prefer a NoSQL database management system, read our tutorial to learn about how to install MongoDB on Ubuntu.
4. Install Composer
Composer is a PHP dependency manager that facilitates the download of PHP libraries in our projects. Composer both works great with and makes it much easier to install Laravel.
First, we need to download Composer.
1 |
curl -sS https://getcomposer.org/installer | php |
Next, we have to make sure Composer can be used globally and make it executable. The following commands will take care of that.
1 |
sudo mv composer.phar /usr/local/bin/composer |
1 |
sudo chmod +x /usr/local/bin/composer |
Suggested Reading
Check out our article to learn more how to change permissions and owners in Linux to control user access in your system.
5. Install Laravel on Ubuntu Using Composer
With Composer installed, now we can install Laravel. To do this, run the following command:
1 |
composer create-project --prefer-dist laravel/laravel [project_name] |
Of course, we have to replace [project_name] with the name of your application. In this case, we name the project example.
Suggested Reading
Check out our article to learn how to list installed packages on Ubuntu.
How to Use Laravel for Local Development
To develop applications locally, we can use PHP serve and specify the host and port of our server. To do this execute the commands following commands, and replace [IP] with your server IP, and [port] with the port you wish to use.
1 |
cd example |
1 |
php artisan serve --host=[IP] --port=[port] |
Next, open your web browser and go to the servers IP address or domain name and the specified port. The address would look like the one displayed in the output above. If you see the screen below in your browser, that means you’re ready to start working with Laravel.

How to Use Laravel to Deploy an Application
On the contrary, if we are going to deploy a Laravel application on our VPS, then we have to make some adjustments to avoid problems.
First, we need to move the previously created project directory to the Apache web root. Remember, in our case, the folder name is Example. Execute the following command:
1 |
sudo mv example /var/www/html/ |
After that, set the necessary permissions to ensure the project runs smoothly:
1 |
sudo chgrp -R www-data /var/www/html/example/ |
1 |
sudo chmod -R 775 /var/www/html/example/storage |
It is necessary to create a new virtual host for the project. It can be done easily with the commands below:
1 |
cd /etc/apache2/sites-available |
1 |
sudo nano laravel_project.conf |
Add the following to create the new Virtual host. Remember to replace thedomain.com with your server’s IP address.
1 2 3 4 5 6 7 8 9 10 11 |
<VirtualHost *:80> ServerName thedomain.com ServerAdmin webmaster@thedomain.com DocumentRoot /var/www/html/example/public <Directory /var/www/html/example> AllowOverride All </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> |
Save the file and close it.
After that, disable the default configuration file of the virtual hosts in Apache with this command:
1 |
sudo a2dissite 000-default.conf |
Afterwards, enable the new virtual host:
1 |
sudo a2ensite laravel_project |
Enable the Apache rewrite module, and finally, restart the Apache service:
1 |
sudo a2enmod rewrite |
1 |
sudo systemctl restart apache2 |
Now, open the web browser and go to the servers IP and voila. If you get the same Laravel landing screen you have seen last time, you’re ready to start working.
Now we can get to work with this great PHP framework.
Source: https://www.hostinger.com/tutorials/how-to-install-laravel-on-ubuntu#1_Install_Apache_Web_Server