Apache and PHP are necessary components for building a web server. They need to be compiled and installed in the Linux system. This article mainly introduces how to set the installation directory during compilation and installation to facilitate subsequent management.
1. Prerequisites
Before compiling and installing Apache and PHP, you need to ensure that the corresponding development tools have been installed, including make, gcc, g, etc. , otherwise it will not be compiled and installed normally.
2. Compile Apache
1. Download the source code package
Official website download address:https://httpd.apache.org/ download.cgi
For example, download the source code package with version 2.4.46:
wget https://archive.apache.org/dist/httpd/httpd-2.4.46.tar.gz
2. Unzip the source code package
tar zxvf httpd-2.4.46.tar.gz
3. Enter the source code directory
cd httpd-2.4.46
4. Configure compilation options
We can configure compilation options through the configure command, where "--prefix" specifies the installation directory. For example:
./configure --prefix=/usr/local/apache2
Other commonly used options include "--enable-ssl" to enable SSL support, "--enable-so" to enable dynamic sharing modules, etc. More detailed options can be viewed through "./configure --help".
5. Compile and install
make make install
3. Compile PHP
1. Download the source code package
Official website download address: https://www.php.net/downloads.php
For example, download the source code package of version 7.4.14:
wget https://www.php.net/distributions/php-7.4.14.tar.gz
2. Unzip the source code package
tar zxvf php-7.4.14.tar.gz
3. Enter the source code directory
cd php-7.4.14
4. Configure compilation options
We can configure compilation options through the configure command, where "--prefix" specifies the installation directory and needs to be specified at the same time "--with-apxs2" specifies the path to Apache's apxs2 executable file. For example:
./configure --prefix=/usr/local/php \ --with-apxs2=/usr/local/apache2/bin/apxs \ --with-mysqli \ --with-zlib \ --with-openssl
Other commonly used options include "--with-mysqli" to enable MySQLi support, "--with-zlib" to enable zlib compression support, "--with-openssl" to enable OpenSSL support, etc. More detailed options can be viewed through "./configure --help".
5. Compile and install
make make install
4. Summary
When compiling and installing Apache and PHP, configure the "--prefix" option The installation directory can be specified. When specifying the installation directory, we can flexibly set it according to actual needs to facilitate subsequent management.
The above is the detailed content of How to configure the installation directory when compiling and installing apache and php. For more information, please follow other related articles on the PHP Chinese website!