How to Change Apache Port Number in CentOS


change apache port number centos

By default, Apache listens to port 80 for HTTP requests and port 443 for HTTPS requests. However, sometimes, you may need to make Apache listen to a non-standard port number, especially if you run Apache behind a proxy server. In this case, here’s how to change Apache port number in CentOS.

 

How to Change Apache Port Number in CentOS

Here are the steps to change Apache port number in CentOS

 

1. Open the Apache config file

Open the configuration file for your Apache server in a text editor.


# nano /etc/apache2/ports.conf [On Debian/Ubuntu]
# nano /etc/httpd/conf/httpd.conf [On RHEL/CentOS]

 

2. Change port number

Look for the line “Listen 80” and change 80 to the new port number you want (e.g 8081)


Listen 8081

 

3. Update Virtual Host file

Next, you need to update the default virtual host file (000-default.conf) to instruct Apache to listen to traffic coming from port 8081.

Open the file in a text editor


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

Look for the line <VirtualHost *:80> and change it to <VirtualHost *:8081>

how to change apache port number in centos

 

4. Restart Apache Server

Restart Apache server to apply the changes


# systemctl restart apache2

 

5. Verify the update

Verify that Apache is listening to new port number with netstat or ss tool


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

You should see something like the following output:

Verify Apache Port

 

You can also open a web browser and go to http://localhost:8081 or http://server_ip:8081. In case you are running Apache on a domain (e.g your_domain), you can go to http://your_domain:8081

You will see the default Apache web page.

Apache HTTP Server Test Page

 

If you are unable to see the web page, please ensure you have enabled incoming traffic for port 8081, in your firewall rules.

About Sreeram Sreenivasan

Sreeram Sreenivasan is the Founder of Ubiq, a business dashboard & reporting platform for small & medium businesses. Ubiq makes it easy to build business dashboards & reports for your business. Try it for free today!