Home > Article > Operation and Maintenance > How to configure and install php on Windows and Linux
Configuring and Installing PHP on Windows Operating System
Step 1: Download PHP
First, we need to download it from php.net Windows version of PHP. Download the correct PHP version based on your computer architecture (32-bit or 64-bit).
Step 2: Install PHP
After the download is complete, unzip the downloaded zip file and place it in the C:\php\ directory. Then, create a new file called php.ini in the C:\php\ directory and add the following content to the file:
extension_dir = "C:\php\ext\"
This code tells PHP where to look for extension files.
Step 3: Configure PHP
In the php.ini file, uncomment the following:
extension=php_mysql.dll extension=php_mysqli.dll
These codes tell PHP to enable support for the MySQL database.
Step 4: Configure environment variables
It is common to use PHP and Apache servers on Windows operating systems. To do this, the PHP and Apache server paths need to be added to the Windows environment variables. Use the following steps to configure environment variables:
Right-click This PC and select Properties.
Click "Advanced system settings" in the left panel.
Click the "Environment Variables" button.
Have found "Path" under system variables and click "Edit".
Click the "New" button in the pop-up window and add the PHP and Apache server paths. For example, add "C:\php\" and "C:\Apache24\bin\".
Step 5: Start the Web Server
If you are using the Apache server, open the "bin" folder in the Apache server installation directory and start it with the following command Apache Server:
httpd.exe -k start
Step 6: Test PHP
Now, PHP has been successfully installed and configured on your Windows computer. To test PHP, create a new file called phpinfo.php and add the following content to the file:
<code><pre class="brush:php;toolbar:false"><?php phpinfo(); ?></pre>
Enter "http://localhost/phpinfo.php" in the web browser. If you see the PHP information page, it means PHP is already installed on your computer.
Configuring and Installing PHP on Linux Operating System
Step 1: Download PHP
When installing PHP on Linux, we need to update the packages Manager and install the latest version of PHP. In most distributions, update the package manager using the following command:
sudo apt-get update
Install php command:
sudo apt-get install php
Step 2: Install the database
PHP supports most popular database management system. Before installing PHP, you need to install any database management system such as MySQL or PostgreSQL. In most Linux distributions, MySQL can be installed using the following command:
sudo apt-get install mysql-server
Step 3: Start the web server
Most Linux distributions come with an Apache or Nginx web server. Here we will use the Apache web server. Start the Apache server using the following command:
sudo service apache2 start
Step 4: Test PHP
To test that PHP is installed correctly, create a new file called phpinfo.php and add the following content to In this file:
<code><pre class="brush:php;toolbar:false"><?php phpinfo(); ?></pre>
Enter "http://localhost/phpinfo.php" in your web browser. If you see the PHP information page, it means that PHP has been successfully installed on your Linux computer.
The above is the detailed content of How to configure and install php on Windows and Linux. For more information, please follow other related articles on the PHP Chinese website!