- 3 Ways to Check Apache Server Status and Uptime in Linux
- 1. Systemctl Utility
- 2. Apachectl Utilities
- On Debian/Ubuntu
- On RHEL/CentOS
- 3. ps Utility
- Полезные команды для управления Apache в Linux
- Про Linux за 5 минут
- Установка Apache Server
- Проверка версии Apache
- How to check if a web server is installed in a Linux machine? [closed]
- 2 Answers 2
3 Ways to Check Apache Server Status and Uptime in Linux
Apache is a world’s most popular, cross platform HTTP web server that is commonly used in Linux and Unix platforms to deploy and run web applications or websites. Importantly, it’s easy to install and has a simple configuration as well.
In this article, we will show how to check Apache web server uptime on a Linux system using different methods/commands explained below.
1. Systemctl Utility
Systemctl is a utility for controlling the systemd system and service manager; it is used it to start, restart, stop services and beyond. The systemctl status sub-command, as the name states is used to view the status of a service, you can use it for the above purpose like so:
$ sudo systemctl status apache2 #Debian/Ubuntu # systemctl status httpd #RHEL/CentOS/Fedora
2. Apachectl Utilities
Apachectl is a control interface for Apache HTTP server. This method requires the mod_status (which displays info about the server is performing including its uptime) module installed and enabled (which is the default setting).
On Debian/Ubuntu
The server-status component is enabled by default using the file /etc/apache2/mods-enabled/status.conf.
$ sudo vi /etc/apache2/mods-enabled/status.conf
On RHEL/CentOS
To enable server-status component, create a file below.
# vi /etc/httpd/conf.d/server-status.conf
and add the following configuration.
SetHandler server-status #Require host localhost #uncomment to only allow requests from localhost
Save the file and close it. Then restart the web server.
If you are primarily using a terminal, then you also need a command line web browser such as lynx or links.
$ sudo apt install lynx #Debian/Ubuntu # yum install links #RHEL/CentOS
Then run the command below to check the Apache service uptime:
Alternatively, use the URL below to view the Apache web server status information from a graphical web browser:
http://localhost/server-status OR http:SERVER_IP/server-status
3. ps Utility
ps is a utility which shows information concerning a selection of the active processes running on a Linux system, you can use it with grep command to check Apache service uptime as follows.
- -e – enables selection of every processes on the system.
- -o – is used to specify output (comm – command, etime – process execution time and user – process owner).
# ps -eo comm,etime,user | grep apache2 # ps -eo comm,etime,user | grep root | grep apache2 OR # ps -eo comm,etime,user | grep httpd # ps -eo comm,etime,user | grep root | grep httpd
The sample output below shows that apache2 service has been running for 4 hours, 10 minutes and 28 seconds (only consider the one started by root).
Lastly, check out more useful Apache web server guides:
In this article, we showed you three different ways to check Apache/HTTPD service uptime on a Linux system. If you have any questions or thoughts to share, do that via the comment section below.
Полезные команды для управления Apache в Linux
В этом руководстве мы опишем некоторые из наиболее часто используемых команд управления службами Apache (HTTPD) , которые полезно знать, разработчику или системному администратору, и держать эти команды под рукой. Мы покажем команды для Systemd и SysVinit.
Убедитесь, что следующие команды должны выполняться от имени пользователя root или sudo и работать с любым дистрибутивом Linux, таким как CentOS, RHEL, Fedora, Debian и Ubuntu.
Про Linux за 5 минут
Установка Apache Server
$ sudo apt install apache2 [On Debian/Ubuntu] $ sudo yum install httpd [On RHEL/CentOS] $ sudo dnf install httpd [On Fedora 22+] $ sudo zypper install apache2 [On openSUSE]
Проверка версии Apache
Чтобы проверить установленную версию вашего веб-сервера Apache в вашей системе Linux, выполните следующую команду.
Server version: Apache/2.4.6 (CentOS) Server built: May 5 2019 01:47:09
Если вы хотите увидеть номер версии Apache и параметры компиляции, используйте флаг -V, как показано ниже.
Server version: Apache/2.4.6 (CentOS) Server built: May 5 2019 01:47:09 Server's Module Magic Number: 20120211:24 Server loaded: APR 1.4.8, APR-UTIL 1.5.2 Compiled using: APR 1.4.8, APR-UTIL 1.5.2 Architecture: 64-bit Server MPM: prefork threaded: no forked: yes (variable process count) Server compiled with. -D APR_HAS_SENDFILE -D APR_HAS_MMAP -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled) -D APR_USE_SYSVSEM_SERIALIZE -D APR_USE_PTHREAD_SERIALIZE -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT -D APR_HAS_OTHER_CHILD -D AP_HAVE_RELIABLE_PIPED_LOGS -D DYNAMIC_MODULE_LIMIT=256 -D HTTPD_ROOT="/etc/httpd" -D SUEXEC_BIN="/usr/sbin/suexec" -D DEFAULT_PIDLOG="/run/httpd/httpd.pid" -D DEFAULT_SCOREBOARD="logs/apache_runtime_status" -D DEFAULT_ERRORLOG="logs/error_log" -D AP_TYPES_CONFIG_FILE="conf/mime.types" -D SERVER_CONFIG_FILE="conf/httpd.conf"
Проверка на ошибки синтаксиса конфигурации Apache
Чтобы проверить ваши файлы конфигурации Apache на наличие любых синтаксических ошибок, выполните следующую команду, которая проверит правильность файлов конфигурации, прежде чем перезапускать службу.
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using merionet.ru. Set the 'ServerName' directive globally to suppress this message Syntax OK
Запуск сервиса Apache
------------ On CentOS/RHEL ------------ $ sudo systemctl start httpd [On Systemd] $ sudo service httpd start [On SysVInit] ------------ On Ubunt/Debian ------------ $ sudo systemctl start apache2 [On Systemd] $ sudo service apache2 start [On SysVInit]
Включение службы Apache
Предыдущая команда пока только запускает службу Apache, чтобы включить автозапуск при загрузке системы, выполните следующую команду.
------------ On CentOS/RHEL ------------ $ sudo systemctl enable httpd [On Systemd] $ sudo chkconfig httpd on [On SysVInit] ------------ On Ubunt/Debian ------------ $ sudo systemctl enable apache2 [On Systemd] $ sudo chkconfig apache2 on [On SysVInit]
Перезапуск службы Apache
------------ On CentOS/RHEL ------------ $ sudo systemctl restart httpd [On Systemd] $ sudo service httpd restart [On SysVInit] ------------ On Ubunt/Debian ------------ $ sudo systemctl restart apache2 [On Systemd] $ sudo service apache2 restart [On SysVInit]
Просмотр состояния сервиса Apache
Чтобы проверить информацию о состоянии времени выполнения службы Apache, выполните следующую команду.
------------ On CentOS/RHEL ------------ $ sudo systemctl status httpd [On Systemd] $ sudo service httpd status [On SysVInit] ------------ On Ubunt/Debian ------------ $ sudo systemctl status apache2 [On Systemd] $ sudo service apache2 status [On SysVInit]
Перезагрузка сервиса Apache
Если вы внесли какие-либо изменения в конфигурацию сервера Apache, вы можете указать службе перезагрузить свою конфигурацию, выполнив следующую команду.
------------ On CentOS/RHEL ------------ $ sudo systemctl reload httpd [On Systemd] $ sudo service httpd reload [On SysVInit] ------------ On Ubunt/Debian ------------ $ sudo systemctl reload apache2 [On Systemd] $ sudo service apache2 reload [On SysVInit]
Остановка службы Apache
------------ On CentOS/RHEL ------------ $ sudo systemctl stop httpd [On Systemd] $ sudo service httpd stop [On SysVInit] ------------ On Ubunt/Debian ------------ $ sudo systemctl stop apache2 [On Systemd] $ sudo service apache2 stop [On SysVInit]
Показать справку Apache Command
И последнее, но не менее важное: вы можете получить справку о служебных командах Apache в systemd, выполнив следующую команду.
Usage: httpd [-D name] [-d directory] [-f file] [-C "directive"] [-c "directive"] [-k start|restart|graceful|graceful-stop|stop] [-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S] [-X] Options: -D name : define a name for use in directives -d directory : specify an alternate initial ServerRoot -f file : specify an alternate ServerConfigFile -C "directive" : process directive before reading config files -c "directive" : process directive after reading config files -e level : show startup errors of level (see LogLevel) -E file : log startup errors to file -v : show version number -V : show compile settings -h : list available command line options (this page) -l : list compiled in modules -L : list available configuration directives -t -D DUMP_VHOSTS : show parsed vhost settings -t -D DUMP_RUN_CFG : show parsed run settings -S : a synonym for -t -D DUMP_VHOSTS -D DUMP_RUN_CFG -t -D DUMP_MODULES : show all loaded modules -M : a synonym for -t -D DUMP_MODULES -t : run syntax check for config files -T : start without DocumentRoot(s) check -X : debug mode (only one worker, do not detach)
На этом пока все! В этой статье мы объяснили наиболее часто используемые команды управления службами Apache / HTTPD, которые полезно будет знать, включая запуск, включение, перезапуск и остановку Apache.
How to check if a web server is installed in a Linux machine? [closed]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
- How to check if a web server is installed in a Linux machine? I dont know if any web server installed or not. If installed I would like to use it to build a web service.
- If a web Server installed, how to check where it is installed, path , properties etc..
2 Answers 2
If there’s a webserver active it’s easy enough to tell, but if the webserver is installed, but not active, it’s more difficult, since there are probably a dozen different webservers that might be installed (but haven’t been started). You can tell if there’s a web server active on the default port for http (80) with:
Where hostname is the hostname or IP address of the machine of interest. If you have shell access to the machine of interest, then you can just use localhost , for example, if there is a webserver active, you will see something like:
$ telnet localhost 80 Trying 127.0.0.1. Connected to localhost. Escape character is '^]'.
If you type something like:
You will get an error message that may tell you something about what webserver is installed. For example:
Not Found
The requested URL /status was not found on this server.
Apache/2.2.22 (Ubuntu) Server at 127.0.1.1 Port 80 Connection closed by foreign host.
This would tell you that Apache version 2.2.22 is installed and running on the machine that you’re running the shell on.
If there is no webserver active, on the other hand, you will see something like:
$ telnet localhost 80 Trying 127.0.0.1. telnet: Unable to connect to remote host: Connection refused
In this case, things get rather more distribution-specific (what you find and where is dependent on the Linux distribution installed). You can try to see if there’s a webserver installed, but not active, by checking for common service names or installed files and directories. You could try:
This at least tells you that Apache is installed, but not running, whereas:
apache2: unrecognized service
. would tell you that Apache is not installed. There could, however, be another webserver installed.
You might also check to see if there’s a /var/www/ directory, or another directory where webservers commonly store files by default, e.g.:
Unfortunately, it’s hard to give a good answer without knowing what distribution (e.g. Debian, Ubuntu, RedHat, CentOS, Fedora, . ) is installed on the machine of interest.