X

How to Install Laravel on Debian 9

In this 7-step guide, we will show you how to install Laravel on Debian 9. We’ll install Laravel together with PHP-FPM and Nginx. Laravel is a next generation of  PHP framework, and it’s the most popular open-source PHP framework lately. It is intended for the modern, rapid development of web applications, following the MVC model.  Installing Laravel (The PHP Framework For Web Artisans, its how they called it) on Debian 9 is an easy task and it should take few minutes to finish it. This guide should work on other Linux operating systems, but was written and tested for Debian 9.  Let’s get started!

1. Update the system and install necessary packages

sudo apt-get update 
sudo apt-get upgrade
sudo apt-get install curl

2. Install PHP and required PHP modules

To install the latest stable version of  PHP version 7.0 and all necessary modules, run:

sudo apt-get install php-cli php-gd php-mbstring php-mcrypt php-zip php-opcache php-xml

3. Install Composer

Composer is a dependency manager for PHP and of course Laravel, which you can install packages with. Composer will pull all the required libraries you need for your project.

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

4. Install Laravel

Install the latest version of Laravel, using the composer create-project command:

sudo composer create-project --prefer-dist laravel/laravel my_app

If the installation is successful, you will see the following lines:

Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover
Discovered Package: fideloper/proxy
Discovered Package: laravel/tinker
Package manifest generated successfully.
> @php artisan key:generate
Application key [base64:cBDZjOZD+T+TjlBI5sWqRWIqrOmDaNEYo2Jc+PVKVzY=] set successfully.

5. Server your application with Artisan serve command

Once the installation is completed you can use the artisan serve command to serve your application:

php artisan serve

The output should be something like this:

Laravel development server started: <http://127.0.0.1:8000>

You can now open your browser and access your new Laravel installation at: http://127.0.0.1:8000

6. Install and configure Nginx and PHP FPM

PHP’s built-in server is good for development but for production sites you will need to use a real web server such as Nginx or Apache. In this part of the tutorial, we will show you how to install and configure both, Nginx and PHP FPM to serve your Laravel application.

Run the following command to install both Nginx and PHP-FPM from the official Debian repositories:

sudo apt-get install nginx php-fpm

Change the ownership of the Laravel directory to the web server user:

sudo chown -R www-data:www-data /path/to/laravel

Create a new Nginx server block with the following content:

sudo vim /etc/nginx/sites-available/mydomain.com
server {
    server_name mylaravel.com www.mylaravel.com;
    listen 80;

    root /path/to/laravel/web;

    access_log /var/log/nginx/laravel-access.log;
    error_log /var/log/nginx/laravel-error.log;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }    
}

Activate the server block by creating a symbolic link :

sudo ln -s /etc/nginx/sites-available/mylaravel.com /etc/nginx/sites-enabled/mylaravel.com

7. Test Nginx configuration

Test the Nginx configuration and restart the Nginx service with the following commands:

sudo nginx -t
sudo service nginx restart

This was the last step, you have successfully installed Laravel on your Debian 9 VPS. For more information about how to manage your Laravel installation, please refer to the Laravel website.


If you are one of our web hosting customers, and use our optimized Laravel Hosting, you don’t have to install Laravel on Debian 9, our expert Linux admins will setup and optimize your Laravel VPS, for you. They are available 24×7 and will take care of your request immediately. As a Laravel developer, you should be focusing on Laravel development and improving your code and leave the server work to us.

PS. If you liked this post, on how to install Laravel on Debian 9, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

Categories Tutorials
admin :