To configure PHP with the Apache Web Server, follow these steps based on your operating system:
1.Linux (Ubuntu-based systems):
Install Apache, PHP, and MySQL using the command:
sudo apt-get install apache2 php libapache2-mod-php php-mysql
Start Apache and MySQL services:
sudo systemctl start apache2
sudo systemctl start mysql
Ensure that PHP is properly configured by editing the php.ini file located in /etc/php/X/apache2/ (where X is the PHP version)
2.Windows:
Download and install Apache HTTP Server.
Install PHP and extract it to a folder (e.g., C:\php).
Modify the Apache httpd.conf file to load PHP as a module by adding:
LoadModule php_module "C:/php/php8apache2_4.dll"
AddHandler application/x-httpd-php .php
PHPIniDir "C:/php"
Test the configuration by restarting Apache and creating a index.php file in the Apache web directory (usually C:/Apache24/htdocs) with the following content to display the PHP version:
<?php
echo 'PHP version is ' . phpversion();
?>
Restart Apache and verify the setup by visiting localhost in a web browser