Scroll to top
© 2018 All Rights Reserved.
Share

How to install WordPress using Nginx on Debian 10 (buster)


Dominik Sachsenhofer - 1. January 2020 - 0 comments

Prerequisites

  • A Debian 10 machine with root access or a user with sudo privileges.
  • A valid domain name that is set up and pointing to your machines IP address.

Step 1: Log in via SSH and Update Packages

Log in to your Debian 10 VPS with SSH as the root user:

ssh root@IPADDRESS -p PORT

Replace “root” with a user that has sudo privileges if necessary. Additionally, replace “IPADDRESS” and “PORT” with your server’s respective IP address and SSH port number. Next, let’s make sure that we’re on Debian 10. You can do that like this:

lsb_release -a

You should get this as the output:

Distributor ID: Debian
Description:    Debian GNU/Linux 10 (buster)
Release:        10
Codename:       buster

Then, run the following command to make sure that all installed packages on the server are updated to their latest available versions:

apt update && apt upgrade

Step 2: Install Nginx, PHP, and MariaDB

WordPress requires a web server on which it will serve its content. It is written in PHP and uses a MySQL/MariaDB database to store its information. We can install Nginx, MariaDB, PHP, and other PHP modules by running the following command:

apt-get install nginx mariadb-server mariadb-client php-cgi php-common php-fpm php-pear php-mbstring php-zip php-net-socket php-gd php-xml-util php-gettext php-mysql php-bcmath unzip wget git -y

Once all the packages are installed, open the php.ini file and tweak some settings:

nano /etc/php/7.3/fpm/php.ini

Make the following changes:

post_max_size = 64M
memory_limit = 256M
max_execution_time = 300
upload_max_filesize = 32M
date.timezone = Europe/Vienna

Save and close the file, then restart PHP-FPM service to apply the configuration changes:

systemctl restart php7.3-fpm

Note: You can change the above PHP settings as per your requirements.

Step 3: Configure a WordPress Database

Next, we will need to create a database and user for WordPress. WordPress will use this database to store its information, and the user to have access to the database.

First, log in to MariaDB shell with the following command:

mysql -u root -p

If the previous command does not work or you do not know your password (i.e. if you are using Google Cloud Compute Engine and ssh into your machine using browser) you can reset your password: mysqladmin -u root password NEWPASSWORD

Provide your root password when prompt then create a database and user with the following command:

MariaDB [(none)]> CREATE DATABASE wpdb;
MariaDB [(none)]> CREATE USER 'wpuser'@'localhost' identified by 'dbpassword';

Don’t forget to choose a strong password for your database user.

Now, you have a valid database and user for WordPress. Next, grant all the privileges to the WordPress database:

MariaDB [(none)]> GRANT ALL PRIVILEGES ON wpdb.* TO 'wpuser'@'localhost';

Next, flush the privileges to apply the changes we’ve made and exit from the MariaDB shell with the following command:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Once you have done, you can proceed to the next step.

Step 4: Install WordPress

First, we will need to download the latest version of the WordPress source form its official website. Run the following command to download the latest release of WordPress:

cd /var/www/html/
wget https://wordpress.org/latest.tar.gz

Once the download is completed, extract the downloaded file with the following command:

tar -xvzf latest.tar.gz

Next, change the directory to wordpress and copy the sample configuration file:

cd wordpress
cp wp-config-sample.php wp-config.php

Next, open the file wp-config.php with the nano editor:

nano wp-config.php

Change the database, database user and password which we have created earlier:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wpdb' );

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

/** MySQL database password */
define( 'DB_PASSWORD', 'dbpassword' );

/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

Save and close the file.

Then, change the ownership of the wordpress directory with the following command:

chown -R www-data:www-data /var/www/html/wordpress

Step 5: Configure Nginx for WordPress

Next, we will need to create a Virtual Host configuration file for WordPress. You can create a new Virtual Host configuration file with the following command:

nano /etc/nginx/sites-available/wordpress.conf

Add the following lines:

server {
	listen 80;
	root /var/www/html/wordpress;
	index index.php index.html index.htm;
	server_name example.com;

	access_log /var/log/nginx/wordpress_access.log;
	error_log /var/log/nginx/wordpress_error.log;

	client_max_body_size 64M;

	location / {
		try_files $uri $uri/ /index.php?$args;
	}

	location ~ \.php$ {
		include snippets/fastcgi-php.conf;                
		# With php-fpm (or other unix sockets):                
		fastcgi_pass unix:/run/php/php7.3-fpm.sock;
	}
}

Make sure to replace example.com with your registered domain name. Save and close the file.

Then enable the newly created virtual block with the following command:

ln -s /etc/nginx/sites-available/wordpress.conf /etc/nginx/sites-enabled/

Finally, restart the nginx and PHP-FPM services to apply the configuration changes:

systemctl restart nginx
systemctl restart php7.3-fpm

Step 6: Access the WordPress Site

Now, open your web browser and visit the URL http://example.com. You will be redirected to the WordPress installation page.

Post a Comment