Home How to install WordPress with LEMP stack on Debian 9
Post
Cancel

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 https://w3techs.com/technologies/overview/content_management/all on April 2018, WordPress is used by 30.8% of all the websites, that is a content management system market share of 59.9%. Prerequisites:

Step 1. Create a MySQL database and user

Login as root MySQL user:

1
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:

1
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.

1
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:

1
mysql> FLUSH PRIVILEGES;

Exit out of MySQL:

1
mysql> exit

 

Step 2: Adjust Nginx configuration

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

1
sudo nano /etc/nginx/sites-available/blog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
server {
listen 80;
server_name blog.reheda.pro;
return 301 https://$host$request_uri;
}

server {
listen 127.0.0.1:443 ssl;
include snippets/ssl-reheda.pro.conf;
include snippets/ssl-params.conf;

root /var/www/html/blog;

index index.php;

server_name blog.reheda.pro;

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:

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

Then create dir we specified in the config:

1
sudo mkdir /var/www/html/blog

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

1
sudo nginx -t

If everyting is ok:

1
sudo systemctl reload nginx

 

Step 3. Install WordPress

Download ans extract wordpress package:

1
wget -q -O - http://wordpress.org/latest.tar.gz | sudo tar -xvzf - --strip 1 -C /var/www/html/blog

Set the correct permissions:

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

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