How to Change Apache Port on cPanel using the Command Line

Can I change the apache port via command line in cpanel servers?  Yes you can, it’s easy to change apache port on cPanel using the Linux terminal, keep reading to see how.

By default, cPanel users port 80 for its apache configuration, as well as 443 for the SSL secure ports (HTTPS). However, in some strange days you will need to change apache port from 80 to another port number like 81 or 8080.

This can happen if you run Nginx as front end server acting as a reverse proxy for Apache on the backend. That’s the most usual scenario when you are going to need to change apache port on cPanel servers.

Let’s see the steps to change the default port from the Linux command line.

Change Apache Port on cPanel using the command line

cPanel configuration defines the Apache port from the cpanel.config configuration file. This file can be located at:


Now, let’s see how apache is configured right now using grep command:

grep apache_port -i /var/cpanel/cpanel.config

This should be the output:

[[email protected]:~]grep apache_port -i /var/cpanel/cpanel.config

Now, let’s replace 80 with 81 for example, for this we will use ‘replace’ command:

replace "apache_port=" "apache_port=" -- /var/cpanel/cpanel.config

Run grep again to see if the new value was replaced:

grep apache_port -i /var/cpanel/cpanel.config

If you see 81, then it’s ok and you can apply this changes to be permanent by running this script:

/usr/local/cpanel/whostmgr/bin/whostmgr2 -updatetweaksettings

Now just to make sure everything is set as we expect, let’s grep Apache configuration file to see if the change was applied to its configuration.

grep 81 /usr/local/apache/conf/httpd.conf

Now, to make sure Apache configuration is picking up the changes, let’s run a rebuild with this handy cPanel script:


That’s all, at this time your Apache default port should be changed. Please share your thoughts about this how to change Apache port via command line tutorial.

Further reading:


About the Author: Santiago Borges

Experienced Sr. Linux SysAdmin and Web Technologist, passionate about building tools, automating processes, fixing server issues, troubleshooting, securing and optimizing high traffic websites.

Leave a Reply

Your email address will not be published. Required fields are marked *