Current Location: Home> Latest Articles> Complete PHP Environment Setup Guide: Detailed Installation for Windows and Linux

Complete PHP Environment Setup Guide: Detailed Installation for Windows and Linux

M66 2025-10-31

Complete PHP Environment Setup Guide: Detailed Installation for Windows and Linux

When developing websites or building dynamic pages, PHP is an essential server-side scripting language used worldwide. This guide explains how to set up a PHP environment on both Windows and Linux systems, helping developers complete the installation and configuration efficiently.

Setting Up PHP on Windows

Download the PHP Package

First, go to the official PHP website and download the appropriate installation package for your Windows version (32-bit or 64-bit). Once downloaded, extract the package to a specific directory, such as C:\PHP.

Install and Configure PHP

In the PHP directory, locate the php.ini-development file, copy it, and rename the copy to php.ini. Open it with a text editor and modify the configuration as needed — for example, set the timezone and enable necessary extensions:

date.timezone = Asia/Shanghai
extension=mysqli
extension=curl

Set Environment Variables

Add the PHP installation path (e.g., C:\PHP) to the system environment variables. Go to “System Properties → Advanced → Environment Variables → System Variables,” find the Path variable, and add the PHP directory path.

Test PHP Installation

Open the command prompt and type:

php -v

If PHP version information appears, the installation is successful.

Setting Up PHP on Linux

Install Apache, MySQL, and PHP

On Linux (such as Ubuntu), you can install Apache, MySQL, and PHP using the package manager. Run the following commands in the terminal:

sudo apt update
sudo apt install apache2
sudo apt install mysql-server
sudo apt install php libapache2-mod-php php-mysql

Modify PHP Configuration

The PHP configuration file is usually located at /etc/php/7.x/apache2/php.ini. You can edit it according to your project requirements — for example, to change memory limits, execution time, or file upload size.

Restart Apache Service

After modifying the configuration, restart Apache to apply the changes:

sudo systemctl restart apache2

Test PHP Installation

You can verify PHP installation via command line or browser:

php -v

Alternatively, create a file named info.php and add the following content:

<?php
phpinfo();
?>

Place it in the Apache root directory and visit http://localhost/info.php in your browser. If the PHP information page loads successfully, your setup is complete.

Conclusion

By following the steps above, you can successfully set up a PHP development environment on both Windows and Linux. Depending on your project needs, you may also install additional extensions or tweak performance settings. A properly configured environment ensures smoother development and reliable deployment for your future projects.