WordPress is a popular content management system (CMS) that is often used to create websites and blogs. In this article, we will guide you through the process of installing WordPress on a LEMP (Linux, Nginx, MySQL, PHP) stack with Ubuntu or Debian.
Before we begin, make sure that you have a fresh installation of Ubuntu or Debian and that you have followed the steps in our previous article on how to install LEMP on Ubuntu or Debian. You will also need to be logged in as a user with sudo
privileges.
Download WordPress
First, we need to download the latest version of WordPress from the official website. To do this, open a terminal and run the following commands:
cd /tmp
curl -O <https://wordpress.org/latest.tar.gz>
This will download the WordPress archive to the /tmp
directory.
Extract WordPress
Next, we need to extract the files from the WordPress archive. To do this, run the following commands:
tar xzvf latest.tar.gz
This will extract the WordPress files into a directory called "wordpress"
in the /tmp
directory.
Copy WordPress files
Now we need to copy the WordPress files to the Nginx web root directory. By default, this directory is /var/www/html. To copy the files, run the following commands:
sudo cp -a /tmp/wordpress/. /var/www/html
Create a MySQL database for WordPress
Before we can install WordPress, we need to create a MySQL database for it to use. To do this, log in to the MySQL shell using the following command:
sudo mysql -u root -p
When prompted, enter the password for the MySQL root
user.
Once you are logged in to the MySQL shell, run the following commands to create a database for WordPress:
CREATE DATABASE wordpress;
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
EXIT;
Make sure to replace "password"
with a strong password of your own. Remember this password, as you will need it later.
Configure WordPress
Next, we need to configure WordPress to use the MySQL database that we just created. To do this, we need to edit the WordPress configuration file. Open the file using the following command:
sudo nano /var/www/html/wp-config.php
In the file, find the section that says “MySQL settings” and replace it with the following code:
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');
/** MySQL database username */
define('DB_USER', 'wordpressuser');
/** MySQL database password */
define('DB_PASSWORD', 'password');
/** MySQL hostname */
define('DB_HOST', 'localhost');
Make sure to replace “password” with the password that you chose earlier. Save the file and exit the editor.
Install WordPress
Now we are ready to install WordPress. To do this, visit http://localhost
in your web browser and follow the on-screen instructions.