+1 (506) 500-5957 sales@monovm.com Get US VPS for 50% OFF!

Changing the Apache port in CentOS

In this tutorial we will explain how to change the Apache port in CentOS 7 Linux server.

Posted: 18 Mar, 19 Updated: 05 Mar, 23 by Elizabet J 3 Min

Apache is a free and open-source cross-platform(Linux & Windows) web server software. It provides the web services default by port 80. The web server supports HTTPS as well as other web servers and it provides port 443 services. In this article, we will explain on changing the Apache port at Centos 7 in order to use Apache on other ports.

Port changes are not performed normally for websites, and are generally subject to change of port on Apache or any other service, that the website is provided privately or the unique service is running on it and there is no need for users Public with it.

Changing the Apache Port in Centos VPS Server

Like any other service and software, Apache has a main configuration file that is located in the directory etc / and named httpd.conf.

Note: In this tutorial, port 8081 has been used instead of port 80 and you can enter the port of interest.

The first step is to make changes to the Apache Configuration file.

1. Open the httpd.conf file with a text editor(Nano text editor).

nano /etc/httpd/conf/httpd.conf

2. In the file, find the 'Listen' and find the following statement as Listen 80.

Listen 80
Listen yourIP: 8081

After editing, save the file and exit.

3. If you want to open your website with a new port, you must edit the corresponding virtual host and enter the 8081 port.

In the example below, we opened the Virtual Host, but this name is different for you, and you must go to the Apache Virtual Host address and edit that file.

nano /etc/apache2/sites-enabled/000-default.conf

In this file, change the Virtual Host port to 8081.

So far you have been able to change the port in Apache, but to access this port from CentOS 7, you need to make changes to SeLinux to allow access to the Apache port on the 8081 port.

Follow these steps for these changes.

- Enter the following command to install the Policy core utils tool.

 yum install -y policiescoreutils

- When the installation finishes, the following commands are issued to allow access to the 8081 port in SeLinux.

semanage port -a -t http_port_t -p tcp 8081
semanage port -m -t http_port_t -p tcp 8081

- After you import the above commands, restart the Apache service.

systemctl restart httpd

This way you can change the port of Apache and you can use the new port as well.

In order to check the port status, you can enter the following command.

netstat -tlpn | grep httpd

You will also be able to access your web port by entering the 8081 port on your domain's or domain's IP address.

Congrtulations! You made it to the end. Now you will change the port numbers like a champ.

if you need to know more about Linux VPS server you can use linke below.


Elizabet J

Elizabet J

One OF my major goals is getting new experiences about ICT and what’s more making progress through this field.