Setup Laravel on Ubuntu

Subscribe to my newsletter and never miss my upcoming articles

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-

http://localhost

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-

<?php
phpinfo();

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

http://localhost/info.php

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 https://getcomposer.org/installer | 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-

http://127.0.0.1:8000

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

No Comments Yet