
WordPress is a free, open-source content management system (CMS) built with PHP and backed by MySQL or MariaDB. It began as a blogging tool and has since grown into one of the most widely used platforms for building websites, powering over 22% of the top one million websites as of December 2024.
This article explains how to install and configure WordPress on a server running Ubuntu 24.04 with the LEMP stack (Linux, Nginx, MySQL, PHP). You'll set up the necessary software, secure the environment, and deploy WordPress to serve dynamic websites from your own server.
Before you begin, ensure you:
www.example.com) if using a custom domain.Install Nginx.
Start the Nginx service.
Enable Nginx to start automatically on boot.
Check the service status to verify Nginx is running.
Output.
Use UFW (Uncomplicated Firewall) to allow HTTP and HTTPS traffic.
Check the current firewall status.
Allow both HTTP and HTTPS through the firewall using the Nginx Full profile.
Reload UFW to apply the rule.
Verify that the rule has been applied.
Output:
Install the MySQL server package.
Verify that MySQL was installed successfully.
Output:
Start the MySQL service to activate the database server.
Enable MySQL to start on boot.
Verify that MySQL is running correctly by checking its service status.
Output:
Harden your MySQL setup by running the built-in security script.
WordPress requires a dedicated MySQL database to store its content, settings, and user information. Follow these steps to set up a database and user:
Log in to the MySQL shell as the root user.
Create the WordPress database.
Create a dedicated user for WordPress with a strong password.
Grant full privileges to the new user on the WordPress database.
Apply the changes by reloading the privileges.
Verify that the database was created successfully.
Output:
Check that the user was created.
Output:
Confirm the privileges granted to the user.
Output:
Exit the MySQL shell.
WordPress uses PHP to process dynamic content and connect to the MySQL database. Install PHP and the required extensions:
Install PHP and all required modules.
Verify the installed PHP version.
Output:
Confirm that php-fpm is running.
The output should show active (running).
Download the latest WordPress release.
Extract the archive.
Move the contents to the Nginx web root.
Set ownership to the Nginx user.
Change to the web root.
Remove default Nginx placeholders.
Rename the sample config.
Verify the WordPress files are in place.
Ensure files like wp-config.php, wp-login.php, and the wp-admin folder exist.
wp-config.php FileTo allow WordPress to connect to your MySQL database, update the wp-config.php file with the database credentials created earlier.
Open the configuration file in a text editor.
Find and update the following lines with your database information:
Save and close the file.
DB_NAME, DB_USER, and DB_PASSWORD match what you used during the Create a WordPress Database and User step.DB_HOST as localhost if the database is hosted on the same server.To serve your WordPress site, configure Nginx with a server block that handles PHP requests and routes domain traffic to your WordPress directory.
Identify the active PHP-FPM socket on your system.
Output:
Note the exact .sock filename, such as php8.3-fpm.sock. You'll need this for the fastcgi_pass directive in the next step.
Open the default Nginx server block configuration file.
Replace the contents of the file with the following configuration. Replace www.example.com with your domain name or server IP, and update the PHP socket path if needed.
Test the Nginx configuration for syntax correctness.
Output:
Restart Nginx to apply the updated configuration.
Open your web browser and visit http://www.example.com. You should see the WordPress installation screen.
Select your preferred language and click Continue.
Fill in the required details, including your Site Title, Username, Password, and Email, then click Install WordPress.
Once installation completes, log in with the credentials you just set.
You’ll be redirected to the WordPress dashboard, where you can begin customizing your website.
In this article, you installed and configured WordPress on Ubuntu 24.04 using the LEMP stack (Linux, Nginx, MySQL, PHP). You set up Nginx to serve your site, configured a secure MySQL database, tuned PHP with necessary extensions, and deployed WordPress for production use.
0 Comments
Be the first to comment and share your perspective with the community.