Apache is an extremely popular software that functions on HTTP servers. Generally speaking, its job is to create a kind of connection between a browser and a server. This soft is compatible with any OS, starting from Windows and ending with Unix.
The client and the server interact through HTTP protocol, and Apache is responsible for its secure and smooth functioning. It is really customized due to the open-source infrastructure. That helps users to adapt the code to the type of site.
Here in this article, you will get helpful instructions about the identification of the uptime of the server by applying various commands and methods on Linux.
Systemctl Command
This command is extremely useful for managing systems and service manager for the users of Linux. It may also be applied for the checks of the status of the web server. Here is a guide on how to show the info about the status of the server by applying this command-line.
- Open a window on the sys.
- Check the status of the service, by filling in the next command:
sudo systemctl status apache2
- If it is functioning properly, you will see tasks with characteristics: memory, CPU, and CGroup. In case the output is different then Apache is not functioning properly.
ps Command
This command line shows data about the active processes. For different systems, the typed command line can be different. For instance, for RPM, it looks like this:
# pgrep httpd | head -1
10915
For those who utilize Debian:
# pgrep apache2 | head -1
1111
Once you received the data about PID, type the next line:
# ps -p 10915 -o etime
The elapsed data that is shown is the same as uptime and it characterizes the time when the process actually started.
Apachectl Command
The next variant of determining the status is by applying apachectl. This is a standard instrument that comes together with a web server pack. Here are the steps you will need to make everything properly:
- Open a window.
- To check the status, fill in the next command:
sudo apachectl status
- If everything functions properly then you will see such characteristics as MPM, loaded APR ver, server ver, server built, and others. Otherwise, there will be an error on the screen.
Checking uptime via mod_status module
Apache has a built-in module which is called mod_status and it is applied to show real-time status of the server. This module shows the following info: CPU use, uptime, general accesses, and a couple of other vital info about the server. To start this module, use the next steps:
- Open a window.
- Insert the command:
sudo a2enmod status
- Edit configuration with the text editor you are using:
sudo nano /etc/apache2/mods-enabled/status.conf
- Fill in the following lines to the configuration file in order to get access to the status from the host:
<Location /server-status>
SetHandler server-status
Require local
</Location>
- Save changes that were made and close the file.
- Restart the server with such command line:
sudo systemctl restart apache2
- To get access to the status of the server via a web browser, type the next:
http://locahost/server-status
- If everything was done as should then the data, about the status page with all the needed information about uptime, CPU use, total accesses, and others, will be shown. Uptime shows the monitoring information beginning from the time the server was restarted.
Applying proc system file
Via procfs system file that is in the Unix OS, you can also get the major data about the processes. The information that is stored in it cares mainly about hardware config, the memory of the system, devices mounted, and others.
At first, you should get PID results as with ps Command, and then type the next line:
# ls -ld/proc/10915
Other helpful recommendations about Apache use
- There can be lots of confusion if you are using several Apache hosts and their names are either similar or identical. To change this thing, you can apply ServerName directive in the config. By entering this file, you can type each of the hosts’ name.
- The most important thing is the security of the server to ensure that you have all the updates, and the system can properly function. You can type the below-mentioned command, it is assigned for Debian and Ubuntu clients.
sudo apt-get update
sudo apt-get upgrade
- Backups of the server should be conducted regularly, in order to guarantee the smooth functioning of the system. The most used tools for this process are tar, rsync, or scp. They are working by creating backups of the files.
To conclude, we have shared the main methods for determining Apache server status on Linux. So, now you have a couple of functional variants to try and choose the one that works better for your specific case. By monitoring the system regularly, you can be sure that everything functions smoothly and quickly.