How to install Laravel framework on Debian 9 Stretch

Laravel is a very popular free and open source PHP framework created by Taylor Otwell and used for seamlessly deploying web applications using the MVC – Model View Controller- pattern. In this guide, we will show you how to install  Laravel framework on Debian 9 stretch.


Before we proceed, ensure that you have updated your sources lists and existing software. To achieve this run,

# sudo apt update && sudo apt upgrade

Before we install Laravel framework, let’s first install the prerequisite packages that will be required

System prerequisites

Your system will need to satisfy the requirements below before proceeding

  • Apache Web server
  • PHP >= 7.1.3 with OpenSSL, PDO, Mbstring, Tokenizer, XML, Ctype and JSON PHP Extensions.
  • Composer – an application-level package manager for the PHP

Installing Apache  Web server and PHP 7.2

Let’s first add a third party  PHP repository. Even though Ubuntu’ s own repository has its own PHP, a third party repository is preferred because it gets more frequently updated.

# sudo add-apt-repository ppa:ondrej/php

Update the repositories

# sudo apt update

Next, install Apache and PHP 7.2 alongside other prerequisites.

# sudo apt-get install apache2 libapache2-mod-php7.2 php7.2 php7.2-xml php7.2-gd php7.2-opcache php7.2-mbstring

Installing Laravel

Before installing Laravel, let’s install a few handy tools. These are git version control, curl and unzip packages.

# sudo apt install curl git unzip

Next, we need to install composer. Composer is another prerequisite that handles dependency management in PHP and allows you to package the required libraries associated with a package as one. Composer will download and install all the packages required to run the Laravel framework.

To install Composer , run the following commands

# cd /opt
# curl -sS | php
# mv composer.phar /usr/local/bin/composer

The curl command downloads Composer to the /opt directory. but since we want composer running globally, we need to move it to the /usr/local/bin directory under ‘composer’ name. This will allow us to run composer from anywhere.

Now, let’s navigate to the public html directory of our Debian System. To install Laravel, we will navigate to the  /var/www/html directory.

# cd /var/www/html directory.

Next, we shall create a directory “your-project” with Laravel installation. The composer will use git to download and install all packages and modules that Laravel requires for functioning

# sudo composer create-project laravel/laravel your-project --prefer-dist

Configuring Apache web server

With Laravel installed,  let’s now configure our Web server.

We are going to assign the necessary permissions to the project directory which will allow access to it from the www-data group and give it write permissions to the storage directory.  To achieve this, run the following commands.

# sudo chgrp -R www-data /var/www/html/your-project
# sudo chmod -R 775 /var/www/html/your-project/storage

Now let’s head out to the /etc/apache2/sites-available directory and run the command below to create a configuration file for our Laravel install.

#  vim /etc/apache2/sites-available/laravel.conf

Add the following content

    ServerName yourdomain.tld

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/your-project/public

        AllowOverride All

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

Save and Exit

Finally, enable the newly created laravel.conf file. First . let’s disable the default config file

# sudo a2dissite 000-default.conf

Next, enable the Laravel config file

# sudo a2ensite laravel.conf

Enable rewrite mode

# sudo a2enmod rewrite

Lastly, restart the Apache service

# sudo service apache2 restart


Congratulations! You have successfully installed Laravel on your Debian System. To confirm that the installation went as expected visit your server’s IP address. In my case, the server’s IP is

install Laravel framework

We hope that this guide has been helpful. Feel free to leave your feedback at the comment section.

About James

Hey there! This is James, a Linux administrator and a tech enthusiast. I love experimenting with various distributions of Linux and keeping tabs on what's new in the Linux world.
Deploy a managed hourly billed Cloud Server!
Read More