Changing the Apache port in CentOS

Learn how to find your IP address and pinpoint your IP location effortlessly. Find your online identity now!

Updated: 30 Jan, 24 by Elizabet J 3 Min

List of content you will read in this article:

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 how to change the Apache port at Centos 7 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 to Public with it.

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 Listen 80.

Listen 80
Listen yourIP: 8081

After editing, save the file and exit.

3. 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 (Security-Enhanced Linux) 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.

To check the port status, you can enter the following command.

netstat -tlpn | grep httpd

You can also access your web port by entering the 8081 port on your domain's or domain's IP address.

📍 Discover Your IP Location: Dive deeper into the topic of "What is My IP Address and How Can I Find My IP Location?" for valuable insights.Congratulations! You made it to the end. Now you will change the port numbers like a champ.

In conclusion, changing the Apache port in CentOS is an effective way to tailor your web server to specific network environments and enhance its security. This process, involving a careful edit of the Apache configuration files, demonstrates the flexibility and control CentOS offers to system administrators. Whether it's to resolve port conflicts, comply with organizational policies, or secure the server against common threats, understanding how to change the Apache port is a valuable skill in the repertoire of a Linux expert. By following best practices and ensuring proper configuration, administrators can ensure that their Apache server runs smoothly on the customized port, contributing to a more secure and efficient network infrastructure.

To change the port number in Apache on CentOS 7, edit the httpd.conf file located in /etc/httpd/conf/. Search for the Listen directive and change the port number to your desired value. For example, Listen 8080 will set the port to 8080. After saving the changes, restart the Apache service using sudo systemctl restart httpd.

Open the httpd.conf file in /etc/httpd/conf/ and locate the line that reads Listen 80. Change it to Listen 8080. Ensure no other service is using port 8080. Save the file and restart Apache with sudo systemctl restart httpd.

The default port number for Apache in Linux is port 80 for unencrypted HTTP traffic and port 443 for encrypted HTTPS traffic.

The default port for the Apache HTTP Server (httpd) is port 80 for HTTP.

Elizabet J

Elizabet J

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