Home  >  Article  >  Backend Development  >  How to compile and install Apache PHP in the directory

How to compile and install Apache PHP in the directory

王林
王林Original
2024-03-09 09:27:031225browse

如何在目录下进行Apache PHP编译安装

How to compile and install Apache PHP in the directory requires specific code examples

Apache and PHP are two important tools often used in web development. Compilation and installation can help us better customize and manage the server environment. This article will introduce in detail how to compile and install Apache PHP in the directory, covering specific code examples and step instructions.

Step One: Preparation
Before you start, make sure you have the necessary compilation tools and dependencies installed in your system. Normally, the following is the command to install these tools:

sudo apt update
sudo apt install build-essential
sudo apt install libapr1-dev libaprutil1-dev
sudo apt install libxml2-dev

Step 2: Download the source code package
First, you need to download the source code package of Apache and PHP. You can download the latest stable version directly from the official website and extract it to a suitable 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

Step 3: Compile and install Apache
Next, start compiling and installing Apache. First enter the decompressed Apache directory and execute the following command:

cd httpd-2.4.41
./configure --prefix=/path/to/install/dir
make
make install

In the above command, --prefix=/path/to/install/dir specifies the installation directory. You can follow Customize the installation path according to the actual situation.

Step 4: Compile and install PHP
After completing the installation of Apache, the next step is to compile and install PHP. Enter the decompressed PHP directory and execute the following command:

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

In the above command, --prefix=/path/to/install/dir specifies the PHP installation directory, --with-apxs2=/path/to/apache/bin/apxsSpecifies the installation path of Apache. In addition, other parameters can be added as needed to enable different extended functions.

Step 5: Configure Apache and PHP
After the installation is complete, you need to configure Apache to load the PHP module. Edit the Apache configuration file httpd.conf and add the following content:

LoadModule php7_module /path/to/install/dir/libphp7.so
AddType application/x-httpd-php .php

After saving the configuration file, restart the Apache server to make PHP take effect.

Summary
Through the above steps, you can successfully compile and install Apache PHP in the specified directory. This method facilitates the management, control and customization of the server environment, and can also avoid affecting the existing configuration of the system itself. I hope this article can help you successfully complete the compilation and installation work!

The above is the detailed content of How to compile and install Apache PHP in the directory. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn