Installing and Configuring Apache, PHP, and MariaDB/MySQL on Windows

Home Installing and Configuring Apache, PHP, and MariaDB/MySQL on Windows

Installing and Configuring Apache, PHP, and MariaDB/MySQL on Windows

Setting up a local development environment with Apache, PHP, and MariaDB/MySQL on Windows allows you to develop and test web applications efficiently. This article will guide you through the installation and configuration process step-by-step.

Why you want to configure yourself and not use XAMPP ?

  • XAMPP is easy to install and configures all but you may not get the latest version of PHP, Apache and Maria DB
  • Manually configuring each component provides a deeper understanding of how web servers, PHP, and databases work together. This knowledge can be valuable for troubleshooting and optimizing your setup.
  • For production environments that don’t use XAMPP, manually setting up your development environment to match the production environment as closely as possible can help prevent deployment issues.
  • When you configure the components manually, you have the opportunity to optimize each one individually, which can lead to better performance.
  • XAMPP comes with many bundled components that you might not need. Manually configuring your environment means you only install and run what’s necessary, potentially reducing system overhead.

Prerequisites

  • A computer running Windows 10 or later
  • Administrator privileges

Step-by-Step Guide

Step 1: Install Apache

  • Download Apache
    • Go to the Apache website.
    • Download the latest version of the Apache HTTP Server.
  • Extract and Configure Apache
    • Extract the downloaded ZIP file to C:\Apache24
    • Open the C:\Apache24\conf\httpd.conf file in a text editor.
    • Change the ServerRoot directive to: ServerRoot "C:/Apache24"
    • Set the Listen directive to the desired port, e.g.,: Listen 80
    • Change the ServerName directive to: ServerName localhost:80
  • Install Apache as a Windows Service
    • Open Command Prompt as an administrator.
    • Navigate to the bin directory: cd C:\Apache24\bin
    • Install the Apache service: httpd.exe -k install
    • Start the Apache service: httpd.exe -k start

Step 2: Install PHP

  • Download PHP
    • Go to PHP website
    • Download the latest Thread Safe version of PHP.
    • Note: You need to download the ZIP file
  • Extract and Configure PHP
    • Extract the downloaded ZIP file to C:\PHP.
    • Rename php.ini-development to php.ini.
    • Open php.ini in a text editor and uncomment extension_dir = "ext"
    • Uncomment the necessary extensions you want to enable, e.g.: extension=mysqli
  • Add PHP to the system PATH:
    • Open Settings > System > Advanced system settings.
    • Click on Environment Variables.
    • Under System variables, select Path and click Edit.
    • Add C:\PHP to the list.
  • Configure Apache to Use PHP
    • Open the C:\Apache24\conf\httpd.conf file in a text editor.
    • Add the following lines at the end of the file:
    • LoadModule php_module "C:/PHP/php8apache2_4.dll"
      AddHandler application/x-httpd-php .php
      PHPIniDir "C:/PHP"
      
    • Restart the Apache service: httpd.exe -k restart

Step 3: Install MariaDB/MySQL

  • Download MariaDB/MySQL
    • Go to the MariaDB or MySQL website.
    • Download the latest stable release.
  • Install MariaDB/MySQL
    • Run the installer and follow the setup wizard.
    • Choose the default options unless you have specific requirements.
    • Note the root password set during the installation process.

Step 4: Configure PHP to Use MariaDB/MySQL

  • Open the php.ini file in a text editor.
  • Enable the MySQL extension: extension=mysqli and extension=pdo_mysql
    • Enable pdo only if you want to use PDO for connecting with mysql
  • Restart the Apache service: httpd.exe -k restart

Step 5: Test the Installation

  • Create a new file named info.php in the C:\Apache24\htdocs directory.
  • Add the following code to info.php
<?php
phpinfo(); 
?>

Connect to MariaDB/MySQL

  • Create a new file named db_test.php in the C:\Apache24\htdocs directory.
  • Add the following code to db_test.php:
<?php
$mysqli = new mysqli("localhost", "root", "your_password", "mysql");
if ($mysqli->connect_error) {
die("Connection failed: " . $mysqli->connect_error);
}
echo "Connected successfully";
?>

Conclusion

You have successfully installed and configured Apache, PHP, and MariaDB/MySQL on your Windows machine. This setup will provide you with a robust local development environment for your web projects

Thankyou for reading!

Get In Touch

Guru Gobind Singh Nagar, Jalandhar, Punjab, India

Quick Links

© 2024 Khaalis Technologies. All Rights Reserved. Designed by HTML Codex