Pankaj Sanam


Setup Laravel on Ubuntu

Setup Laravel on Ubuntu

Pankaj Sanam's photo
Pankaj Sanam
·Apr 22, 2020·

2 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

Before setting up the Laravel on Ubuntu, lets install some prerequisites-

sudo apt install -y git curl wget zip unzip

Install Apache

Install apache and check the status if it's running properly-

sudo apt install apache2
sudo systemctl status apache2

You can check if you have installed apache properly by opening this address in your browser, which would open a default apache2 page-


Now enable the mod_rewrite in apache2-

sudo a2enmod rewrite
sudo systemctl restart apache2

Install MySQL

Run the following command to install MySQL-

sudo apt install mysql-server

Then run this is secure your mysql installation-

sudo mysql_secure_installation

Now answer the questions-

Remove anonymous users? y

Disallow root login remotely? y

Remove test database and access to it? y

Reload privilege tables now? y

Install PHP

Install following packages-

sudo apt install php libapache2-mod-php php-mysql

sudo apt install php7.2-common php7.2-cli php7.2-gd php7.2-mysql php7.2-curl php7.2-intl php7.2-mbstring php7.2-bcmath php7.2-imap php7.2-xml php7.2-zip

Now check if the PHP is installed properly by creating a new file-

sudo nano /var/www/html/info.php

Put the following content in the above file-


Now open the following URL in your browser and you would see a lot of PHP related details-


Now delete the info.php as it is not needed anymore.

Install Composer

It's a dependency manager for PHP. You can install composer by running these-

curl -sS | php

sudo mv composer.phar /usr/local/bin/composer

sudo chmod +x /usr/local/bin/composer

composer --version

Install Laravel

Go to the directory where you would like to install Laravel and then run the following-

composer create-project --prefer-dist laravel/laravel my_laravel_app

cd my_laravel_app

Now you can start the inbuilt server-

php artisan serve

You can verify it here-

Note: Check out my last post if you want to use a virtual host instead of the in-built server.

Share this


🙋‍♂️ Hello there,

My name is Pankaj, and I am the author of Slashism. I hope that you learn something useful today.

If you like my content and want to stay updated then subscribe to my newsletter in the header.

You can also follow me on Twitter and say hello.

If you would like to request a particular article/topic covered or would want to discuss something, then please start a discussion here on Github Discussions

⭐ Keep learning, keep growing ⭐