In this post we will see, how we can change the default port (port 80) of Wordpress to something else (port 1280) in order to have port 80 available for other applications to use.

To make this change we will need to change 2 main things, the Apache configuration files and some options in the MySQL database.

We are assuming that Wordpress is installed in a LAMP stack on an Ubuntu or Debian server.

Update Port in Apache configuration files

In order to change ports, we first need to configure Apache to listen to port 1280 and not the default port 80. To do that we have to edit the /etc/apache2/ports.conf file and change the Listen port:

Listen 1280

<IfModule ssl_module>
	Listen 443
</IfModule>

<IfModule mod_gnutls.c>
	Listen 443
</IfModule>

Next we need edit the configuration file we have created for Wordpress, in our case it is /etc/apache2/sites-available/wordpress.conf, and change the VirtualHost port:

<VirtualHost *:1280>

	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/wordpress
	ServerName yourdomain.com
	ServerAlias www.yourdomain.com

	<Directory /var/www/wordpress/>
		AllowOverride All
	</Directory>

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

We can make sure we don’t have syntax errors, by running:

sudo apache2ctl configtest

If the output has a AH00558 message ignore it. We only care about the SYNTAX OK message.

and finally restart Apache:

sudo systemctl restart apache2

You can check the local network sockets, using netstat or ss to see if the change is successful:

netstat -tlpn | grep apache
ss -tlpn| grep apache

Update Port in Wordpress configuration file

After configuring Apache to listen to another port, we need to configure Wordpress to use this new port in order to redirect the requests correctly.

We can do this by updating the WPSITE and WPHOME properties in wp-config.php.

Open www/wordpress/wp-config.php and append the following lines:

define('WPSITEURL','http://192.168.1.99:1280/');
define('WPHOME','http://192.168.1.99:1280/');

After saving the changes, the new requests will ignore the values that are stored in the MySQL database and use these values defined here in the Wordpress configuration file.

But this change is temporary, and in order to change these properties permanently, we have to edit these values in the MySQL database.

Update Port in MySQL database

The WPSITE and WPHOME properties we set earlier in the wp-config.php file are stored as siteurl and home options, in the wp_options table of the wordpress database we have created for Wordpress in MySQL.

We can see the values that they have with the following command:

mysql> SELECT * FROM wp_options WHERE option_name = 'siteurl' OR option_name = 'home';
+-----------+-------------+---------------------+----------+
| option_id | option_name | option_value        | autoload |
+-----------+-------------+---------------------+----------+
|         2 | home        | http://192.168.1.99 | yes      |
|         1 | siteurl     | http://192.168.1.99 | yes      |
+-----------+-------------+---------------------+----------+
2 rows in set (0,01 sec)

In order to update the option_value field with the updated url with the new port (port 1280), we have to run the following commands:

use wordpress;
update wp_options set option_value='http://192.168.1.99:1280' where option_name='siteurl';
update wp_options set option_value='http://192.168.1.99:1280' where option_name='home';

Now if we check the values again we can see:

mysql> SELECT * FROM wp_options WHERE option_name = 'siteurl' OR option_name = 'home';
+-----------+-------------+--------------------------+----------+
| option_id | option_name | option_value             | autoload |
+-----------+-------------+--------------------------+----------+
|         2 | home        | http://192.168.1.99:1280 | yes      |
|         1 | siteurl     | http://192.168.1.99:1280 | yes      |
+-----------+-------------+--------------------------+----------+
2 rows in set (0.00 sec)