Linux,  技术

How to change default port for Apache2

This example is for Ubuntu.

Run sudo apachectl -S to check which conf file you are using. The result is something like:

liangqi@nuci5-2:~$ sudo apachectl -S
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
*:83                   127.0.1.1 (/etc/apache2/sites-enabled/000-default.conf:1)
*:443                  liangqi.org (/etc/apache2/sites-enabled/default-ssl.conf:2)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/run/apache2/" mechanism=default
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex ssl-stapling: using_defaults
Mutex ssl-cache: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

Then update the file /etc/apache2/sites-enabled/000-default.conf. Change the default file in that file.

You need to change another file /etc/apache2/ports.conf. to update it to the right port.

Restart apache sudo service apache2 restart

Then check the status: sudo apachectl -S

Done.

Leave a Reply

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