Home >Operation and Maintenance >Linux Operation and Maintenance >How to install and configure the PHP operating environment under Linux and Windows

How to install and configure the PHP operating environment under Linux and Windows

PHPz
PHPzforward
2023-06-03 22:43:171419browse

Installing PHP on Linux

You can install it directly from the package manager of the Linux distribution, because most of them already have PHP built-in. PHP and its related dependencies can be installed in Ubuntu, Debian, CentOS and other systems through the following command:

sudo apt-get install php

After the installation is complete, enter the following command to check the version of PHP:

php -v

If All goes well and you will see the installed PHP version number and other details.

Installing PHP on Windows

Unlike Linux, Windows requires manual downloading and installation of the PHP operating environment. First, you need to download the Windows version of PHP from the PHP official website.

Next, unzip the downloaded file and place it in an easily accessible folder. For example, you can unzip it into the C:\php directory.

In the Windows environment variable settings, add C:\php to the system path. This action ensures that the PHP executable is accessible from anywhere.

Integrating PHP and Web Server

PHP needs to run on the web server to be able to handle requests from clients. Generally, the most commonly used web servers are Apache or Nginx. In this article, we will explain how to integrate PHP with Apache.

Integrating PHP and Apache on Linux

When you install Apache on Linux, you can install the integration module with PHP by using the following command:

sudo apt-get install libapache2-mod-php

Then, restart the Apache server:

sudo systemctl restart apache2

Open the following file using an editor to check if the PHP module has been enabled:

/etc/apache2/mods-enabled/php7.4.conf

Confirm that the file contains the following content:

<FilesMatch ".+\.ph(p[3457]?|t|tml)$">
    SetHandler application/x-httpd-php
</FilesMatch>

If all goes well, the PHP module has been successfully enabled and you can start writing PHP code.

Integrating PHP and Apache on Windows

On Windows, integrating PHP with Apache requires the following two steps:

  1. Enable the PHP module in the Apache configuration file.

  2. Copy the PHP configuration file to the bin directory of Apache.

Open the following file to enable the PHP module:

C:\xampp\apache\conf\httpd.conf

Find the following line:

#LoadModule php7_module modules/libphp7.so

Uncomment the line:

LoadModule php7_module "C:\php\php7apache2_4.dll"

Then, copy the following file:

C:\php\php.ini-development

and rename it to php.ini. Then copy the file to Apache's bin directory:

C:\xampp\apache\bin\php.ini

Finally, restart the Apache server.

The above is the detailed content of How to install and configure the PHP operating environment under Linux and Windows. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete