How to install WordPress with LEMP stack on Debian 9

Usually, most blogs are using WordPress. In this article, we will step you through the installation process of WordPress on your site.

According to W3Techs on April 2018, WordPress is used by 30.8% of all the websites, that is a content management system market share of 59.9%.

- Debian 9
- a sudo non-root user
- Nginx with SSL
- MySQL server

Step 1. Create a MySQL database and user

Login as root MySQL user:

mysql -u root -p

You will be prompted for the password you set for the MySQL root account when you installed the software.

First, we can create a separate database that WordPress can control. You can call this whatever you would like, but we will be using wordpressdb in this guide to keep it simple:

mysql> CREATE DATABASE wordpressdb DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Now, we are going to create a separate MySQL user account that we will use exclusively to operate on our new database. Creating one-function databases and accounts is a good idea from a management and security standpoint. We will use the name wpuser in this guide.

mysql> GRANT ALL ON wordpressdb.* TO 'wpuser'@'localhost' IDENTIFIED BY 'password';

You now have a database and user account, each made specifically for WordPress. We need to flush the privileges so that the current instance of MySQL knows about the recent changes:


Exit out of MySQL:

mysql> exit


Step 2: Adjust Nginx configuration

Let's create our new server block with the following content:

sudo nano /etc/nginx/sites-available/blog

server {
listen 80;
return 301 https://$host$request_uri;

server { listen ssl; include snippets/; include snippets/ssl-params.conf;

root /var/www/html/blog;

index index.php;


location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { log_not_found off; access_log off; allow all; } location / { try_files $uri $uri/ /index.php?q=$uri&$args; }

location ~* \.(jpg|jpeg|gif|css|png|js|ico|html|woff2)$ { access_log off; expires 30d; }

location ~ /\.ht { deny all; }

location ~ \.php$ { fastcgi_index index.php; fastcgi_keep_conn on; include /etc/nginx/fastcgi_params; fastcgi_pass unix:/run/php/php7.1-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }


Save and exit.

Activate the server block by creating a symlink:

sudo ln -s /etc/nginx/sites-available/blog /etc/nginx/sites-enabled/blog

Then create dir we specified in the config:

sudo mkdir /var/www/html/blog

Now, we can check our configuration for syntax errors by typing:

sudo nginx -t

If everyting is ok:

sudo systemctl reload nginx


Step 3. Install WordPress

Download ans extract wordpress package:

wget -q -O - | sudo tar -xvzf - --strip 1 -C /var/www/html/blog

Set the correct permissions:

sudo chown www-data: -R /var/www/html/blog

Finally, run the WordPress installation script by accessing the URL in your web browser:, enter the details for the database we created earlier in this post and create your WordPress admin user.



  1. Reply
    Forever Embrase Skin Cream May 21, 2018 at 3:04 pm

    Some really interesting information, well written and broadly user pleasant.

  2. Reply
    link 188bet May 21, 2018 at 9:35 pm

    What’s up mates, its great article concerning educationand entirely explained, keep
    it up all the time.

  3. Reply
    link 188bet May 22, 2018 at 6:11 am

    Amazing! Its actually remarkable article, I have got much clear idea on the topic of
    from this article.

  4. Reply
    Alex October 4, 2018 at 9:25 pm

    Pretty nice post. I just stumbled upon your weblog and wanted to say that I
    have really enjoyed surfing around your blog posts. In any case I will be subscribing to
    your rss feed and I hope you write again very soon!

  5. Reply
    John Louren October 11, 2018 at 9:43 pm

    Thanks for the marvelous posting! I quite enjoyed reading it, you’re a great author. I will ensure that I bookmark your blog and will eventually come back in the future.
    I want to encourage you continue your great work, have a nice morning!

  6. Reply
    John April 30, 2019 at 2:42 pm

    Howdy! I’m at work browsing your blog from my new apple iphone!
    Just wanted to say I love reading through your blog and look forward to all your posts! Carry on the excellent work!

  7. Reply
    Rickey July 18, 2019 at 6:56 am

    Excellent post! We will be linking to this
    great post on our website. Keep up the great writing.

  8. Reply
    Andres October 14, 2019 at 2:51 am

    I am truly thankful to the holder of this web page who has shared this enormous post at here.

  9. Reply
    jung hateley February 21, 2020 at 4:53 am

    Appreciating the time and effort you put into your site and in depth information you present.
    It’s nice to come across a blog every once in a while that isn’t the same old
    rehashed material. Great read! I’ve bookmarked your site and I’m including your RSS
    feeds to my Google account.

Leave a reply