Writing

Pankaj Sanam · personal space

Code · Programming

Setup Laravel on Ubuntu

Guide to install and set up Laravel on Ubuntu with Apache, MySQL, PHP, and Composer

A layered Laravel application stack connected to a database and Ubuntu server A layered Laravel application stack connected to a database and Ubuntu server

Lets install some prerequisites:

sudo apt install -y git curl wget zip unzip

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:

http://localhost

Now enable the mod_rewrite in apache2:

sudo a2enmod rewrite
sudo systemctl restart apache2

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:

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:

<?php
phpinfo();

You can open the following URL in your browser to see all the configured PHP settings:

http://localhost/info.php

Now delete the info.php as it is not needed anymore and could cause a potential security issue as this exposes a lot of details.

Install the PHP depedency manager known as Composer:

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer
composer --version

Now 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:

http://127.0.0.1:8000

That’s it! You have successfully installed Laravel on your Ubuntu machine. 🎉