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
Release: 2023-06-03 22:43:17
forward
1404 people have browsed it

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
Copy after login

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

php -v
Copy after login

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
Copy after login

Then, restart the Apache server:

sudo systemctl restart apache2
Copy after login

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

/etc/apache2/mods-enabled/php7.4.conf
Copy after login

Confirm that the file contains the following content:

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

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
Copy after login

Find the following line:

#LoadModule php7_module modules/libphp7.so
Copy after login

Uncomment the line:

LoadModule php7_module "C:\php\php7apache2_4.dll"
Copy after login

Then, copy the following file:

C:\php\php.ini-development
Copy after login

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

C:\xampp\apache\bin\php.ini
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template