Install WordPress on Ubuntu 24.04 With Free SSL (Let’s Encrypt)
This guide shows how to install WordPress on Ubuntu 24.04 using Apache, PHP, and MySQL — then secure it with a free SSL certificate from Let’s Encrypt. It also includes two common production needs: blocking search engines until launch and increasing WordPress upload size.
What you’ll set up
- Apache + PHP + MySQL (LAMP stack)
- WordPress running on your domain
- HTTPS enabled with SSL auto-renewal
- Pre-launch protection to stop Google indexing
- Increased upload limits for themes/media/plugins
Prerequisites
- Ubuntu 24.04 VM with SSH access (works great on Microsoft Azure)
- A domain pointed to your VM public IP
- DNS A record:
yourdomain.com → <VM Public IP> - DNS A record:
www.yourdomain.com → <VM Public IP>
- DNS A record:
- Firewall/Security rules allowing:
- TCP 22 (SSH), TCP 80 (HTTP), TCP 443 (HTTPS)
Step 1 — Update your server
sudo apt update && sudo apt -y upgrade
sudo reboot
Step 2 — Install Apache, MySQL, and PHP
sudo apt update
sudo apt install -y apache2 mysql-server \
php php-mysql php-xml php-curl php-gd php-mbstring php-zip php-intl php-soap \
unzip curl
Enable Apache:
sudo systemctl enable --now apache2
sudo systemctl status apache2 --no-pager
Step 3 — Secure MySQL and create the WordPress database
sudo mysql_secure_installation
Create DB + user (replace the password):
sudo mysql -u root <<'SQL'
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'ChangeThis_StrongPassword!';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
SQL
Step 4 — Create an Apache Virtual Host
Replace yourdomain.com below with your real domain (example: travel94.com).
Create web root:
sudo mkdir -p /var/www/yourdomain.com
sudo chown -R $USER:$USER /var/www/yourdomain.com
Create vhost:
sudo nano /etc/apache2/sites-available/yourdomain.com.conf
Paste:
<VirtualHost *:80>
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /var/www/yourdomain.com
<Directory /var/www/yourdomain.com>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/yourdomain.com_error.log
CustomLog ${APACHE_LOG_DIR}/yourdomain.com_access.log combined
</VirtualHost>
Enable the site:
sudo a2enmod rewrite headers
sudo a2ensite yourdomain.com
sudo a2dissite 000-default
sudo apache2ctl configtest
sudo systemctl reload apache2
Test:
curl -I http://yourdomain.com
Step 5 — Download and deploy WordPress
cd /tmp
curl -LO https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
rsync -av wordpress/ /var/www/yourdomain.com/
Permissions:
sudo chown -R www-data:www-data /var/www/yourdomain.com
sudo find /var/www/yourdomain.com -type d -exec chmod 755 {} \;
sudo find /var/www/yourdomain.com -type f -exec chmod 644 {} \;
Step 6 — Configure WordPress (wp-config.php)
cd /var/www/yourdomain.com
sudo -u www-data cp wp-config-sample.php wp-config.php
sudo nano wp-config.php
Update:
define( 'DB_NAME', 'wordpress' );
define( 'DB_USER', 'wpuser' );
define( 'DB_PASSWORD', 'ChangeThis_StrongPassword!' );
define( 'DB_HOST', 'localhost' );
Add salts:
curl -s https://api.wordpress.org/secret-key/1.1/salt/
Now browse:
http://yourdomain.comand complete the installer.
Step 7 — Enable SSL (Let’s Encrypt)
Install Certbot (from Electronic Frontier Foundation ecosystem):
sudo apt install -y certbot python3-certbot-apache
Issue certificate:
sudo certbot --apache -d yourdomain.com -d www.yourdomain.com
Choose redirect HTTP → HTTPS when prompted.
Test renewal:
sudo certbot renew --dry-run
Pre-launch: Stop search engines from indexing your site
If your site is not ready, the safest approach is to block public access (password protection), then also add “noindex” signals as backup.
Option A (Best): Password-protect the entire site (recommended pre-launch)
Enable basic auth:
sudo a2enmod auth_basic
sudo systemctl reload apache2
Create a password file:
sudo htpasswd -c /etc/apache2/.htpasswd youradminuser
Edit your vhost:
sudo nano /etc/apache2/sites-available/yourdomain.com.conf
Inside the <Directory /var/www/yourdomain.com> block, add:
AuthType Basic
AuthName "Coming Soon"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
Reload:
sudo apache2ctl configtest
sudo systemctl reload apache2
✅ Result: search engines can’t crawl the site at all (most reliable).
Option B: Allow public access but prevent indexing (good, not foolproof)
1) Add a robots.txt
Create:
sudo nano /var/www/yourdomain.com/robots.txt
Add:
User-agent: *
Disallow: /
2) Add an “X-Robots-Tag” header at Apache level (stronger)
Edit vhost:
sudo nano /etc/apache2/sites-available/yourdomain.com.conf
Add inside the <VirtualHost *:80> block:
Header set X-Robots-Tag "noindex, nofollow, noarchive, nosnippet"
After SSL is enabled, also add the same line inside the <VirtualHost *:443> block that Certbot creates.
Reload:
sudo apache2ctl configtest
sudo systemctl reload apache2
✅ Result: compliant crawlers should not index your pages, even if they can access them.
Option C: WordPress setting (quick checkbox)
In WordPress Admin:
- Settings → Reading → tick “Discourage search engines from indexing this site”
This helps, but it’s not as reliable as password protection.
If the site was already indexed
Once you’re sure “noindex” or password protection is in place, you can use the URL removal tool in Google’s webmaster console to request quicker removal (optional).
Increase WordPress upload size to 256MB
If you see: “The uploaded file exceeds the upload_max_filesize directive in php.ini”, increase PHP limits.
Step 1: Identify your PHP version
php -v
On Ubuntu 24.04, it’s commonly PHP 8.3.
Step 2: Update php.ini (Apache)
Edit:
sudo nano /etc/php/8.3/apache2/php.ini
Set:
upload_max_filesize = 256M
post_max_size = 256M
memory_limit = 512M
max_execution_time = 300
max_input_time = 300
Important:
post_max_sizemust be >=upload_max_filesize.
Reload Apache:
sudo systemctl reload apache2
If you are using PHP-FPM (instead of mod_php)
Edit:
sudo nano /etc/php/8.3/fpm/php.ini
Then restart:
sudo systemctl restart php8.3-fpm
sudo systemctl restart apache2
Verify the new upload limit
Easiest method:
- WordPress Admin → Tools → Site Health → Info (look for upload limits)
Or create a temporary phpinfo (remove immediately after testing):
echo "<?php phpinfo(); ?>" | sudo tee /var/www/yourdomain.com/phpinfo.php >/dev/null
Visit: https://yourdomain.com/phpinfo.php and search for upload_max_filesize.
Then delete it:
sudo rm -f /var/www/yourdomain.com/phpinfo.php
Common troubleshooting
Certbot says it can’t find a virtual host on port 80
Certbot needs a working <VirtualHost *:80> for your domain. Confirm:
sudo apache2ctl -S
Ensure port 80 is open in your cloud firewall/NSG and DNS points to the VM.
Launch checklist
✅ DNS A records pointing to VM IP
✅ Ports 80/443 open
✅ SSL active and auto-renewing
✅ Upload size increased (if needed)
✅ Pre-launch indexing disabled (password/noindex)
✅ Remove phpinfo and keep plugins updated

