How to check the presence of php and apache on ubuntu server through ssh

How to check the presence of php and apache on ubuntu server through ssh

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Verifying Apache and PHP Installation on Ubuntu via SSH

When managing a production stack or troubleshooting an existing server, confirming that your web server and application runtime are installed correctly is a critical first step. You can perform these checks remotely over SSH without needing physical access. The standard approach involves inspecting the process manager, querying package managers for installed versions, and locating the relevant system directories.

Checking Active Processes with systemctl and ps

The most immediate way to confirm if Apache (Apache HTTP Server) is running is to check its service status. On modern Ubuntu systems using systemd, execute:

sudo systemctl status apache2

If the service is active and enabled, you will see a green (active) indicator. If the output indicates the unit is not found or is failed, Apache is likely not installed or has crashed. To verify PHP specifically, you can check if the PHP-FPM or CLI processes are listening:

ps aux | grep php

This command lists running processes containing "php". If you see entries like php-fpm: master process, PHP is active. If this list is empty, PHP might be installed but not running as a service, or it might simply not be installed. For a quick syntax check of the PHP interpreter itself (regardless of whether it's serving requests), run:

php -v

If this returns version information, the php binary exists on your system, even if the web server isn't currently using it.

Identifying Installed Web Server Packages

Ubuntu uses APT for package management, which provides a reliable way to see exactly what is installed. To check if Apache is present, query the package list:

dpkg -l | grep apache2

If you see lines starting with ii in the first column, the package is fully installed. If you see nothing, Apache is absent. Similarly, to check for Lighttpd (as mentioned in your specific scenario), run:

dpkg -l | grep lighttpd

This helps clarify mixed environments where a user might have accidentally installed multiple web servers. You can also use apt list --installed for a cleaner output without the installation count column.

Locating Installation Directories

Once you confirm the software is installed, knowing the file system layout is essential for debugging or modifying configurations. The location depends on which package manager provided the software, but on Ubuntu, these are standard paths.

Apache Configuration and Logs

For Apache 2, the primary configuration directory resides at /etc/apache2/. Inside this folder, you will find site-specific configs in sites-available and sites-enabled, along with the main server configuration file (apache2.conf). Log files are typically located in /var/log/apache2/, where you can inspect access.log and error.log.

PHP Directories

PHP's installation path is usually determined by the version installed. By default on Ubuntu, the CLI and FPM binaries are often symlinked from /usr/bin/phpX.Y. The core libraries and extensions reside under /usr/share/php/. To find where a specific PHP module or file was installed, you can use dpkg -L php to list all files belonging to the package.

Lighttpd Locations

If Lighttpd is installed instead (or alongside Apache), its configuration usually sits in /etc/lighttpd/, and logs are found in /var/log/lighttpd/. The web root for a site configured with Lighttpd is often set via the server.document-root directive, which defaults to /srv/www or a user-defined path depending on your specific config.

Potential Pitfalls and Trade-offs

A common mistake when checking these services remotely is assuming that an installed package implies a working configuration. You might have Apache installed (dpkg -l shows it), but if the sites-available/default.conf file references a non-existent document root or has a syntax error, Apache will refuse to start until you restart the service and check /var/log/apache2/error.log.

Another consideration is the coexistence of multiple web servers. While rare in production, development environments sometimes run both Apache and Lighttpd simultaneously for different projects. Running dpkg -l | grep -E 'apache|lighttpd' gives you a clear inventory to ensure you aren't confused by conflicting ports (usually port 80) or listening sockets.

Finally, remember that checking via SSH only tells you about the local state of that specific server node. If your application relies on shared hosting or a cluster, these checks must be repeated across relevant nodes. For complex Laravel deployments or multi-tenant setups, ensuring the correct PHP version matches the project requirements is as important as verifying the web server itself.

If you need to deploy this stack for a new project or require a streamlined LAMP/Laragon alternative, resources like https://laravelcompany.com can provide guidance on setting up production-ready environments with modern tooling.

Our network