Site icon GetCodify

How to enable permalinks in WordPress – Ubuntu Apache2


To enable permalinks in WordPress while hosting on an Ubuntu server with Apache2, you can follow these steps:

1. Log into your server:

Ensure that you have SSH access to your Ubuntu server.

2. Install WordPress:

If you haven’t already, install WordPress on your server. You can follow the WordPress installation guide for Ubuntu: https://getcodify.com/setting-up-wordpress-on-ubuntu-with-apache2-mysql-and-ssl/

3. Configure Apache2:

Make sure your Apache2 server is configured to serve your WordPress site. You may need to set up virtual hosts if you haven’t already. Here’s a simplified example:

With this command, you are creating a new virtual host for your new WordPress site.

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

Add the following configuration and adjust it to your needs:

<VirtualHost *:80>
    ServerAdmin webmaster@yourdomain.com
    ServerName yourdomain.com
    ServerAlias www.yourdomain.com
    DocumentRoot /var/www/html/wordpress

    <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 site and restart Apache 2:

sudo a2ensite wordpress.conf
sudo systemctl restart apache2

Please note that the configuration provided above is currently set up for HTTP propagation on port 80. If you wish to enable HTTPS, you can use the same configuration and simply replace port 80 with port 443. If you are utilizing Certbot to generate an SSL certificate, follow these steps: After creating the HTTP port 80 configuration file, run Certbot. Certbot will automatically generate a new site configuration file for HTTPS.
Occasionally, Certbot may not automatically include the <Directory> tag values by default. Therefore, please ensure that these tags are present in both configuration files. This step is crucial, especially when dealing with WordPress permalinks.

4. Enable Permalinks in WordPress:

Now that your server is configured, you can enable permalinks in WordPress:

5. Update .htaccess:

WordPress will automatically generate a .htaccess file with the required rules for your chosen permalink structure. If you don’t see this file in your WordPress root directory, create it manually and set the correct permissions:

touch /var/www/html/wordpress/.htaccess
sudo chown www-data:www-data /var/www/html/wordpress/.htaccess
Exit mobile version