Setting up your own WordPress site on a fast, secure, and scalable Ubuntu server? This guide will walk you through the process of installing WordPress using the LAMP stack (Linux, Apache, MySQL, PHP) with HTTPS enabled via Let's Encrypt and Certbot.
Let’s dive in!
Table of contents [Show] [Hide]
- Prerequisites
- Step 1: Install Apache Web Server
- Step 2: Install MySQL Database Server
- Step 3: Install PHP and Extensions
- Step 4: Download and Configure WordPress
- Step 5: Configure Apache Virtual Host
- Step 6: Configure WordPress
- Step 7: Enable HTTPS Using Let’s Encrypt (Certbot)
- Step 8: Finish WordPress Installation in Browser
- Final Recommendations
Prerequisites
- A server running Ubuntu 22.04
- A registered domain name pointing to your server
- A user with
sudo
privileges - Apache, MySQL, PHP installed (explained below)
Step 1: Install Apache Web Server
sudo apt update
sudo apt install apache2
Enable Apache and start the service:
sudo systemctl enable apache2
sudo systemctl start apache2
Step 2: Install MySQL Database Server
sudo apt install mysql-server
sudo mysql_secure_installation
Create a database and user for WordPress:
sudo mysql
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'your_secure_password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Step 3: Install PHP and Extensions
sudo apt install php php-mysql libapache2-mod-php php-cli php-curl php-gd php-xml php-mbstring php-soap php-intl php-zip
Check version:
php -v
Restart Apache:
sudo systemctl restart apache2
Step 4: Download and Configure WordPress
cd /tmp
curl -O https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
sudo mkdir -p /var/www/wordpress
sudo cp -a /tmp/wordpress/. /var/www/wordpress
Set permissions:
sudo chown -R www-data:www-data /var/www/wordpress
sudo find /var/www/wordpress -type d -exec chmod 755 {} \;
sudo find /var/www/wordpress -type f -exec chmod 644 {} \;
Step 5: Configure Apache Virtual Host
Create config file:
sudo nano /etc/apache2/sites-available/wordpress.conf
Paste:
<VirtualHost *:80>
ServerName yourdomain.com
DocumentRoot /var/www/wordpress
<Directory /var/www/wordpress>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/wordpress_error.log
CustomLog ${APACHE_LOG_DIR}/wordpress_access.log combined
</VirtualHost>
Enable site and modules:
sudo a2ensite wordpress
sudo a2enmod rewrite
sudo systemctl reload apache2
Step 6: Configure WordPress
Create and edit config file:
cd /var/www/wordpress
cp wp-config-sample.php wp-config.php
nano wp-config.php
Update these lines:
define('DB_NAME', 'wordpress');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'your_secure_password');
define('DB_HOST', 'localhost');
Add secret keys from: https://api.wordpress.org/secret-key/1.1/salt/
Step 7: Enable HTTPS Using Let’s Encrypt (Certbot)
Install Certbot and Apache plugin:
sudo apt install certbot python3-certbot-apache
Request and install SSL certificate:
sudo certbot --apache
- Enter your email
- Agree to terms
- Select your domain
- Choose to redirect HTTP to HTTPS (recommended)
Certbot will automatically update your Apache config and reload it.
To auto-renew certificates:
sudo systemctl status certbot.timer
To test renewal:
sudo certbot renew --dry-run
Step 8: Finish WordPress Installation in Browser
Visit:
https: //yourdomain.com
Follow the setup wizard:
- Choose language
- Site title
- Admin username, password, and email
Click Install WordPress — done!
You now have a fully functional, secure WordPress site with HTTPS, hosted on Ubuntu 22.04! This setup is ideal for blogs, portfolios, and small business websites.
Final Recommendations
- Use a caching plugin like LiteSpeed Cache or WP Super Cache
- Regularly update WordPress, plugins, and Ubuntu packages
- Enable automatic backups
Frequently Asked Questions (FAQs)
The best way to install WordPress on Ubuntu is by using the LAMP stack (Linux, Apache, MySQL, PHP). This setup provides full control, better performance, and flexibility for hosting WordPress on a VPS.
Yes, Ubuntu is a popular Linux distribution for hosting WordPress websites. It is secure, lightweight, and has excellent community support, making it a reliable choice for web hosting.
To enable HTTPS on your WordPress site hosted on Ubuntu, use Let's Encrypt with Certbot. It provides a free SSL certificate and automatically configures Apache to serve your site over HTTPS.
Certbot is a free, open-source tool from the Electronic Frontier Foundation (EFF) that automates the process of obtaining and installing SSL/TLS certificates from Let’s Encrypt. It helps secure your WordPress site by enabling HTTPS.
Yes, a valid domain name is required to generate a Let's Encrypt SSL certificate using Certbot. The domain should point to your server’s public IP address via DNS.
Absolutely. This guide shows you how to install WordPress on Ubuntu manually using the command line, without any control panel like cPanel or Plesk.
Yes, if you follow best practices like creating a strong MySQL password, setting correct file permissions, enabling HTTPS, and keeping software updated, your installation will be secure.
You can update WordPress from the admin dashboard. For system-level updates (PHP, MySQL, Apache), use the command:
sudo apt update && sudo apt upg rade