{"id":16099,"date":"2019-03-21T08:21:10","date_gmt":"2019-03-21T08:21:10","guid":{"rendered":"https:\/\/www.hostinger.com\/tutorials\/?p=16099"},"modified":"2025-04-28T08:09:42","modified_gmt":"2025-04-28T08:09:42","slug":"how-to-install-wordpress-with-nginx-on-ubuntu","status":"publish","type":"post","link":"\/in\/tutorials\/how-to-install-wordpress-with-nginx-on-ubuntu","title":{"rendered":"WordPress Nginx: Everything You Need to Know About Installing WordPress on Ubuntu"},"content":{"rendered":"<p>Nginx is an open-source web server that was first released in 2004 and is written completely in the <a href=\"https:\/\/en.wikipedia.org\/wiki\/C_(programming_language)\" target=\"_blank\" rel=\"noopener\">C programming language<\/a>. It has many benefits that you&rsquo;ll discover right here! In this tutorial, we&rsquo;ll show you how to install WordPress with Nginx!<\/p><p class=\"has-text-align-center\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/Mega-WordPress-Cheat-EN.pdf\" target=\"_blank\" rel=\"noopener\">Download all in one WordPress cheat sheet<\/a><\/p><h2 class=\"wp-block-heading\" id=\"h-why-use-nginx-with-wordpress\">Why Use Nginx With WordPress<\/h2><p><a href=\"\/in\/tutorials\/what-is-nginx\">Nginx<\/a> has gained immense popularity in the recent past and is commonly sought as an alternative to the Apache web server. <a href=\"\/in\/tutorials\/how-to-set-up-nginx-reverse-proxy\/\">Nginx supports reverse proxy<\/a>, caching, media streaming, load balancing, and much more. That makes it a great fit for a WordPress website powered by a <a href=\"\/in\/vps-hosting\">VPS solution<\/a>.<\/p><?xml encoding=\"utf-8\" ?><figure class=\"wp-block-image size-large\"><a href=\"\/in\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner-1024x300.png\" alt=\"\" class=\"wp-image-77934\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner.png 1024w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner-300x88.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner-150x44.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner-768x225.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><p>Few of Nginx&rsquo;s inbuilt features are:<\/p><ul class=\"wp-block-list\">\n<li>Nginx is built to work on low memory usage<\/li>\n\n\n\n<li>It can support extremely high concurrency<\/li>\n\n\n\n<li>Is Ipv6 enabled<\/li>\n\n\n\n<li>Supports reverse proxy with efficient caching<\/li>\n\n\n\n<li>Provides an inbuilt load balancer<\/li>\n\n\n\n<li>Supports WebSockets<\/li>\n\n\n\n<li>Optimized handling of index files, static files and provides auto indexing<\/li>\n\n\n\n<li>Is accompanied with FastCGI for efficient caching<\/li>\n<\/ul><p>Nginx does much more than a conventional web server, which is one of the reasons it has gained so much popularity. Nginx overshadows a lot of legacy web servers and consistently provides benchmarks surpassing their performance.<\/p><p>Nginx solves a lot of scalability issues and is taken as a solution to the commonly referred C10K problem related to concurrency.<\/p><p>And as you now know, Nginx and WordPress work really well together!<\/p><p>Here, we will walk you through the installation of WordPress using Nginx on the Linux platform.<\/p><p>Similar to LAMP, using Nginx is referred to as LEMP which stands for Linux, Nginx, MySQL\/MariaDB, and PHP.<\/p><h2 class=\"wp-block-heading\" id=\"h-prerequisites-for-installing-wordpress-with-nginx\">Prerequisites for Installing WordPress With Nginx<\/h2><ol class=\"wp-block-list\">\n<li>You are logged with sudo access<\/li>\n\n\n\n<li>Nginx is preinstalled<\/li>\n\n\n\n<li>You have an SSL certificate installed for your domain<\/li>\n\n\n\n<li>You own a <a href=\"\/in\/domain-name-search\">domain name<\/a> pointing to your server&rsquo;s public IP. In this example it&rsquo;ll be sample.com<\/li>\n<\/ol><h2 class=\"wp-block-heading\" id=\"h-how-to-install-wordpress-with-nginx\">How to Install WordPress with Nginx<\/h2><p>Let&rsquo;s walk through the entire process:<\/p><h3 class=\"wp-block-heading\" id=\"h-1-update-your-system\">1. Update Your System<\/h3><p>Update the package index using:<\/p><pre class=\"wp-block-preformatted\">sudo apt update<\/pre><p>Update system packages to the latest version using:<\/p><pre class=\"wp-block-preformatted\">sudo apt upgrade<\/pre><h3 class=\"wp-block-heading\" id=\"h-2-install-nginx\">2. Install Nginx<\/h3><p>Nginx packages are available in the default Ubuntu repository. You can use the below command to install them:<\/p><pre class=\"wp-block-preformatted\">sudo apt install nginx<\/pre><p>This will take a while to install. Once the installation is complete, the Nginx service will start automatically. To know the status of the service, use the below command:<\/p><pre class=\"wp-block-preformatted\">sudo systemctl status nginx<\/pre><h3 class=\"wp-block-heading\" id=\"h-3-configure-ufw-optional\">3. Configure UFW (Optional)<\/h3><p>If you are using <a href=\"\/in\/tutorials\/how-to-configure-firewall-on-ubuntu-using-ufw\/\">UFW<\/a> (Uncomplicated Firewall) to manage your VPS firewall then you will have to open ports 80 and 443 for HTTP and HTTPS respectively. You can enable the Nginx full profile which contains rules for both ports. This can be done using:<\/p><pre class=\"wp-block-preformatted\">sudo ufw allow 'Nginx Full'<\/pre><p>To verify the status, you can use:<\/p><pre class=\"wp-block-preformatted\">sudo ufw status<\/pre><h3 class=\"wp-block-heading\" id=\"h-4-install-and-configure-mysql-database\">4. Install and Configure MySQL Database<\/h3><p>To store data we will be using MySQL. In case you do not have MySQL installed, then you can get it by using:<\/p><pre class=\"wp-block-preformatted\">sudo apt install mysql-server<\/pre><p>Once this is complete, the MySQL Database will be started automatically. You can use the below command to check its status:<\/p><pre class=\"wp-block-preformatted\">sudo systemctl status mysql<\/pre><p>Next, you can log in to the MySQL shell by using:<\/p><pre class=\"wp-block-preformatted\">mysql -u root -p<\/pre><p>This will switch over to the MySQL console, which you can tell by the <code>mysql&gt;<\/code> at the start of the line. Here you can create a database and a database user with the names WordPress and WordPressUser respectively.<\/p><pre class=\"wp-block-preformatted\">CREATE DATABASE WordPress CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;<\/pre><pre class=\"wp-block-preformatted\">CREATE USER 'WordPressUser'@'localhost' IDENTIFIED BY 'your_password';<\/pre><pre class=\"wp-block-preformatted\">FLUSH PRIVILEGES;<\/pre><pre class=\"wp-block-preformatted\">EXIT;<\/pre><p>This creates a basic database configuration that can be used for the WordPress setup.<\/p><h3 class=\"wp-block-heading\" id=\"h-5-install-php\">5. Install PHP<\/h3><p>You can install all the required PHP extensions directly with a single command since these are the only ones that WordPress will use. This can be done using:<\/p><pre class=\"wp-block-preformatted\">sudo apt install php8.1-cli php8.1-fpm php8.1-mysql php8.1-opcache php8.1-mbstring php8.1-xml php8.1-gd php8.1-curl<\/pre><p>On completion of this installation, PHP-FPM will start automatically. This is a Fast CGI process manager which enables caching.<\/p><h3 class=\"wp-block-heading\" id=\"h-6-install-wordpress-with-nginx\">6. Install WordPress with Nginx<\/h3><p>To Install WordPress with Nginx, first create a directory to download the WordPress archive:<\/p><pre class=\"wp-block-preformatted\">sudo mkdir -p \/var\/www\/html\/sample.com<\/pre><p>From the official WordPress website, you can download the latest WordPress installs. Download it to the \/tmp directory. You can access said directory by using <strong>cd<\/strong>, and download the archive using <strong>wget<\/strong>:<\/p><pre class=\"wp-block-preformatted\">cd \/tmp<\/pre><pre class=\"wp-block-preformatted\">wget https:\/\/wordpress.org\/latest.tar.gz<\/pre><p>Next, you can extract this archive to the directory created earlier. This can be done using:<\/p><pre class=\"wp-block-preformatted\">tar xf latest.tar.gz<\/pre><pre class=\"wp-block-preformatted\">sudo mv \/tmp\/wordpress\/* \/var\/www\/html\/sample.com\/<\/pre><p>The web server will require complete access to these files. Change the permission by running the <a href=\"\/in\/tutorials\/linux-chown-command\/\">chown command<\/a>:<\/p><pre class=\"wp-block-preformatted\">sudo chown -R www-data: \/var\/www\/html\/sample.com<\/pre><p>Note that Nginx and PHP run as the <strong>www-data<\/strong> user and group, hence this is used in the above command.<\/p><h3 class=\"wp-block-heading\" id=\"h-7-configure-nginx-for-wordpress\">7. Configure Nginx for WordPress<\/h3><p>To configure Nginx for WordPress, we have to create a new server block for our WordPress installation. Navigate to <strong>\/etc\/nginx\/sites-available<\/strong>. There, create a file with the name <strong>sample.com<\/strong>. The name should be the same as your domain.<\/p><pre class=\"wp-block-preformatted\"># Redirect HTTP -&gt; HTTPS<br>server {<br>    listen 80;<br>    server_name www.sample.com sample.com;<br><br>    include snippets\/letsencrypt.conf;<br>    return 301 https:\/\/sample.com$request_uri;<br>}<br><br># Redirect WWW -&gt; NON-WWW<br>server {<br>    listen 443 ssl http2;<br>    server_name www.sample.com;<br><br>    ssl_certificate \/etc\/letsencrypt\/live\/sample.com\/fullchain.pem;<br>    ssl_certificate_key \/etc\/letsencrypt\/live\/sample.com\/privkey.pem;<br>    ssl_trusted_certificate \/etc\/letsencrypt\/live\/sample.com\/chain.pem;<br>    include snippets\/ssl.conf;<br><br>    return 301 https:\/\/sample.com$request_uri;<br>}<br><br>server {<br>    listen 443 ssl http2;<br>    server_name sample.com;<br><br>    root \/var\/www\/html\/sample.com;<br>    index index.php;<br><br>    # SSL parameters<br>    ssl_certificate \/etc\/letsencrypt\/live\/sample.com\/fullchain.pem;<br>    ssl_certificate_key \/etc\/letsencrypt\/live\/sample.com\/privkey.pem;<br>    ssl_trusted_certificate \/etc\/letsencrypt\/live\/sample.com\/chain.pem;<br>    include snippets\/ssl.conf;<br>    include snippets\/letsencrypt.conf;<br><br>    # Log files<br>    access_log \/var\/log\/nginx\/sample.com.access.log;<br>    error_log \/var\/log\/nginx\/sample.com.error.log;<br><br>    location = \/favicon.ico {<br>        log_not_found off;<br>        access_log off;<br>    }<br><br>    location = \/robots.txt {<br>        allow all;<br>        log_not_found off;<br>        access_log off;<br>    }<br><br>    location \/ {<br>        try_files $uri $uri\/ \/index.php?$args;<br>    }<br><br>    location ~ \\.php$ {<br>        include snippets\/fastcgi-php.conf;<br>        fastcgi_pass unix:\/run\/php\/php8.1-fpm.sock;<br>    }<br><br>    location ~* \\.(js|css|png|jpg|jpeg|gif|ico|svg)$ {<br>        expires max;<br>        log_not_found off;<br>    }<br>}<\/pre><p>Make sure to use the correct domain name. For easier management, <a href=\"\/in\/tutorials\/how-to-create-symbolic-links-in-linux\">create a symbolic link<\/a> to the <strong>sites-enabled<\/strong> directory.<\/p><pre class=\"wp-block-preformatted\">sudo ln -s \/etc\/nginx\/sites-available\/sample.com \/etc\/nginx\/sites-enabled\/<\/pre><p>You can validate the Nginx configuration by using:<\/p><pre class=\"wp-block-preformatted\">sudo nginx -t<\/pre><p>Alternatively, use <strong>Kodee<\/strong>, <a href=\"\/in\/vps-hosting\">Hostinger VPS&rsquo;<\/a> AI assistant, to verify your NGINX configuration and check for errors:<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e08f4483856\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/09\/hpanel-vps-kodee-1024x339.png\" alt=\"Kodee responds to a question about NGINX configuration\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>If this has no errors then you will see a message showing <strong>syntax is ok<\/strong>. You can ignore the rest of the message.<\/p><p>Next, you can restart Nginx by using:<\/p><pre class=\"wp-block-preformatted\">sudo systemctl restart nginx<\/pre><p>At this stage you have PHP, MySQL and Nginx configured and started. Next, configure and verify the WordPress installation.<\/p><h3 class=\"wp-block-heading\" id=\"h-8-configuring-wordpress-for-nginx\">8. Configuring WordPress for Nginx<\/h3><p>Nearly done! The last step is configuring your very own WordPress!<\/p><p>Open your browser and type the domain name as you would <strong>http:\/\/sample.com<\/strong>. Replace this with your domain!<\/p><p>You will be able to see a screen showing language selection. Pick your preferred option.<\/p><p>You will see an instruction page that you can read and proceed to the next page. On the next screen, you can configure your Database details.<\/p><p>Provide your database name along with the username and password. In our case, this will be WordPress for the database name and WordPressUser for Username.<\/p><p>You can start the installation by clicking the button.<\/p><p>In the next page, you can provide additional details. At this step, you will set the username for WordPress.<\/p><p>For security, you should change the username from admin to something else. Click on the Install WordPress button. This will redirect you to the login page where you can type in your newly configured WordPress username and password.<\/p><p>Once logged in, you will be able to see the WordPress dashboard.<\/p><p>From here you can configure your WordPress, set new themes, add plugins and more.<\/p><p>\n\n\n<div class=\"protip\">\n                    <h4 class=\"title\">Sugested Reading<\/h4>\n                    <p>Discover our guide to learn<a href=\"\/in\/tutorials\/how-to-install-wordpress-on-ubuntu-using-lamp-stack\/\"> how to install WordPress on Ubuntu using LAMP Stack<\/a>.<\/p>\n                <\/div>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>Through this tutorial, we have learned <a href=\"\/in\/tutorials\/how-to-install-wordpress\">how you can install WordPress<\/a> using Nginx on Ubuntu. Bingo, you just configured a full setup of the most popular CMS. Go ahead and have fun exploring the power of WordPress with the additional features of a powerful virtual private server.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nginx is an open-source web server that was first released in 2004 and is written completely in the C programming language. It has many benefits that you&rsquo;ll discover right here! In this tutorial, we&rsquo;ll show you how to install WordPress with Nginx! Why Use Nginx With WordPress Nginx has gained immense popularity in the recent [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/in\/tutorials\/how-to-install-wordpress-with-nginx-on-ubuntu\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":110,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"","rank_math_description":"","rank_math_focus_keyword":"","footnotes":""},"categories":[22642,22640],"tags":[],"class_list":["post-16099","post","type-post","status-publish","format-standard","hentry","category-pre-installed-applications","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/how-to-install-wordpress-with-nginx-on-ubuntu","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/instalar-wordpress-con-nginx-en-ubuntu","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/cara-install-wordpress-di-ubuntu","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/how-to-install-wordpress-with-nginx-on-ubuntu","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/how-to-install-wordpress-with-nginx-on-ubuntu\/","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/how-to-install-wordpress-with-nginx-on-ubuntu\/","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/instalar-wordpress-con-nginx-en-ubuntu","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/instalar-wordpress-con-nginx-en-ubuntu","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/instalar-wordpress-con-nginx-en-ubuntu","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/how-to-install-wordpress-with-nginx-on-ubuntu","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/how-to-install-wordpress-with-nginx-on-ubuntu","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/how-to-install-wordpress-with-nginx-on-ubuntu","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/how-to-install-wordpress-with-nginx-on-ubuntu","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts\/16099","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/comments?post=16099"}],"version-history":[{"count":17,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts\/16099\/revisions"}],"predecessor-version":[{"id":124501,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts\/16099\/revisions\/124501"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/media?parent=16099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/categories?post=16099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/tags?post=16099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}