Install WordPress with LEMP on Ubuntu 20.04

WordPress is a popular CMS that lets users create flexible blogs and websites with a MySQL backend and PHP processing. It is known for its efficiency and is an excellent option for creating a website quickly.

There are over 1.98 billion websites, with more than 835 million of them using WordPress.

Keywords: LEMP, Ubuntu, Ubuntu 20.04, WordPress.

Prerequisites

To follow this guide, ensure you can access an Ubuntu 20.04 server.

  • Create a sudo user on your server: Follow this article: Initial Server Setup With Ubuntu 20.04 to establish a non-root user with sudo privileges, as this tutorial will require a non-root user.
  • Install LEMP: tutorial.
  • Secure site with SSL: WordPress handles dynamic content, including user authentication and authorization. TLS/SSL technology ensures your site’s traffic is encrypted for a secure connection.

Step 1: Create a MYSQL Database and WordPress user

WordPress uses MySQL for the management and storage of site and user information.

$ sudo MySQL

If you have modified the authentication method to utilize a password for the MySQL root account, employ the following command instead:

$ mysql -u root -p

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

Next, create a separate MySQL user account to perform only operations on the newly created database. We will use the name “WordPress user” for this guide so that you can change it at your convenience.

You will create an account, enter a password, and authorize access to the database established with this command. Make sure you choose a strong and secure password in this step.

mysql> CREATE USER ‘wordpressuser’@’localhost’ IDENTIFIED BY ‘password’;

mySQL> 

mysql> GRANT ALL ON wordpress.* TO ‘wordpressuser’@’localhost’;

You have a database and user account specifically designed for the WordPress site.

Now that the database-related tasks are finished exit MySQL by entering the following –
mysql> exit;

Step 2: Install additional PHP extensions

Small extensions were required to enable communication between PHP and MySQL when setting up the LEMP stack.

By typing, you can download & install some of the most famous PHP extensions for use with WordPress:

$ sudo apt update

$ sudo apt install php-curl php-gd php-intl php-mbstring php-soap php-xml php-xmlrpc php-zip

$ sudo systemctl restart php8.1-fpm

All the necessary PHP extensions have now been successfully installed on the server.

Step 3: Configuring Nginx

Next, let us make some changes to the Nginx server block files.

Based on the prerequisite, ensure you possess a configuration file for your site in the /etc/nginx/sites-available/ directory. This file should be Configure this file to respond to your server’s domain name or IP address, ensuring a TLS/SSL certificate protects it.

We will illustrate using /etc/nginx/sites-available/wordpress as an example, but please replace this path with the appropriate location of your configuration file.

$ sudo vi /etc/nginx/sites-available/wordpress

Inside the primary server block, let us include several location blocks.
You can start by creating a matching location block for the requests to www.favicon.ico and www.robots.txt, which you don’t want to log in to.

try_files list. Comment on the default setting by adding a pound sign index.php file and the request arguments.

This should look like this –

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


Once you have completed the modifications, save and close the file.
Now, verify the syntax of your configuration for any errors by entering:
$ sudo nginx -t

If there are no reported errors, proceed to reload Nginx by entering –

$ sudo systemctl reload nginx

Step 4: Downloading WordPress

Let’s download and install WordPress with the server software set up. For security reasons, it is recommended that you use the new version of WordPress on your project’s Web site.

Move to a writable directory and download the compressed release by entering –
$ cd /tmp

$ curl -LO https://wordpress.org/latest.tar.gz

Extract the compressed file to generate the WordPress directory structure –

$ tar xzvf latest.tar.gz

Let’s copy the sample configuration file to the filename WordPress reads:

$ cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php

The `-a’ flag ensures permissions are maintained during the copy process. The dot at the end of the source directory specifies that everything within the directory, including hidden files, should be copied.

$ sudo cp -a /tmp/wordpress/. /var/www/your_domain/wordpress

Now that we have placed our files, we must assign ownership to the www-data user and group. Nginx runs as this user and group, and it needs to be able to read and write WordPress files to serve the website and perform automatic updates.

$ sudo chown -R www-data:www-data /var/www/your_domain/wordpress

Step 5: Set up the WordPress configuration file

Now, let us implement some modifications to the main WordPress configuration file.

To obtain secure values from the WordPress secret key generator, input the following command –
$ curl -s https://api.wordpress.org/secret-key/1.1/salt/

Caution: It is crucial to request unique values each time. Do NOT copy the values displayed below!

Now, proceed to open the WordPress configuration file –
$ sudo vi /var/www/your_domain/wordpress/wp-config.php

Locate the section containing dummy values for those settings. It will resemble something similar to this –

Remove those lines and insert the values you copied from the command line –

Now, let’s change some of the database connection settings at the beginning of the file. Change the database name, the database user, and the corresponding password configured in MySQL.

Another adjustment you need to make is configuring WordPress’s method for writing to the filesystem. As you’ve already granted the necessary permissions to the web server, explicitly set the filesystem method to “direct.” We must do this with our current configurations to avoid WordPress asking for FTP credentials during specific actions. Include this setting below the database connection settings or in any other file section.

. . .

define( ‘DB_NAME’, ‘wordpress’ );

/** MySQL database username */
define( ‘DB_USER’, ‘wordpressuser’ );

/** MySQL database password */
define( ‘DB_PASSWORD’, ‘password’ );

. . .

define( ‘FS_METHOD’, ‘direct’ );

Save and close the file after editing.

Step 6: Complete the Installation by using the Web Interface

With the server configuration now complete, you can finalize the installation through WordPress’ web interface.

Using your web browser, go to your server’s domain name or public IP address:

http://server_domain_or_ip_address

Choose the language you would like to use:

Next, you will be redirected to the main setup page.

Choose a name for your WordPress site and select a username (avoid using common choices like “admin” for security reasons). A strong password will be generated automatically; save this password or opt for another strong alternative.

Input your email address and choose whether you wish to Discourage search engines from indexing your site.

Click the Install WordPress button to redirect you to the login page.

After logging in, the system will redirect you to the WordPress administration dashboard.

The installation process is complete, and WordPress is now ready for use!

Conclusion

In conclusion, setting up WordPress with LEMP on Ubuntu 20.04 involves several steps, including installing and configuring the LEMP stack, creating a MySQL database and user, downloading and configuring WordPress, and adjusting file permissions. Following these steps carefully ensures a successful installation, enabling you to enjoy the benefits of running WordPress on your Ubuntu 20.04 server.

(Visited 1,091 times, 1 visits today)

Latest Comments

  1. 3xploit on3 February 28, 2024

Leave a Reply

AlphaOmega Captcha Classica  –  Enter Security Code
captcha      
 

This site uses Akismet to reduce spam. Learn how your comment data is processed.