skip to content
Slashism

Setup Laravel on Ubuntu

/ 2 min read

Lets install some prerequisites:

Terminal window
sudo apt install -y git curl wget zip unzip

Install apache and check the status if it’s running properly:

Terminal window
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:

Terminal window
sudo a2enmod rewrite
sudo systemctl restart apache2

Run the following command to install MySQL:

Terminal window
sudo apt install mysql-server

Then run this is secure your mysql installation:

Terminal window
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:

Terminal window
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:

Terminal window
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:

Terminal window
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:

Terminal window
composer create-project --prefer-dist laravel/laravel my_laravel_app
cd my_laravel_app

Now you can start the inbuilt server:

Terminal window
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. 🎉