Apache and PHP are two indispensable key components in web development, and their installation and configuration are very important. Below we will explain in detail how to install and configure Apache and PHP.
1. Apache installation and configuration
Apache is an open source HTTP server software that can run on a variety of operating systems, such as Windows, Linux, Unix, etc. There are two ways to install Apache: binary package and source code package.
We can download the binary package suitable for the current operating system from the Apache official website (http://httpd.apache.org) for installation.
Step 1: Download and decompress the binary package
Download the corresponding binary package from the official website, and then decompress it to the directory you want to install.
Step 2: Configure Apache
Open the conf directory in the decompressed directory, find the httpd.conf file in it, and use a text editor to open it for editing. Edit the following configuration according to your needs:
Step 3: Start and test
Start command:
./apachectl start
Enter http://localhost on the browser Or http://127.0.0.1 for testing.
Step 1: Download and decompress the source code package
Download the source code package suitable for your operating system from the Apache official website , and then unzip it into the directory where you want to install it.
Step 2: Configure Apache
Open the terminal, enter the directory where the installation package is located, and execute the following command to configure:
./configure
make
make install
Step 3: Start and test
Start command:
/usr/local/apache2/bin/apachectl start
Enter on the browser http://localhost or http://127.0.0.1 for testing.
2. PHP installation and configuration
PHP is a general scripting language, mainly used in Web development and can be embedded in HTML. There are two ways to install PHP: binary package and source code package.
Step 1: Download and install the binary package
We can download it from the PHP official website (http://www.php.net ) Download the binary package suitable for the current operating system and install it.
Step 2: Configure PHP
Find the php.ini-development (or php.ini-production) file in the installation directory, copy it, and name it php.ini. Then edit it to suit your needs.
Step 3: Enable PHP
Open Apache's configuration file httpd.conf, find the following two lines of code in it, and uncomment them:
LoadModule php5_module modules/libphp5.so
AddHandler php5-script .php
After starting the Apache server, test whether it is successful.
Step 1: Download and decompress the source code package
Download the source code package suitable for your operating system from the PHP official website , and then unzip it into the directory where you want to install it.
Step 2: Configure PHP
Open the terminal, enter the directory where the installation package is located, and execute the following command to configure:
./configure
make
make install
Step 3: Enable PHP
Open Apache's configuration file httpd.conf, find the following two lines of code in it, and uncomment them:
LoadModule php5_module modules/ libphp5.so
AddHandler php5-script .php
After starting the Apache server, test whether it is successful.
Summary
The above is the installation and configuration method of Apache and PHP. If you are a web developer, this knowledge is essential. But no matter which way you install, you need to first understand your operating system and current environment configuration. Only in this way can you better choose according to your own needs and maintain efficient development at any time.
The above is the detailed content of Detailed explanation of how to install and configure Apache and PHP. For more information, please follow other related articles on the PHP Chinese website!