{"id":41,"date":"2019-02-02T21:15:00","date_gmt":"2019-02-02T21:15:00","guid":{"rendered":"https:\/\/hostup.org\/blog\/?p=41"},"modified":"2021-05-02T22:49:30","modified_gmt":"2021-05-02T22:49:30","slug":"install-wordpress-on-latest-nginx-mainline-version","status":"publish","type":"post","link":"https:\/\/hostup.se\/en\/blog\/install-wordpress-on-latest-nginx-mainline-version\/","title":{"rendered":"How to Install WordPress on Latest Nginx Mainline Version on Ubuntu 16.04 \/ 18.04"},"content":{"rendered":"\n<p>If you do not already have Nginx installed, then please follow <a href=\"https:\/\/hostup.org\/blog\/how-to-install-configure-latest-nginx-mainline-version-on-ubuntu\/\" target=\"_blank\" rel=\"noopener\">this<\/a> tutorial.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Download &amp; Extract WordPress<\/h2>\n\n\n\n<p>First of all, we need to download and extract WordPress to your website HTML folder. (<strong>Default \/usr\/share\/nginx\/html<\/strong>).<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cd \/tmp<br><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"> curl -LO https:\/\/wordpress.org\/latest.tar.gz<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"> tar xzvf latest.tar.gz<\/pre>\n\n\n\n<p>IF you want your blog to be installed in a sub directory (<strong>example.com\/blog<\/strong>) then run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo cp -a wordpress \/usr\/share\/nginx\/html\/blog\/<\/pre>\n\n\n\n<p>IF you want your WordPress to be installed in your main directory instead (<strong>example.com<\/strong>) then run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo cp -a wordpress \/usr\/share\/nginx\/html\/<\/pre>\n\n\n\n<p>Now that we have downloaded WordPress and copied it over to our Nginx website directory we need to edit your website config, default.conf. You can edit it by running the following:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo nano \/etc\/nginx\/conf.d\/default.conf<\/pre>\n\n\n\n<p>IF you want your blog to be installed in a subdirectory like blog, <strong>example.com\/blog\/<\/strong> then put the following config in:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>server {\n    listen       80;\n    listen       &#091;::]:80;\n    server_name  localhost;\n\n        root   \/usr\/share\/nginx\/html;\n        index  index.php index.html index.htm;\n\n        location \/blog\/ {\n                try_files $uri $uri\/ \/blog\/index.php?$args;\n        }\n\n    location \/ {\n        try_files $uri $uri\/ \/index.php?$args;\n    }\n\n    error_page   500 502 503 504  \/50x.html;\n    location = \/50x.html {\n        root   \/usr\/share\/nginx\/html;\n    }\n\n    location ~ \\.php$ {\n        fastcgi_split_path_info ^(.+\\.php)(\/.+)$;\n        fastcgi_pass   unix:\/var\/run\/php\/php7.3-fpm.sock;\n        fastcgi_index  index.php;\n        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;\n        include        fastcgi_params;\n    }\n\n    if (!-e $request_filename) {\n    rewrite ^.*$ \/blog\/index.php last;\n    }\n}<\/code><\/pre>\n\n\n\n<p>You can change <strong>\/blog<\/strong> to whatever subdirectory you want.<\/p>\n\n\n\n<p>IF you want your WordPress to be installed at your main directory instead then simply <strong>remove blog\/<\/strong> so your configuration file will look like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>server {\n    listen       80;\n    listen       &#091;::]: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    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.3-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<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\">Install MariaDB<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt-get install mariadb-server mariadb-client<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo systemctl enable mysql.service<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo systemctl start mysql.service<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo mysql_secure_installation<\/pre>\n\n\n\n<p>You will now be prompted with a configuration setup file. Please read through it and configure it to your liking. It is recommended to disable logins that are not from localhost.<\/p>\n\n\n\n<p>After this you may create your database for wordpress. Login by:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo mysql -u root -p<\/pre>\n\n\n\n<p>Create your database. We will call it &#8216;blog&#8217; although you are free to call it whatever you want.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE DATABASE blog;\nFLUSH PRIVILEGES;\nEXIT;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configure wordpress configuration file<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo mv \/usr\/share\/nginx\/html\/blog\/wp-config-sample.php  <br>\/usr\/share\/nginx\/html\/blog\/wp-config.php<\/pre>\n\n\n\n<p>Now let&#8217;s open it!<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo nano \/usr\/share\/nginx\/html\/blog\/wp-config.php<\/pre>\n\n\n\n<p>Change your database name, username and password.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>define('DB_NAME', 'blog');\n\n\/** MySQL database username *\/\ndefine('DB_USER', 'root');\n\n\/** MySQL database password *\/\ndefine('DB_PASSWORD', '');<\/code><\/pre>\n\n\n\n<p>If you set any password to your MariaDB then please specify it in the correct field.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Install PHP 7.3<\/h2>\n\n\n\n<p>To install 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>To install the 2nd 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.3-fpm php7.3-common php7.3-mysql php7.3-gmp php7.3-curl php7.3-intl php7.3-mbstring php7.3-xmlrpc php7.3-gd php7.3-xml php7.3-cli php7.3-zip<\/pre>\n\n\n\n<p>It is recommended to raise the <strong>memory limit<\/strong> and disable <strong>cgi.fix_pathinfo<\/strong>. Your PHP configuration is located in<code><strong>\/etc\/php\/7.3\/cli\/php.ini<\/strong><\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo nano \/etc\/php\/7.3\/cli\/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>Press <bawt-key>CTRL<\/bawt-key> +  <bawt-key>W<\/bawt-key> and search for  ;cgi.fix_pathinfo=1<\/p>\n\n\n\n<p> Replace it with <strong>cgi.fix_pathinfo=0<\/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<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<h2 class=\"wp-block-heading\">That&#8217;s it!<\/h2>\n\n\n\n<p>Congratulations you have now installed &amp; configured WordPress for Nginx web-server. You can visit your website at <strong>http:\/\/yourdomain.tld<\/strong> and start the final configuration. If you want to add an SSL certificate so you can visit your website from &#8216;https:\/\/&#8217; and other security options then please do follow <a href=\"https:\/\/hostup.org\/blog\/how-to-secure-your-nginx-server\/\" target=\"_blank\" rel=\"noopener\">this<\/a> tutorial.<br><\/p>\n\n\n\n<p>If you don&#8217;t already have a VPS, or want to reward us for hard work and ad free experience you can buy a <a href=\"https:\/\/hostup.org\/vps\" target=\"_blank\" rel=\"noopener\">VPS<\/a> from us. We would really appreciate it as we don&#8217;t have any donation buttons and this is our only source of income. Our VPSes are located in Stockholm, and we even have a <a href=\"https:\/\/hostup.se\/vps\">Swedish branded site <\/a>if you&#8217;re from Sweden.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you do not already have Nginx installed, then please follow this tutorial. Download &amp; Extract WordPress First of all, we need to download and extract WordPress to your website HTML folder. (Default \/usr\/share\/nginx\/html). cd \/tmp curl -LO https:\/\/wordpress.org\/latest.tar.gz tar xzvf latest.tar.gz IF you want your blog to be installed in a sub directory (example.com\/blog) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":158,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-41","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/hostup.se\/en\/blog\/wp-json\/wp\/v2\/posts\/41","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=41"}],"version-history":[{"count":4,"href":"https:\/\/hostup.se\/en\/blog\/wp-json\/wp\/v2\/posts\/41\/revisions"}],"predecessor-version":[{"id":228,"href":"https:\/\/hostup.se\/en\/blog\/wp-json\/wp\/v2\/posts\/41\/revisions\/228"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hostup.se\/en\/blog\/wp-json\/wp\/v2\/media\/158"}],"wp:attachment":[{"href":"https:\/\/hostup.se\/en\/blog\/wp-json\/wp\/v2\/media?parent=41"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hostup.se\/en\/blog\/wp-json\/wp\/v2\/categories?post=41"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hostup.se\/en\/blog\/wp-json\/wp\/v2\/tags?post=41"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}