Configure a WordPress website on LEMP

WordPress is a content management system, that makes it very easy to set up flexible blogs and websites. Clear installation directives are given as a DigitalOcean tutorial.


Start with:

  1. a secure php-driven website
  2. a new database with a user with full privileges
Topics on this page

Copy the files

Install WordPress in the root folder of your websites, by copying the files from the repository you created during the basic configuration of your Ubuntu webserver.

$ sudo cp -a /var/www/wordpress/. /home/webdomain/public_html
$ sudo chown -R www-data:www-data /var/www/wordpress

WordPress on NGINX

For WordPress to run properly on NGINX, you need to make some slight modifications to the server-block.

server {
        listen 80;
        root /home/testuser/public_html;
        index index.html index.php;

	location / {
#		try_files $uri $uri/ =404;
		try_files $uri $uri/ /index.php$is_args$args;

	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        location  = /favicon.ico { log_not_found off; access_log off; }
        location  = /robots.txt { log_not_found off; access_log off; allow all; }
	location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
		expires max;
		log_not_found off;

        location ~ /\.ht {
                deny all;

Since the symbolic link in the sites-enabled directory was already created druing the preparatory NGINX configuration, you can now test the configuration and reload the nginx configuration file.

$ sudo nginx -t
$ sudo systemctl reload nginx

Adjust wp-config and start WordPress

During the basic configuration of a Ubuntu webserver you created a sample wp-config.php file. You need to make three adjustments to this file in the root directory of your new WordPress installation.

1) Provide a set of secrete keys

A set of key-values can be generated at As these values are only used internally, it is not a problem to have complex values. The following command will produce a unige set of keys, that can be copy-pasted in the config-file.

$ curl -s

Replace the following block in the wp-config.php file, around line 49, with the output of the previous command.

define('AUTH_KEY',         'put your unique phrase here');
define('SECURE_AUTH_KEY',  'put your unique phrase here');
define('LOGGED_IN_KEY',    'put your unique phrase here');
define('NONCE_KEY',        'put your unique phrase here');
define('AUTH_SALT',        'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT',   'put your unique phrase here');
define('NONCE_SALT',       'put your unique phrase here');
2) Provide database credentials
/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');

/** MySQL database username */
define('DB_USER', 'username_here');

/** MySQL database password */
define('DB_PASSWORD', 'password_here');
3) Set the FS_METHOD

The final change you need to make is to set the method that WordPress should use to write to the filesystem. Since we’ve granted the server full privileges to write where it needs to, we can explicitly set the filesystem method to “direct”. Failure to set this would result in WordPress prompting for FTP credentials when we perform some actions. This setting can be added below the database connection settings, or anywhere else in the file.

define('FS_METHOD', 'direct');
Completing the Installation Through the Web Interface

You can now start your new WordPress installation for the first time and complete the initial configuration, by setting the language and providing a username and password.

That’s it.