Apache and PHP are widely used tools in web development. Compiling and installing them allows for greater flexibility in customizing and managing your server environment. This article will walk you through the installation process with detailed steps and code examples.
Before starting the installation, make sure the necessary compilation tools and dependencies are installed on your system. Here are the commands commonly used for installation:
sudo apt update
sudo apt install build-essential
sudo apt install libapr1-dev libaprutil1-dev
sudo apt install libxml2-dev
Next, download the Apache and PHP source packages from their official websites, extract them to an appropriate directory.
wget https://www.apache.org/dist/httpd/httpd-2.4.41.tar.gz
tar -zxvf httpd-2.4.41.tar.gz
wget https://www.php.net/distributions/php-7.3.11.tar.gz
tar -zxvf php-7.3.11.tar.gz
After extracting the Apache files, navigate to the Apache directory and execute the following commands to compile and install it:
cd httpd-2.4.41
./configure --prefix=/path/to/install/dir
make
make install
In the above commands, --prefix=/path/to/install/dir specifies the installation directory. You can modify the path as needed.
Once Apache is installed, it's time to compile and install PHP. Navigate to the extracted PHP directory and run the following commands:
cd php-7.3.11
./configure --prefix=/path/to/install/dir --with-apxs2=/path/to/apache/bin/apxs
--with-mysqli --with-pdo-mysql
make
make install
Here, --prefix=/path/to/install/dir specifies the installation directory for PHP, and --with-apxs2=/path/to/apache/bin/apxs specifies the path to Apache. Additional options can be added to enable PHP extensions if needed.
After installation, you need to modify Apache's configuration file httpd.conf to load the PHP module:
LoadModule php7_module /path/to/install/dir/libphp7.so
AddType application/x-httpd-php .php
Save the configuration file and restart the Apache server to enable PHP.
By following these steps, you can successfully compile and install Apache and PHP in a specified directory. This method allows you to customize your server environment without affecting the existing system configurations. We hope this guide helps you complete your installation smoothly.