Apache is the most popular open-source webserver. It is also called httpd in Centos/Redhat distributions.

Begin by checking if the server is running or not:

[debian.linuxnix] root:~/ # service apache2 status
Apache2 is running (pid 2082).

On Centos you can use the service command or the command below which gives more informations:

[centos.linuxnix] root:~ # apachectl status
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2016-10-13 10:53:26 CEST; 1 months 4 days ago
Docs: man:httpd(8)
Process: 27054 ExecReload=/usr/sbin/httpd $OPTIONS -k graceful (code=exited, status=0/SUCCESS)
Main PID: 1179 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─ 1179 /usr/sbin/httpd -DFOREGROUND
├─ 6529 /usr/sbin/httpd -DFOREGROUND
├─ 8835 /usr/sbin/httpd -DFOREGROUND
├─ 8858 /usr/sbin/httpd -DFOREGROUND
├─ 8859 /usr/sbin/httpd -DFOREGROUND
├─ 8860 /usr/sbin/httpd -DFOREGROUND
├─ 8861 /usr/sbin/httpd -DFOREGROUND
├─27059 /usr/sbin/httpd -DFOREGROUND
├─27060 /usr/sbin/httpd -DFOREGROUND
├─27061 /usr/sbin/httpd -DFOREGROUND
└─27062 /usr/sbin/httpd -DFOREGROUND

Nov 13 03:36:01 vps24699.ovh.net systemd[1]: Reloaded The Apache HTTP Server.

When you modify your vhosts configurations you can check syntax by using commands below:

[debian.linuxnix] root:~/ # apache2ctl configtest
Syntax OK
[debian.linuxnix] root:~/ # apache2ctl -t
Syntax OK

Now, to list all running vhosts, you can use :

[debian.linuxnix] root:~/ # apache2ctl -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
_default_:443          211.ip-5-126-0.eu (/etc/apache2/sites-enabled/001-default-ssl:2)
*:8080                 is a NameVirtualHost
         default server 211.ip-5-126-0.eu (/etc/apache2/sites-enabled/000-default:2)
         port 8080 namevhost 211.ip-5-126-0.eu (/etc/apache2/sites-enabled/000-default:2)
         port 8080 namevhost agency (/etc/apache2/sites-enabled/agency:2)
         port 8080 namevhost janux-dashboard (/etc/apache2/sites-enabled/janux-dashboard:2)
         port 8080 namevhost vh1 (/etc/apache2/sites-enabled/vh1:2)
Syntax OK

You can see that :

  • There are 4 loaded vhosts listening on port 8080.
  • The default vhost is also listening on port 443 for HTTPS.
Related concept:   Linux Bash History: Replace occurrences in last command

On Centos we can use:

[centos.linuxnix] root:~ # apachectl -S
VirtualHost configuration:
*:80                   localhost (/etc/httpd/conf.d/s9s.conf:1)
*:443                  cc.severalnines.local (/etc/httpd/conf.d/ssl.conf:2)
ServerRoot: "/etc/httpd"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/etc/httpd/logs/error_log"
Mutex proxy: using_defaults
Mutex authn-socache: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/run/httpd/" mechanism=default
Mutex mpm-accept: using_defaults
Mutex authdigest-opaque: using_defaults
Mutex proxy-balancer-shm: using_defaults
Mutex rewrite-map: using_defaults
Mutex authdigest-client: using_defaults
Mutex ssl-stapling: using_defaults
PidFile: "/run/httpd/httpd.pid"
User: name="apache" id=48
Group: name="apache" id=48

On Centos listing vhosts with the command above shows some important informations like:

  • Main DocumentRoot : path in which HTML pages are stored (HTML, CSS, PHP, JS,…)
  • Main ErrorLog
  • Pidfile
  • user & group

I hope that this blog helped you. Please visit our blog website for other interesting blogs and feel free to leave your feedbacks and comments. Till next time