On a Linux system, ensuring PHP is running properly is a critical task for developers and system administrators. As PHP plays a vital role in building dynamic websites and applications, keeping it active ensures the stability of your web environment. This article outlines several reliable ways to check whether PHP is up and running on your Linux server.
The most straightforward method is to use the terminal to look for PHP-related processes. Run the following command:
ps aux | grep php
This will list all active processes associated with PHP. If you see multiple PHP-related entries, that means PHP is currently running. If there’s no output, PHP might need to be started manually.
If your setup uses PHP-FPM (FastCGI Process Manager), you can check its status using the systemctl command:
systemctl status php7.x-fpm
Replace “7.x” with the actual version of PHP installed on your server. For example:
systemctl status php7.4-fpm
If the output includes “active (running)”, the PHP-FPM service is running correctly. If it is not active, you can start it using this command:
systemctl start php7.x-fpm
Another effective way to confirm PHP is working is to use the phpinfo() function. Create a file named info.php with the following content:
<?php
phpinfo();
?>
Place this file in your web server’s root directory and access it via a browser, e.g., http://localhost/info.php. If PHP is running, it will display a detailed page of configuration info. If not, double-check your web server settings.
To further verify PHP’s ability to handle requests, use the curl command:
curl -I http://localhost/info.php
If you receive an HTTP response, PHP is working as expected. If there’s an error, check your web server configuration or verify that PHP-FPM is properly connected to the server.
These methods allow you to quickly determine whether PHP is running on your Linux server. Regularly checking your PHP service helps maintain a reliable and stable web environment. Mastering these commands will enable you to troubleshoot and manage your server with confidence.