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

PHPz
Release: 2023-03-23 15:40:02
Original
1628 people have browsed it

In modern web development, PHP has become a very popular language. Everything from simple scripts to large back-end applications can be implemented using PHP.

PHP is a scripting language that needs to be run on the server. Therefore, we need to install the PHP running environment and integrate PHP with the web server (such as Apache or Nginx). Currently, the latest version of PHP is PHP 8. In this article, we will explain how to install PHP in Linux and Windows operating systems.

Installing PHP on Linux

Most Linux distributions already have PHP built-in, so it can be installed directly from the package manager. In Ubuntu, Debian, CentOS and other systems, you can use the following command to install PHP and other dependencies:

sudo apt-get install php
Copy after login

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

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 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.

Open the Windows environment variable settings and 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 whether 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.

Conclusion

In this article, we covered how to install PHP on Linux and Windows and integrate it with the Apache server. This is an important basic knowledge for PHP developers. Hopefully this article will help you get started writing PHP code.

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:
php
source:php.cn
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!