In this guide, CW-AI provides a complete step-by-step installation of WordPress on Ubuntu 24.04. This version has been verified for correctness, providing 100% accurate commands and configurations for a secure and efficient setup.
Step 1: Update System Packages
Begin by updating your system to ensure all packages are up to date.
sudo apt update && sudo apt upgrade -y
Step 2: Install Apache Web Server
Apache is used as the web server for hosting WordPress.
- Install Apache:
sudo apt install apache2 -y
- Verify the Apache service:
sudo systemctl status apache2
- Configure Firewall (UFW): Allow HTTP and HTTPS traffic for WordPress:
sudo ufw allow 'Apache Full' sudo ufw reload sudo ufw status verbose
Step 3: Install MySQL Database Server
WordPress requires a database for storing site content. We will use MySQL.
- Install MySQL:
sudo apt install mysql-server -y
- Secure your MySQL installation:
sudo mysql_secure_installation
Follow the prompts to enhance the security of your MySQL instance, such as setting a root password and disabling remote root access.
- Create a WordPress Database and User:
sudo mysql
Then, run the following commands within the MySQL prompt to create a database and user for WordPress:
CREATE DATABASE wordpress_db; CREATE USER 'wordpress_user'@'localhost' IDENTIFIED BY 'your_password'; GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress_user'@'localhost'; FLUSH PRIVILEGES; EXIT;
Step 4: Install PHP
WordPress uses PHP for server-side scripting. Install PHP and required modules:
sudo apt install php libapache2-mod-php php-mysql php-xml php-curl php-zip php-gd php-imagick -y
Step 5: Download and Configure WordPress
- Navigate to the
/tmpdirectory and download WordPress:
cd /tmp wget https://wordpress.org/latest.tar.gz
- Extract the downloaded archive:
tar -xvzf latest.tar.gz
- Move the extracted files to the Apache web root:
sudo mv wordpress /var/www/html/wordpress
- Set proper ownership and permissions:
sudo chown -R www-data:www-data /var/www/html/wordpress
sudo find /var/www/html/wordpress/ -type d -exec chmod 750 {} \;
sudo find /var/www/html/wordpress/ -type f -exec chmod 640 {} \;
Step 6: Configure Apache for WordPress
- Create an Apache configuration file for WordPress:
sudo nano /etc/apache2/sites-available/wordpress.conf
Add the following configuration:
<VirtualHost *:80>
ServerAdmin admin@your_domain.com
DocumentRoot /var/www/html/wordpress
ServerName your_domain.com
ServerAlias www.your_domain.com
<Directory /var/www/html/wordpress/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
- Enable the new site and Apache rewrite module:
sudo a2ensite wordpress.conf sudo a2enmod rewrite sudo systemctl restart apache2
Step 7: Enable SSL with Let’s Encrypt (Recommended)
To secure your WordPress site, install a free SSL certificate using Let’s Encrypt:
- Install Certbot:
sudo apt install certbot python3-certbot-apache -y
- Run Certbot to obtain and install an SSL certificate:
sudo certbot --apache -d your_domain.com -d www.your_domain.com
- Follow the prompts to complete the SSL setup. Certbot will configure Apache to redirect HTTP to HTTPS automatically.
Step 8: Complete WordPress Setup
- Access your WordPress installation by navigating to
http://your_domain.comin your web browser. - Follow the on-screen instructions to complete the installation, entering the database information created earlier.
Additional Recommendations
- Regular Backups: Set up regular backups for both WordPress files and the MySQL database. Tools like
rsyncor plugins such as UpdraftPlus are great options. - Strong Permissions: Revisit file and directory permissions to minimize security vulnerabilities.
- Disable XML-RPC: XML-RPC is enabled by default and can be exploited. Disable it if not needed by adding the following to your theme’s
functions.phpfile:
add_filter('xmlrpc_enabled', '__return_false');
Conclusion
You now have a functional WordPress installation on Ubuntu 24.04, complete with enhanced security, firewall settings, and SSL. This setup by CW-AI ensures you are using best practices for a stable and secure WordPress site.
Guide provided by CW-AI.