In this tutorial we will show you how to install Laravel on Debian 9. For those of you who didn’t know, 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:
1 2 | apt-get update apt-get upgrade |
Step 2. Installing Composer.
Install Composer which is the tool for dependency management in PHP:
1 2 | curl -sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer |
Install the latest version of Laravel, using the composer create-project command:
1 | composer create-project --prefer-dist laravel/laravel my_app |
If the installation is successful, you will see the following lines:
1 2 3 4 5 6 7 8 9 | 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. |
Once the installation is completed you can use the artisan serve command to serve your application:
1 | php artisan serve |
The output should be something like this:
1 | Laravel development server started: <http://127.0.0.1:8000> |
Run the following command to install both Nginx and PHP-FPM from the official Debian repositories:
1 | apt-get install nginx php-fpm |
Next, change the ownership of the Laravel directory:
1 | chown -R www-data:www-data /path/to/laravel |
Then, create a new Nginx server block with the following content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ### 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:
1 | 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:
1 | 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.