{"id":175,"date":"2021-01-28T06:16:10","date_gmt":"2021-01-28T06:16:10","guid":{"rendered":"https:\/\/hostup.org\/blog\/?p=175"},"modified":"2021-10-30T08:25:40","modified_gmt":"2021-10-30T08:25:40","slug":"how-to-install-nginx-and-php-8-on-debian-10","status":"publish","type":"post","link":"https:\/\/hostup.se\/en\/blog\/how-to-install-nginx-and-php-8-on-debian-10\/","title":{"rendered":"How to Install Nginx and PHP 8 on Debian 10"},"content":{"rendered":"\n<p>PHP 8 is the <a href=\"https:\/\/www.php.net\/releases\/8.0\/en.php\" target=\"_blank\" rel=\"noopener\">latest<\/a> PHP version released. This tutorial will show you how you can install Nginx mainline version on Debian 10 for optimal performance as well as the newest version of PHP, currently 8.0.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Install Nginx<\/h2>\n\n\n\n<p>Firstly we need to install the prerequisites. <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt install curl gnupg2 ca-certificates lsb-release<\/pre>\n\n\n\n<p>Then we need to add the Nginx mainline package to our repository so that when we run apt install nginx, we will download the mainline version instead of the old stable version.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">echo \"deb http:\/\/nginx.org\/packages\/mainline\/debian `lsb_release -cs` nginx\" \\\n    | sudo tee \/etc\/apt\/sources.list.d\/nginx.list<\/pre>\n\n\n\n<p><strong>Optionally<\/strong>, if you would rather want to use the older and slower stable version of Nginx you can do so by running: (Remember that you should only run one of the following)<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">echo \"deb http:\/\/nginx.org\/packages\/mainline\/debian `lsb_release -cs` nginx\" \\\n    | sudo tee \/etc\/apt\/sources.list.d\/nginx.list<\/pre>\n\n\n\n<p>Next we need to download the signing key so that we can verify its authenticity<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">curl -fsSL https:\/\/nginx.org\/keys\/nginx_signing.key | sudo apt-key add -<\/pre>\n\n\n\n<p>If it prints out <strong>OK!<\/strong> then you are good to go!<\/p>\n\n\n\n<p>Now that we have downloaded &amp; verified its authnicity lets install it!<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt update<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt install nginx<\/pre>\n\n\n\n<p>That\u2019s it! You have now installed the latest release of Nginx on Debian 10. You should now start it!<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo systemctl start nginx.service<\/pre>\n\n\n\n<p>Don&#8217;t forget to make it automaticly start on system boot as well.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo systemctl enable nginx.service<\/pre>\n\n\n\n<p>Visit your server&#8217;s IP address in your webbrowser. You should now see something along these lines if it is working correctly.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"580\" height=\"262\" src=\"https:\/\/hostup.org\/blog\/wp-content\/uploads\/2021\/01\/image-29.png\" alt=\"welcome to nginx, default index.html\" class=\"wp-image-99\" srcset=\"https:\/\/hostup.se\/en\/blog\/wp-content\/uploads\/2021\/01\/image-29.png 580w, https:\/\/hostup.se\/en\/blog\/wp-content\/uploads\/2021\/01\/image-29-300x136.png 300w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><figcaption>Default welcome screen on Nginx<\/figcaption><\/figure><\/div>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-4376591297601343\" data-ad-slot=\"5387153895\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Install PHP 8<\/h2>\n\n\n\n<p>To add the repositories for PHP:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt-get install software-properties-common<\/pre>\n\n\n\n<p>Since PHP 7.4 didn&#8217;t come with Debian 10 it is required to add the following repository<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo add-apt-repository ppa:ondrej\/php<\/pre>\n\n\n\n<p>Run this to download your added repositories:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt update<\/pre>\n\n\n\n<p>We can now install PHP now that we have all of the required repositories.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt install php8.0-fpm php8.0-common php8.0-mysql php8.0-gmp php8.0-curl php8.0-intl php8.0-mbstring php8.0-xmlrpc php8.0-gd php8.0-xml php8.0-cli php8.0-zip php8.0-soap php8.0-imap<\/pre>\n\n\n\n<p>It is recommended to raise the <strong>memory limit<\/strong> to improve the overall performance. Your PHP configuration is located in<code><strong>\/etc\/php\/8.9\/fpm\/php.ini<\/strong><\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo nano \/etc\/php\/8.0\/fpm\/php.ini<\/pre>\n\n\n\n<p>Press <bawt-key>CTRL<\/bawt-key> +  <bawt-key>W<\/bawt-key> and search for <strong>memory_limit.<\/strong><\/p>\n\n\n\n<p>Replace it with <strong>memory_limit = 256<\/strong><\/p>\n\n\n\n<p>Save &amp; exit by pressing <bawt-key>CTRL<\/bawt-key> +  <bawt-key>X<\/bawt-key> followed by <bawt-key>Y<\/bawt-key><\/p>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-4376591297601343\" data-ad-slot=\"5387153895\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Configure Nginx<\/h2>\n\n\n\n<p>Add nginx to www-data group<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo usermod -a -G www-data nginx<\/pre>\n\n\n\n<p>Change owner of directory to www-data<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo chown -R www-data \/usr\/share\/nginx\/html<\/pre>\n\n\n\n<p>Next up we need to replace our existing default.conf file for Nginx. To do this easily run the following commands:<\/p>\n\n\n\n<pre id=\"block-c6baca7d-e871-4678-9da4-9d1c361cf604\" class=\"wp-block-preformatted\">sudo rm \/etc\/nginx\/conf.d\/default.conf\nsudo touch \/etc\/nginx\/conf.d\/default.conf<\/pre>\n\n\n\n<p>Go into your <strong>default.conf<\/strong> file<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo nano \/etc\/nginx\/conf.d\/default.conf<\/pre>\n\n\n\n<p>Paste the following in the configuration file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>server {\n    listen       80;\n    server_name  localhost;\n\n    root   \/usr\/share\/nginx\/html;\n    index  index.php index.html index.htm;\n\n   location \/ {\n    if ($request_uri ~ ^\/(.*)\\.html$) {\n        return 302 \/$1;\n        }\n    }\n\n    error_page   500 502 503 504  \/50x.html;\n    location = \/50x.html {\n        root   \/usr\/share\/nginx\/html;\n    }\n        location ~ \\.php$ {\n        fastcgi_split_path_info ^(.+\\.php)(\/.+)$;\n        fastcgi_pass   unix:\/var\/run\/php\/php8.0-fpm.sock;\n        fastcgi_index  index.php;\n        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;\n        include        fastcgi_params;\n    }\n\n}<\/code><\/pre>\n\n\n\n<p>Save &amp; exit by pressing <bawt-key>CTRL<\/bawt-key> +  <bawt-key>X<\/bawt-key> followed by <bawt-key>Y<\/bawt-key><\/p>\n\n\n\n<p>Now restart your Nginx:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> service nginx restart<\/pre>\n\n\n\n<p>That&#8217;s it! However, you may now test to see if php works<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">nano \/usr\/share\/nginx\/html\/phpinfo.php<\/pre>\n\n\n\n<p>Add the following lines<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\nphpinfo();\n\n?&gt;<\/code><\/pre>\n\n\n\n<p>Save &amp; exit by pressing <bawt-key>CTRL<\/bawt-key> +  <bawt-key>X<\/bawt-key> followed by <bawt-key>Y<\/bawt-key><\/p>\n\n\n\n<p>Now go to <strong>YOURSERVERIP\/phpinfo.php<\/strong> in your web browser. You should see something along these lines<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"936\" height=\"901\" src=\"https:\/\/hostup.org\/blog\/wp-content\/uploads\/2021\/01\/image-2-1.png\" alt=\"\" class=\"wp-image-85\" srcset=\"https:\/\/hostup.se\/en\/blog\/wp-content\/uploads\/2021\/01\/image-2-1.png 936w, https:\/\/hostup.se\/en\/blog\/wp-content\/uploads\/2021\/01\/image-2-1-300x289.png 300w, https:\/\/hostup.se\/en\/blog\/wp-content\/uploads\/2021\/01\/image-2-1-768x739.png 768w\" sizes=\"auto, (max-width: 936px) 100vw, 936px\" \/><figcaption>phpinfo example page that shows that PHP is installed<\/figcaption><\/figure>\n\n\n\n<p>That&#8217;s it! Now you know how to install Nginx and PHP 7.4 on Debian 10.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP 8 is the latest PHP version released. This tutorial will show you how you can install Nginx mainline version on Debian 10 for optimal performance as well as the newest version of PHP, currently 8.0. Step 1: Install Nginx Firstly we need to install the prerequisites. sudo apt install curl gnupg2 ca-certificates lsb-release Then [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":137,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,10],"tags":[],"class_list":["post-175","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-tutorials"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/hostup.se\/en\/blog\/wp-json\/wp\/v2\/posts\/175","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hostup.se\/en\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hostup.se\/en\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hostup.se\/en\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hostup.se\/en\/blog\/wp-json\/wp\/v2\/comments?post=175"}],"version-history":[{"count":4,"href":"https:\/\/hostup.se\/en\/blog\/wp-json\/wp\/v2\/posts\/175\/revisions"}],"predecessor-version":[{"id":191,"href":"https:\/\/hostup.se\/en\/blog\/wp-json\/wp\/v2\/posts\/175\/revisions\/191"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hostup.se\/en\/blog\/wp-json\/wp\/v2\/media\/137"}],"wp:attachment":[{"href":"https:\/\/hostup.se\/en\/blog\/wp-json\/wp\/v2\/media?parent=175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hostup.se\/en\/blog\/wp-json\/wp\/v2\/categories?post=175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hostup.se\/en\/blog\/wp-json\/wp\/v2\/tags?post=175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}