Why to change the default port?
Change the default port (443) for WordPress web applications is a crucial security measure. By altering the default port (usually port 80 for HTTP and 443 for HTTPS), users can enhance protection against common cyber threats. This practice helps mitigate unauthorized access and reduces the risk of automated attacks targeting well-known ports.
However, when changing ports, it’s essential to update server configurations, firewalls, and any associated infrastructure to ensure seamless functionality and accessibility for users while fortifying the overall cybersecurity posture of the web application.
VERY IMPORTANT: CREATE THE BACKUP OF ALL CONFIGURATION FILES!
Steps to Change the WordPress Port from 433 to 8443
Step 1: Login to the WordPress WP-Admin and Change settings
Change the settings on the WordPress Settings:
Step 2: Change Port Settings in your WebServer Configuration
Change the settings in the file: /etc/apache2/ports.conf
nano /etc/apache2/ports.conf
Content of the file:
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf
Listen 80
<IfModule ssl_module>
Listen 8443
</IfModule>
<IfModule mod_gnutls.c>
Listen 8443
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
<IfModule mod_ssl.c>
Listen 8443
</IfModule>
Step 3: Change the Settings in Web Server Site-Available Configuration
Change the settings in the file:
nano /etc/apache2/sites-available/wordpress-le-ssl.conf
Content of the file:
<IfModule mod_ssl.c>
<VirtualHost *:8443>
DocumentRoot /srv/www/wordpress
<Directory /srv/www/wordpress>
Options FollowSymLinks
AllowOverride Limit Options FileInfo
DirectoryIndex index.php
Require all granted
</Directory>
<Directory /srv/www/wordpress/wp-content>
Options FollowSymLinks
Require all granted
</Directory>
ServerName domain.com
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/domain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/domain.com/privkey.pem
</VirtualHost>
</IfModule>
Step 4: Change Settings in WordPress wp-config.php File
Change the settings on the file nano /srv/www/wordpress/wp-config.php
define('WPSITEURL','https://domain.com:8443/');
define('WPHOME','https://domain.com:8443/');
Check Settings on MySQL Server
Connect to your MySQL Server
# Connect to the MySQL Serber
mysql -u root
Select correct database, in my case it is wordpress
use wordpress;
Check the settings save in the wp_options
table:
# Execute the following query to check the settings:
select * from wp_options where option_name='siteurl';
select * from wp_options where option_name='home';
In case that you need to update this, use the following updates statements:
# In case that you need to update the values:
update wp_options set option_value='https://domain.com:8443' where option_name='siteurl';
update wp_options set option_value='https://domain.com:8443' where option_name='home';