theme-sticky-logo-alt
theme-logo-alt

How to Install WordPress with Apache, MySQL, and SSL

Setting up WordPress on an Ubuntu 20.04 server with Apache, MySQL, and an SSL certificate ensures your website is secure and performant. This guide, brought to you by lab53.uk, will detail each step in the installation process.

Step 1: Install Required Packages

First, update your package list and install Apache, MySQL, PHP, and other necessary packages:

sudo apt update
sudo apt install apache2 php libapache2-mod-php mysql-server php-mysql certbot python3-certbot-apache php-curl php-xml php-mbstring php-imagick php-zip php-gd

Step 2: Enable mod_rewrite

Ensure mod_rewrite is enabled for Apache to handle permalinks correctly:

sudo a2enmod rewrite
sudo systemctl restart apache2

Step 3: Secure MySQL Installation

Run the MySQL secure installation script to improve security:

sudo mysql_secure_installation

Follow the prompts to set up the root password, remove anonymous users, disallow root login remotely, and remove the test database.

Step 4: Create a MySQL Database and User

Log into MySQL and create a new database and user for WordPress:

sudo mysql
mysql> CREATE DATABASE wordpress_db;
mysql> CREATE USER 'wordpress_user'@'localhost' IDENTIFIED BY 'secure_password';
mysql> GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress_user'@'localhost';
mysql> FLUSH PRIVILEGES;
mysql> EXIT;

Step 5: Configure php.ini

Update php.ini to ensure compatibility and performance:

sudo nano /etc/php/7.4/apache2/php.ini

Adjust the following settings:

memory_limit = 256M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 300

Save and close the file. Restart Apache:

sudo systemctl restart apache2

Step 6: Create a Directory for Your Site

Create a directory for your WordPress installation:

sudo mkdir /var/www/your_site_name

Step 7: Create a Directory for Your Site

Create a directory for your WordPress installation:

sudo mkdir /var/www/your_site_name

Step 8: Configure Apache Virtual Hosts

Create a new virtual host configuration file for your website:

sudo nano /etc/apache2/sites-available/your_site_name.conf

Paste the following content, replacing placeholders with your actual domain and directory paths:

<VirtualHost *:80>
    ServerAdmin admin@yourdomain.com
    ServerName yourdomain.com
    ServerAlias www.yourdomain.com
    DocumentRoot /var/www/your_site_name
    <Directory /var/www/your_site_name>
        Options FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/your_site_name_error.log
    CustomLog ${APACHE_LOG_DIR}/your_site_name_access.log combined
</VirtualHost>

Enable the site and disable the default site:

sudo a2ensite your_site_name.conf
sudo a2dissite 000-default.conf
sudo rm -rf /var/www/html

Step 9: Test Apache Configuration
Check the configuration and restart Apache:

sudo apache2ctl configtest
sudo systemctl restart apache2

Step 10: Install SSL Certificate

Use Certbot to install an SSL certificate from Let’s Encrypt:

sudo certbot -d yourdomain.com -d www.yourdomain.com --apache --agree-tos -m admin@yourdomain.com --no-eff-email --redirect

Verify that certbot.timer is active and test the certificate renewal process:

sudo systemctl status certbot.timer
sudo certbot renew --dry-run

Step 11: Install WordPress

Download and unpack the latest version of WordPress:

sudo wget -O /tmp/wordpress.tar.gz https://wordpress.org/latest.tar.gz sudo tar -xzvf /tmp/wordpress.tar.gz -C /tmp sudo cp -av /tmp/wordpress/* /var/www/your_site_name sudo rm -rf /tmp/wordpress.tar.gz /tmp/wordpress

Step 12: Set Permissions

Ensure the correct permissions for the WordPress directory:

sudo chown -R www-data:www-data /var/www/your_site_name

Step 13: Complete WordPress Setup

Visit your domain in a web browser to complete the WordPress installation by following the on-screen instructions. Use the database details created in Step 3.

By following this guide, you will have a fully operational WordPress site with Apache, MySQL, and SSL on Ubuntu 20.04, providing a secure and reliable platform for your content.

Share:
Category:System Admin
NEXT POST
Advanced Linux System Administration: Tips and Tricks
15 49.0138 8.38624 1 0 4000 1 https://lab53.uk 300 1