There is some time when we need to change the port of the Apache server. There are several reasons for that like when 80 port is already in use by some other software or due to some security reasons and there could be many other reasons which lead to changing the default port of Apache web server. Here we will see how can we change the default port of an Apache Web Server on Ubuntu server.
Changing Default Port of Apache in Ubuntu/Debian
Verify that you have installed Apache first.
Step 1. Edit the ports.conf file of Apache.
Open /etc/apache2/ports.conf in any editor.
$ sudo nano /etc/apache2/ports.conf
Look for this line
Replace 80 with your desired port number, for example 8080.
Save and close the file.
Step 2. Edit the default file configuration file
$ sudo nano /etc/apache2/sites-enabled/000-default.conf
Change the port in this file as well at
Save and close this file.
Step 3. Restart the Apache
To apply those changes, we have to restart the Apache
$ sudo systemctl restart apache2
Step 4. Access Apache on new port