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.
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
After the installation is complete, enter the following command to check the PHP version:
php -v
If All goes well and you will see the installed PHP version number and other details.
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.
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.
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 whether 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.
On Windows, integrating PHP with Apache requires the following two steps:
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.
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!