How to Install Laravel in Ubuntu Server?

Hi,

This tutorial will give you example of how to install laravel in ubuntu. i would like to share with you ubuntu install laravel project. it’s simple example of how to install laravel in ubuntu step by step. i explained simply step by step how to install laravel in ubuntu using terminal. So, let’s follow few step to create example of how to install laravel in ubuntu digitalocean.

In this tutorial, i will show you how to install laravel project in ubuntu 21.10, ubuntu 21.04, ubuntu 20.04, ubuntu 18.04 and ubuntu 16.04 server. you can easily install laravel 6, laravel 7 and laravel 8 version using composer.

i am going to step by step from scratch so you have to follow following step to install laravel app in your server like digitalocean, godaddy server and aws ec2 linux server as well.

so, let’s follow bellow steps:

Step 1: Install Apache

Update Local Package:

sudo apt update

Install apache2 Package:

sudo apt install apache2

After install successfully apache2, you can go to browser and check your IP as like bellow and layout:

http://your_server_ip

OR

http://localhost

Output:

How to Install Laravel in Ubuntu Server?

Step 2: Install PHP

Install software-properties-common:

sudo apt install software-properties-common

Add the ondrej/php PPA:

sudo add-apt-repository ppa:ondrej/php

Update Local Package:

sudo apt update

Install PHP:

sudo apt install php libapache2-mod-php php-mbstring php-cli php-bcmath php-json php-xml php-zip php-pdo php-common php-tokenizer php-mysql

Now you can check php version by following command:

php -v

you can see terminal layout as bellow:

How to Install Laravel in Ubuntu Server?

Set DirectoryIndex on Apache:

you have to set default index.php file for run. so let’s run bellow command and update file:

sudo nano /etc/apache2/mods-enabled/dir.conf

/etc/apache2/mods-enabled/dir.conf

<IfModule mod_dir.c>

DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm

</IfModule>

Now let’s restart apache server:

sudo systemctl reload apache2

Step 3: Install MySQL

Install MySQL Server:

sudo apt install mysql-server

Access MySQL:

Now you can access mysql by using mysql command:

sudo mysql

OR

mysql -u root

you can see terminal layout as bellow:

How to Install Laravel in Ubuntu Server?

Create User on MySQL:

you can create new user for mysql by using following query:

mysql -u root -p

CREATE USER 'demo'@'localhost' IDENTIFIED BY 'rootnewpassword';

GRANT ALL PRIVILEGES ON * . * TO 'demo'@'localhost';

FLUSH PRIVILEGES;

Create Database on MySQL:

CREATE DATABASE laravel_demo;

Step 4: Install Composer

Download Composer:

curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php

Move Composer:

sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer

Composer Command:

composer

you can see composer command layout:

How to Install Laravel in Ubuntu Server?

Step 5: Install Laravel

now, we are ready to install laravel app using composer, so let’s go to www directory and install laravel app:

cd /var/www

now let’s add following command for download latest laravel app:

composer create-project laravel/laravel demo

Output:

How to Install Laravel in Ubuntu Server?

Next, you must need to give permission to storage folder inside demo project folder as like bellow:

sudo chmod -R 777 /var/www/html/demo/storage

Next, we need to change default folder path on apache for laravel app. so let’s change default config file as bellow:

sudo nano /etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>

# The ServerName directive sets the request scheme, hostname and port that

# the server uses to identify itself. This is used when creating

# redirection URLs. In the context of virtual hosts, the ServerName

# specifies what hostname must appear in the request's Host: header to

# match this virtual host. For the default virtual host (this file) this

# value is not decisive as it is used as a last resort host regardless.

# However, you must set it for any further virtual host explicitly.

#ServerName www.example.com

ServerAdmin [email protected]

DocumentRoot /var/www/demo/public

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,

# error, crit, alert, emerg.

# It is also possible to configure the loglevel for particular

# modules, e.g.

#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log

CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are

# enabled or disabled at a global level, it is possible to

# include a line for only one particular virtual host. For example the

# following line enables the CGI configuration for this host only

# after it has been globally disabled with "a2disconf".

#Include conf-available/serve-cgi-bin.conf

<Directory /var/www/html/demo>

AllowOverride All

</Directory>

</VirtualHost>

Now, let’s restart apache2.

sudo service apache2 reload

After install successfully, you can go to browser and check your IP as like bellow and layout:

http://your_server_ip

OR

http://localhost

Output:

How to Install Laravel in Ubuntu Server?

Add Database Configuration:

here, we will add database configuration on .env file and run migration for make sure it’s working or not:

.env

DB_CONNECTION=mysql

DB_HOST=127.0.0.1

DB_PORT=3306

DB_DATABASE=laravel_demo

DB_USERNAME=demo

DB_PASSWORD=demo123456

now let’s run migration command:

php artisan migrate

Output:

How to Install Laravel in Ubuntu Server?

I hope it can help you…

3 thoughts on “How to Install Laravel in Ubuntu Server?”

Leave a Comment