DebianLinuxTutorials

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 the step-by-step installation of Laravel on a Debian 9 (Stretch) server.

Prerequisites

  • A server running one of the following operating systems: Debian 9 (Stretch).
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

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 the 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 the Nginx web server so that the changes take place:

sudo systemctl restart nginx

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

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 the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button