Tips / Recommendations

Install Laravel on Ubuntu

System requirements

Your system must meet the following requirements to be able to run the latest version of Laravel:

PHP> = 7.1.3 with OpenSSL, PDO, Mbstring, Tokenizer, XML, Ctype and JSON PHP Extensions.
Composer is an application-level package manager for PHP.
Setting prerequisites

First, make sure you update your system sources and existing software packages using the following commands.

$ sudo apt-get update
$ sudo apt-get upgrade

Installing LAMP Stack on Ubuntu

Then set up a running LAMP environment (Linux, Apache, MySQL and PHP), if you already have it, you can skip this step or install the LAMP stack using the following commands on your Ubuntu system.

$ sudo apt-get install python-software-properties
$ sudo add-apt-repository ppa: ondrej / php
$ sudo apt-get update
$ sudo apt-get install apache2 libapache2-mod-php7.2 mysql-server php7.2 php7.2-xml php7.2-gd php7.2-opcache php7.2-mbstring php7.2-mysql

Although the Ubuntu repository has PHP by default, it is always recommended to have a third party repository for more frequent updates.

If you want, you can skip this step and stick with the standard PHP version from the Ubuntu repository.

Installing Composer on Ubuntu

Now we need to install Composer (dependency manager for PHP) to install the required Laravel dependencies using the following commands.

# curl -sS | php
# mv composer.phar / usr / local / bin / composer
# chmod + x / usr / local / bin / composer
Installing Laravel on Ubuntu

After installing Composer, you can now download and install the latest Laravel from the official git repository in the Apache / var / www directory.

$ cd / var / www
$ git clone
$ cd / var / www / laravel
$ sudo composer install

After the Laravel installation is complete, set the appropriate permissions for all files using the following commands.

$ chown -R www-data.www-data / var / www / laravel
$ chmod -R 755 / var / www / laravel
$ chmod -R 777 / var / www / laravel / storage
Setting up an encryption key

Now create an environment file for your application using the provided sample file.

$ cp .env.example .env

Laravel uses the application key to secure user sessions and other encrypted data.

Therefore, you need to generate and set your application key to a random string using the following command.

$ php artisan key: generate

After the key has been generated, open the .env configuration file and update the required values.

Also, make sure APP_KEY is set correctly in the config file generated in the above command.

APP_NAME = Laravel
APP_ENV = local
APP_KEY = base64: AFcS6c5rhDl + FeLu5kf2LJKuxGbb6RQ / 5gfGTYpoAk =
APP_DEBUG = true
APP_URL = http: // localhost
Create database for Laravel

You may also need to create a MySQL database for your Laravel application project using the following commands.

$ mysql -u root -p
mysql> CREATE DATABASE laravel;
mysql> GRANT ALL ON laravel. * to ‘laravel’ @ ‘localhost’ IDENTIFIED BY ‘secret_password’;
mysql> quit

Now open your .env config file and update your database settings as shown below:

DB_PORT = 3306
DB_DATABASE = laravel
DB_USERNAME = laravel
DB_PASSWORD = secret_password
Configuring Apache for Laravel

Now go to the default virtual host config file in Apache /etc/apache2/sites-enabled/000-default.conf and update the DocumentRoot public directory in Laravel as shown below:

$ nano /etc/apache2/sites-enabled/000-default.conf

Now change the default virtual host configuration with the following content and also be sure to replace yourdomain.tld with your website’s domain name as shown below:

<VirtualHost *: 80>
ServerName yourdomain.tld
ServerAdmin webmaster @ localhost
DocumentRoot / var / www / laravel / public
<Directory />
Options FollowSymLinks
AllowOverride None
<Directory / var / www / laravel>
AllowOverride All
ErrorLog $ {APACHE_LOG_DIR} /error.log
CustomLog $ {APACHE_LOG_DIR} /access.log combined

After making the above changes, remember to reload the Apache configuration changes by restarting the service using the following command:

$ sudo service apache2 restart

Accessing Laravel Application

Finally, access your Laravel app from the browser using the following url.

http: //yourdomain.tld
http: // your-ip-address