Home  >  Article  >  Backend Development  >  Detailed explanation of how to install and configure Apache and PHP

Detailed explanation of how to install and configure Apache and PHP

PHPz
PHPzOriginal
2023-04-10 09:45:292954browse

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.

  1. Binary package installation

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:

  • ServerName The host name or IP address of the server
  • DocumentRoot Default document directory
  • Directory can set the permissions you want to access and Table of contents and so on.

Step 3: Start and test

Start command:

./apachectl start

Enter http://localhost on the browser Or http://127.0.0.1 for testing.

  1. Source code package installation

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.

  1. Binary package installation

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.

  • extension_dir sets the extension directory of PHP
  • error_reporting sets the error reporting level of PHP
  • date.timezone sets the time zone and so on.

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.

  1. Source code package installation

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!

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