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.
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.
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 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.
On Windows, integrating PHP with Apache requires the following two steps:
Enable the PHP module in the Apache configuration file.
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!