How to change the Apache port on Linux

There are several programs you can choose to create a web server on Linux such as: B. Nginx, Litespeed and Apache. They each have their own way of managing them and they have their own set of features as well.
Using Apache to create a private web server is very easy. Because basically, users just have to install it and then activate the service. The web server can then be reached via port 80.
But what if you want to use Apache on a different port? For example, you might want to test a web without releasing the port HTTP (80). So the right choice is to change port 80 to the desired port.
Change tutorial port to Apache
Changing the port in Apache is quick and easy as you only need to set it up in the configuration file. And the file is located in a different directory depending on the Linux distributor used.
1. Open the configuration file
Just start, please go to the configuration file first, here are the commands, please paste them into the terminal.
CentOS / Fedora
$ sudo vi /etc/httpd/conf/httpd.conf
Debian / Ubuntu
$ sudo vi /etc/apache2/ports.conf
2. Change the Apache port
You will find port 80 which is currently running Apache.
Listen 80
Please change to
Listen 8080
For example, I would like to change the port here 80 Will 8080, so all you need to do is change the configuration as above.
Also read: Tutorial Install Apache, PHP7 and MariaDB on openSUSE
3. Change the port on the virtual host (Debian / Ubuntu only)
There are other configurations that you need to set when using Debian or Ubuntu. Namely change the port in the configuration file that is in the directory /etc/apache2/sites-enabled/
.
By default, the virtual host is 000-default.conf, but if you have previously set it to a domain, please set it according to the file with the domain name you want to use for this port change.
Now please go to the configuration file first.
$ sudo vi /etc/apache2/sites-enabled/000-default.conf
I remind you one more time, please change 000 standard the domain name for which you want to change the port. Unless you are using a domain, please continue to use the command above.
Next you will find the following text:
Please change that to:
At this point, Apache should be successfully set up for port 8080. However, there is still something left to do, please proceed to the next step.
4. Restart Apache
The final stage is start anew service Apache so that the configuration settings can be applied. Here is the command:
$ sudo systemctl restart apache2
After Apache has restarted, you can now access the new port directly, such as http: // ip_address: 8080. Please change the IP address and the port as set.
This is the easy way to change the port on Apache. You can use this method if you want to run tests before you publish a website on port 80. Also, make sure the port you set is open on the firewall so that it can be used.
Hopefully useful and good luck