
{"id":5885,"date":"2019-09-18T13:14:56","date_gmt":"2019-09-18T11:14:56","guid":{"rendered":"https:\/\/contabo.com\/blog\/?p=5885"},"modified":"2021-12-22T10:59:42","modified_gmt":"2021-12-22T09:59:42","slug":"lemp-debian-nginx-certbot-mariadb-php","status":"publish","type":"post","link":"https:\/\/contabo.com\/blog\/lemp-debian-nginx-certbot-mariadb-php\/","title":{"rendered":"LEMP: Debian, NGINX + Certbot, MariaDB, PHP"},"content":{"rendered":"\n<p>This tutorial shows you how to prepare your Debian VPS for hosting your website.<br>We are not going to perform any fine-tuning or optimization on the default configuration files. So neither NGINX, MySQL or PHP (LEMP) will get any other than the necessary configuration changes in order to run a website properly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Install the Software <\/h3>\n\n\n\n<p>If you\u2019re not sure about your admin rights, always enter the command sudo -i at the beginning of every session:<\/p>\n\n\n\n<p><code><strong>sudo -i<\/strong><\/code><\/p>\n\n\n\n<p>This command will grant you the rights of a power user, so you don\u2019t have to write the command sudo at the beginning of every command line.<\/p>\n\n\n\n<p>NGINX, Certbot, PHP installation:<\/p>\n\n\n\n<p><code>:~# apt install nginx python3-certbot-nginx php-fpm php-mysql zip unzip pwgen<\/code><\/p>\n\n\n\n<p> MariaDB can be installed as follows: <\/p>\n\n\n\n<p><code>  :~# apt install mariadb-server <\/code><\/p>\n\n\n\n<p>Installing MariaDB by using the default-package repositories might not install the latest version of MariaDB. For the latest MariaDB version visit <a rel=\"noreferrer noopener nofollow\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/downloads.mariadb.org\/mariadb\/repositories\/\" target=\"_blank\">Official MariaDB Repo<\/a> and follow the instructions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Configure the Software<\/h3>\n\n\n\n<p>You should secure your MariaDB installation first:<\/p>\n\n\n\n<p><code>:~# mysql_secure_installation &amp;&amp; mysql_upgrade<br>:~# mysql<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> Welcome to the MariaDB monitor.  Commands end with ; or \\g.\n Your MariaDB connection id is 55\n Server version: 10.4.6-MariaDB-1:10.4.6+maria~buster mariadb.org binary distribution\n Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.\n Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement. <\/pre>\n\n\n\n<p>We will now run Certbot for our default vmXXXX.contaboserver.net hostname, you could also simply add any other website.<br><strong><br>Important:<\/strong> In case you want to secure multiple domains you can simply add them with another &#8220;-d&#8221; option behind the command, e.g.:<\/p>\n\n\n\n<p><code>:~# certbot --nginx -d  $(hostname) -d  vmXXXX.contaboserver.net  <\/code> <\/p>\n\n\n\n<p>Certbot will also create a default configuration for your website within \/etc\/nginx\/sites-enabled\/<br><br>Let&#8217;s configure PHP, so NGINX knows where to send PHP-Files for interpreting. Check where PHP-FPM listens to:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>:~# grep \"listen =\" \/etc\/php\/7.3\/fpm\/pool.d\/www.conf<br><\/code>listen = \/run\/php\/php7.3-fpm.sock<\/pre>\n\n\n\n<p>The pool configuration file got a lot of parameters which can be adjusted according to the hardware your server is running and the type of scripts hosted on your website.<br>Open \/etc\/nginx\/sites-enabled\/default and you will see a PHP section which is commented out, you could install multiple PHP-Versions, add a  server or VPS for PHP interpreting only and much more. <br>We will add the following lines to any &#8220;server {}&#8221; configuration we want PHP to be available on:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">location ~ .php$ {<br>                include snippets\/fastcgi-php.conf;<br>                fastcgi_pass unix:\/run\/php\/php7.3-fpm.sock;<br>                }<\/pre>\n\n\n\n<p>You also need to expand the &#8220;index&#8221; line with &#8220;index.php&#8221; :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> index index.php index.html index.htm; <\/pre>\n\n\n\n<p><code>:~# systemctl restart nginx<\/code><\/p>\n\n\n\n<p>We will now download and install phpMyAdmin and make it available.  On Debian 10 phpMyAdmin is not available via &#8220;apt install phpmyadmin&#8221; command, they are probably going to add the package once the Alpha got  stable. <br>For downloads visit <a href=\"https:\/\/www.phpmyadmin.net\/downloads\/\" rel=\"nofollow\">Official phpMyAdmin Website<\/a> . As we are using PHP 7.3 we need to download the Alpha Version, which is still in testing phase.<\/p>\n\n\n\n<p><code> :~# mkdir \/var\/www\/phpmyadmin<br> :~# cd \/var\/www\/phpmyadmin\/<br> :~# wget https:\/\/files.phpmyadmin.net\/phpMyAdmin\/5.0.0-alpha1\/phpMyAdmin-5.0.0-alpha1-all-languages.zip<br> &amp;&amp; unzip phpMyAdmin-5.0.0-alpha1-all-languages.zip<br> :~# mv phpMyAdmin-5.0.0-alpha1-all-languages\/* .<\/code><\/p>\n\n\n\n<p>Create a database user and import the database; run &#8220;pwgen&#8221; to generate random passwords.<\/p>\n\n\n\n<p><code> :~# mysql &lt;  sql\/create_tables.sql <\/code><br><code> :~# mysql <\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">CREATE USER 'phpmyadminuser'@'localhost'  IDENTIFIED BY 'USE ONLY SECURE PASSWORDS !!';\nGRANT SELECT, INSERT, UPDATE, DELETE ON phpmyadmin.* TO 'phpmyadminuser'@'localhost'<br>  IDENTIFIED BY 'USE ONLY SECURE PASSWORDS !!';\nFLUSH PRIVILEGES;<\/pre>\n\n\n\n<p>Let&#8217;s configure phpMyAdmin to use the database. Uncomment the following lines in config.inc.php:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/* User used to manipulate with storage *\/\n  $cfg['Servers'][$i]['controlhost'] = 'localhost';\n  $cfg['Servers'][$i]['controlport'] = '3306';\n  $cfg['Servers'][$i]['controluser'] = 'phpmyadminuser';<\/pre>\n\n\n\n<p><code> :~# cp -p config.sample.inc.php config.inc.php<br> :~# pwgen 32 1 #Copy the password for blowfish secret<br> :~# chown www-data: \/var\/www\/phpmyadmin -R<\/code><\/p>\n\n\n\n<p>Last but not least, configure the webserver to make the content available.<br>Add the following section to the domain you want to expose it on:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">    location \/phpmyadmin {\n           root \/var\/www\/phpmyadmin\/;\n           index index.php index.html index.htm;\n           location ~ ^\/phpmyadmin\/(.+\\.php)$ {\n                   try_files $uri =404;\n                   root \/var\/www\/phpmyadmin\/;\n                   fastcgi_pass unix:\/run\/php\/php7.3-fpm.sock;\n                   fastcgi_index index.php;\n                   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n           }\n           location ~* ^\/phpmyadmin\/(.+\\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {\n                   root \/var\/www\/phpmyadmin\/;\n           }\n    }<\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows you how to prepare your Debian VPS for hosting your website.We are not going to perform any fine-tuning or optimization on the default configuration files. So neither NGINX, MySQL or PHP (LEMP) will get any other than the necessary configuration changes in order to run a website properly. 1. Install the Software [&hellip;]<\/p>\n","protected":false},"author":17,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[18],"tags":[181,505,532,570,632,737,880,894],"ppma_author":[1493],"class_list":["post-5885","post","type-post","status-publish","format-standard","hentry","category-tutorials","tag-contabo","tag-lemp","tag-mariadb","tag-nginx","tag-php","tag-server-administration","tag-virtual-private-server","tag-vps"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Gianni-Donato","author_link":"https:\/\/contabo.com\/blog\/author\/gianni-donato\/"},"uagb_comment_info":0,"uagb_excerpt":"This tutorial shows you how to prepare your Debian VPS for hosting your website.We are not going to perform any fine-tuning or optimization on the default configuration files. So neither NGINX, MySQL or PHP (LEMP) will get any other than the necessary configuration changes in order to run a website properly. 1. Install the Software&hellip;","authors":[{"term_id":1493,"user_id":17,"is_guest":0,"slug":"gianni-donato","display_name":"Gianni-Donato","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/4457fc8553ead9a4e1e3d5b4a940590df9bad9d9132e58e40df3894b99bbe5d0?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/5885","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/comments?post=5885"}],"version-history":[{"count":0,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/5885\/revisions"}],"wp:attachment":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/media?parent=5885"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/categories?post=5885"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/tags?post=5885"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=5885"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}