How to Install Apache PHP Module on Ubuntu or Debian

PHP Apache Ubuntu Techhyme

In the realm of web development, integrating PHP with the Apache server is a common requirement. To achieve this synergy, the installation of the Apache PHP module becomes imperative. This module acts as a bridge, enabling Apache to interpret and execute PHP code seamlessly. Without it, Apache would treat PHP files as plain text, failing to comprehend the intricacies of PHP code.

In this guide, we will walk through the steps to install the Apache PHP module on Ubuntu or Debian-based systems.

Step 1: Prerequisites

Before diving into the installation process, ensure the following prerequisites are met:

  • A running Ubuntu or Debian server.
  • Sudo or root access to execute privileged commands.
  • Availability of the apt or apt-get utility on your server.

Step 2: Update Your Server

To ensure that your system is equipped with the latest bug fixes and security updates, execute the following command:

sudo apt update && sudo apt upgrade

Apache PHP

Step 3: Install Apache PHP Module

Proceed to install the Apache PHP module from the default Ubuntu repository using the following command:

sudo apt install php libapache2-mod-php

This command downloads and installs the required package along with its dependencies.

Apache PHP Install 2

Step 4: Verify Installation

Confirm the successful installation of the module by executing the following command:

apachectl -M | grep -i php

This command should display information indicating that the PHP module is loaded.

Step 5: Using PHP in Apache Server

Now that the PHP module is installed, let’s test its functionality by running a simple PHP script on the Apache server. Create a file named `index.php` in the `/var/www/html/` directory with the following content:

Command: sudo nano /var/www/html/index.php

<!DOCTYPE html>
<html>
<body>

<?php
phpinfo()
?>

</body>
</html>

This script uses the `phpinfo()` function to display the current PHP configuration.

PHPinfo

Output

When you access this script through your Apache server, the output should resemble the PHP information page, showcasing details about your PHP configuration.

Conclusion:

Congratulations! You have successfully installed the Apache PHP module on your Ubuntu or Debian-based system. This integration enables your Apache server to handle PHP scripts seamlessly, opening the door to dynamic web development possibilities. Feel free to explore additional PHP functionalities and configurations to enhance your web projects.

You may also like:

Related Posts

Leave a Reply