HOW TO INSTALL LARAVEL ON DEBIAN 9

 In Dedicated, VPS, Web

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. For more information about how to manage your Laravel installation, please refer to the Laravel website.

Recommended Posts

Start typing and press Enter to search