{"id":125,"date":"2020-05-22T10:12:00","date_gmt":"2020-05-22T10:12:00","guid":{"rendered":"https:\/\/hostup.org\/blog\/?p=125"},"modified":"2021-05-02T22:40:08","modified_gmt":"2021-05-02T22:40:08","slug":"how-to-install-nginx-and-php-7-4-on-debian-10","status":"publish","type":"post","link":"https:\/\/hostup.se\/en\/blog\/how-to-install-nginx-and-php-7-4-on-debian-10\/","title":{"rendered":"How to Install Nginx and PHP 7.4 on Debian 10"},"content":{"rendered":"\n<p>So PHP 7.4 has now been released for quite a while for <a href=\"https:\/\/wiki.debian.org\/DebianBuster\" target=\"_blank\" rel=\"noopener\">Debian 10 buster.<\/a> 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 7.4.<\/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 7.4<\/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 php7.4-fpm php7.4-common php7.4-mysql php7.4-gmp php7.4-curl php7.4-intl php7.4-mbstring php7.4-xmlrpc php7.4-gd php7.4-xml php7.4-cli php7.4-zip php7.4-soap php7.4-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\/7.4\/fpm\/php.ini<\/strong><\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo nano \/etc\/php\/7.4\/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>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>Replace your existing configuration file with the one below<\/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\/php7.4-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\n\n\n<p>Don&#8217;t forget to try out <a href=\"https:\/\/hostup.org\/vps\" target=\"_blank\" rel=\"noopener\">our VPS<\/a> too! Our servers are located in stockholm, so if you&#8217;re from Sweden feel free to check out our Swedish site too, and grab yourself a <a href=\"https:\/\/hostup.org\/vps\" target=\"_blank\" rel=\"noopener\">Stockholm VPS<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So PHP 7.4 has now been released for quite a while for Debian 10 buster. 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 7.4. Step 1: Install Nginx Firstly we need to install the prerequisites. sudo [&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-125","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\/125","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=125"}],"version-history":[{"count":6,"href":"https:\/\/hostup.se\/en\/blog\/wp-json\/wp\/v2\/posts\/125\/revisions"}],"predecessor-version":[{"id":219,"href":"https:\/\/hostup.se\/en\/blog\/wp-json\/wp\/v2\/posts\/125\/revisions\/219"}],"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=125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hostup.se\/en\/blog\/wp-json\/wp\/v2\/categories?post=125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hostup.se\/en\/blog\/wp-json\/wp\/v2\/tags?post=125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}