How to Install WordPress on LEMP Stack Ubuntu 22.04
Learn to install WordPress on a LEMP stack with this straightforward guide. Covering every step from MySQL setup to Nginx configuration on Ubuntu 22.04, we ensure a smooth WordPress integration with your LEMP environment.
Introduction:
Setting up WordPress on a LEMP stack involves integrating one of the world’s most popular content management systems with a robust server environment. LEMP, which stands for Linux, Nginx (pronounced as Engine-X), MySQL, and PHP, provides a stable and efficient platform for running dynamic websites. In this tutorial, we will guide you through the comprehensive process of installing WordPress on a LEMP stack running on an Ubuntu 22.04 server. From creating a MySQL database and configuring Nginx to finalizing the WordPress installation, we will cover all the essential steps to get your WordPress site up and running seamlessly.
Step 1: Create a MySQL Database and User for WordPress
- Login to MySQL:
sudo mysql
- Create a Database for WordPress:
CREATE DATABASE wordpress_db;
- Create a MySQL User and Grant Privileges: Replace
'your_username'
and'your_password'
with your desired username and password.
CREATE USER 'your_username'@'localhost' IDENTIFIED BY 'your_password'; GRANT ALL PRIVILEGES ON wordpress_db.* TO 'your_username'@'localhost'; FLUSH PRIVILEGES; EXIT;
Step 2: Download WordPress
- Change to the temp directory:
cd /tmp
- Download WordPress:
curl -O https://wordpress.org/latest.tar.gz
- Extract the files:
tar xzvf latest.tar.gz
Step 3: Configure WordPress
- Copy the sample configuration file:
cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php
- Open the configuration file in a text editor:
nano /tmp/wordpress/wp-config.php
- Update the database connection details: Find the section that defines the database connection settings and update the
DB_NAME
,DB_USER
, andDB_PASSWORD
values with the database name, user, and password you created in Step 1.
define('DB_NAME', 'wordpress_db'); define('DB_USER', 'your_username'); define('DB_PASSWORD', 'your_password');
- Add Unique Keys and Salts: Generate unique values from the WordPress secret key generator (https://api.wordpress.org/secret-key/1.1/salt/) and replace the dummy values in the
wp-config.php
file.
Step 4: Copy Files to the Document Root
- Copy the WordPress files to your document root: Replace
/var/www/html
with your Nginx document root if it’s different.
sudo cp -a /tmp/wordpress/. /var/www/html
- Set the proper permissions:
sudo chown -R www-data:www-data /var/www/html
Step 5: Configure Nginx
- Open your Nginx server block configuration file: Replace
example.com
with your server’s name.
sudo nano /etc/nginx/sites-available/example.com
- Add location directives for WordPress: Inside the server block, add the following location directives to handle pretty permalinks:
location / { try_files $uri $uri/ /index.php$is_args$args; }
- Test the Nginx configuration:
sudo nginx -t
- Reload Nginx to apply changes:
sudo systemctl reload nginx
Step 6: Complete the Installation Through the Web Interface
- Open your web browser and go to your server’s domain name or IP address:
http://example.com
- Follow the on-screen instructions to complete the WordPress installation.
Now, you should have WordPress installed and running on your LEMP stack. You can log in to the WordPress admin panel to start customizing your new site. Enjoy your new WordPress site on your Ubuntu 22.04 server with Nginx, MySQL, and PHP!
Conclusion:
Congratulations! You’ve successfully navigated through the process of installing WordPress on a LEMP stack in Ubuntu 22.04. With your new setup, you’re now equipped with a powerful, flexible platform perfect for hosting a wide array of websites and applications. By following best practices and ensuring proper configurations, your server is now running a secure, efficient WordPress installation, poised to deliver optimal performance. Whether you’re setting up a blog, a business website, or a creative portfolio, your LEMP-powered WordPress site is ready to meet the challenge. Remember to keep your system and applications updated to maintain security and performance over time. Enjoy building and managing your content with WordPress on your robust LEMP stack!
I hope this article was helpful! You can find more here: Ubuntu Tutorial Articles
Discover more from Patrick Domingues
Subscribe to get the latest posts sent to your email.