{"id":1455,"date":"2022-06-04T11:33:15","date_gmt":"2022-06-04T11:33:15","guid":{"rendered":"https:\/\/www.ridiculously-simple.com\/?p=1455"},"modified":"2023-06-18T07:05:49","modified_gmt":"2023-06-18T07:05:49","slug":"laravel-9-step-by-step-on-debian-11-bullseye","status":"publish","type":"post","link":"https:\/\/www.voodoo.business\/blog\/2022\/06\/04\/laravel-9-step-by-step-on-debian-11-bullseye\/","title":{"rendered":"Laravel 9 on NGINX under Debian 12 (bookworm) &#8211; Step by step"},"content":{"rendered":"\n<p>This part of the tutorial is a hands on setup to have Laravel working on nginx under Linux. this is not the only way to run Laravel, for all the options, see here<\/p>\n\n\n\n<p>NOTE: Most if not all of the popular development tools are available for Linux and Windows, so If this setup is for development, you might want to install Debian Linux with the Gnome GUI so that you can install the development tools used in the next part of this tutorial, if you are going to be developing on a different machine or this is for production, then you shouldn&#8217;t.<\/p>\n\n\n\n<p>STEP 1: Install Debian 11 (Bullseye) on a computer.<\/p>\n\n\n\n<p>STEP 2: Install the basic Laravel environment with the following commands, Laravel 9 requires PHP 8, which at the time of writing is not available in Debian 11 repositories, so we will need to add the repositories from the guy who manages PHP for Debian anyway<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt-get install ca-certificates apt-transport-https software-properties-common gnupg unzip curl\necho \"deb https:\/\/packages.sury.org\/php\/ $(lsb_release -sc) main\" | tee \/etc\/apt\/sources.list.d\/sury-php.list\nwget -qO - https:\/\/packages.sury.org\/php\/apt.gpg | apt-key add -\napt-get update<\/pre>\n\n\n\n<p>Now, to the actual installation of the environment<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">apt install php8.1-fpm nginx\napt install php8.1-{dev,common,xml,tokenizer,zip,mysql,curl,mbstring,mysql,opcache,gd,intl,xsl,bcmath,imap,soap,readline,sqlite3,gmp}\napt install redis-server\napt-get install php8.1-redis\napt install mariadb-server mariadb-client<\/pre>\n\n\n\n<p>Now you need to secure redis !<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Now remember to secure your mariaDB (MySQL) installation with the following command<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql_secure_installation<\/pre>\n\n\n\n<p>Next, we need composer, the PHP dependency manager, to get it execute the following<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">curl -sS https:\/\/getcomposer.org\/installer | php\nmv composer.phar \/usr\/local\/bin\/composer\nchmod +x \/usr\/local\/bin\/composer\ncomposer --version<\/pre>\n\n\n\n<p>The last line above should show you what version of composer you have just installed<\/p>\n\n\n\n<p>Now, remember to <strong>never run composer as root<\/strong>, but rather as a regular user, from this point on I am assuming you are running the terminal as a regular user.<\/p>\n\n\n\n<p>I understand that Debian puts the web root in \/var\/www\/html, but i usually like to create a separate directory called \/var\/vhosts and put all my web projects in it<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mkdir \/var\/vhosts<\/pre>\n\n\n\n<p>Now, we need to create a sample project for our learning and training experience<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cd \/var\/vhosts\ncomposer create-project laravel\/laravel laraveltestapp\nchmod -R 0777 \/var\/vhosts\/laravelapp\/storage<\/pre>\n\n\n\n<p>Next, We would need to setup nginx to serve this website (&#8220;Would like to&#8221; actually, because there are alternatives, but I&#8217;m keeping it simple), here is an almost standard template for nginx, modify the host name and project name to match your project and preferences.<\/p>\n\n\n\n<p>NGINX vhost config file (In my case \/etc\/nginx\/sites-available\/laraveltestapp)<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">server {\n    listen 80;\n    listen [::]:80;\n    server_name ltest.net www.ltest.net;\n    root \/var\/vhosts\/laraveltestapp\/public;\n\n    add_header X-Frame-Options \"SAMEORIGIN\";\n    add_header X-XSS-Protection \"1; mode=block\";\n    add_header X-Content-Type-Options \"nosniff\";\n\n    index index.html index.htm index.php;\n\n    charset utf-8;\n\n    location \/ {\n        try_files $uri $uri\/ \/index.php?$query_string;\n    }\n\n    location = \/favicon.ico { access_log off; log_not_found off; }\n    location = \/robots.txt  { access_log off; log_not_found off; }\n\n    error_page 404 \/index.php;\n\n    location ~ \\.php$ {\n        fastcgi_pass unix:\/var\/run\/php\/php8.1-fpm.sock;\n#\tfastcgi_pass unix:\/var\/run\/php-fpm.sock;\n        fastcgi_index index.php;\n        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;\n        include fastcgi_params;\n    }\n\n    location ~ \/\\.(?!well-known).* {\n        deny all;\n    }\n}<\/pre>\n\n\n\n<p>Surely for this to work, you will need to add the following two lines to the end of the \/etc\/hosts file<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">127.0.0.1 ltest.net<br>127.0.0.1 www.ltest.net<\/pre>\n\n\n\n<p>As soon as we have the file above, we need to create a symbolic link for it in the sites enabled directory<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cd \/etc\/nginx\/sites-enabled\nln -s \/etc\/nginx\/sites-available\/laraveltestapp<\/pre>\n\n\n\n<p>Suddenly, it works through nginx, you should see the welcome page (View) here<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.ridiculously-simple.com\/wp-content\/uploads\/2022\/06\/laravel_welcome.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"665\" src=\"https:\/\/www.ridiculously-simple.com\/wp-content\/uploads\/2022\/06\/laravel_welcome-1024x665.png\" alt=\"\" class=\"wp-image-1473\" srcset=\"https:\/\/www.voodoo.business\/blog\/wp-content\/uploads\/2022\/06\/laravel_welcome-1024x665.png 1024w, https:\/\/www.voodoo.business\/blog\/wp-content\/uploads\/2022\/06\/laravel_welcome-300x195.png 300w, https:\/\/www.voodoo.business\/blog\/wp-content\/uploads\/2022\/06\/laravel_welcome-768x499.png 768w, https:\/\/www.voodoo.business\/blog\/wp-content\/uploads\/2022\/06\/laravel_welcome-1536x998.png 1536w, https:\/\/www.voodoo.business\/blog\/wp-content\/uploads\/2022\/06\/laravel_welcome.png 1992w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>Now, to the development environment, how to <a href=\"\/2022\/06\/05\/laravel-development-under-linux-dev-tools\/\">setup your development environment<\/a> can be found here<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This part of the tutorial is a hands on setup to have Laravel working on nginx under Linux. this is not the only way to run Laravel, for all the options, see here NOTE: Most if not all of the popular development tools are available for Linux and Windows, so If this setup is for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[124,123],"tags":[],"class_list":["post-1455","post","type-post","status-publish","format-standard","hentry","category-laravel","category-php"],"_links":{"self":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts\/1455","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/comments?post=1455"}],"version-history":[{"count":30,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts\/1455\/revisions"}],"predecessor-version":[{"id":2257,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts\/1455\/revisions\/2257"}],"wp:attachment":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/media?parent=1455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/categories?post=1455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/tags?post=1455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}