How To Install Laravel on Debian 9

Install Laravel on Debian 9

In this tutorial we will show you how to install Laravel on Debian 9. For those of you who didn’t know, Laravel is a free, open-source PHP web application framework, created by Taylor Otwell and intended for the development of web applications following the model–view–controller (MVC) architectural pattern. It is a pretty new framework, but with a big potential to become one of the most popular PHP frameworks.

This article assumes you have at least basic knowledge of linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step installation Laravel on a Debian 9 (Stretch) server.

Install Laravel on Debian 9 Stretch

Step 1. Before we install any software, it’s important to make sure your system is up to date by running these following apt-get commands in the terminal:

apt-get update
apt-get upgrade

Step 2. Installing Composer.

Install Composer which is the tool for dependency management in PHP:

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

Step 3. Installing Laravel.

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

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+PVKBMW=] set successfully.

Step 4. Server your application with Artisan.

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>

Step 5. Installing Nginx and PHP-FPM.

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

apt-get install nginx php-fpm

Next, change the ownership of the Laravel directory:

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

Then, create a new Nginx server block with the following content:

### nano /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:

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

Now, we can restart Nginx web server so that the changes take place:

systemctl restart nginx

Congratulation’s! You have successfully installed Laravel. Thanks for using this tutorial for installing Install Laravel on Debian 9 Stretch system. For additional help or useful information, we recommend you to check the official Laravel web site.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get a best deal!