Install PHP on Windows

Obtaining PHP

  • Download latest version of PHP from http://www.php.net/downloads.php.
  • You can also download the .msi package i.e. windows installer of PHP from sourceforge.net

Prerequisite and running on your Windows system, else you will not be able to run PHP Scripts.

Alternatively, you can install wamp server to install PHP, MySQL, and Apache Web Server on your Windows machine.

Options for installing PHP on Windows

  • You can install php on windows manually.
  • You can run the .msi package, i.e. windows installer for php to install php.
  • Besides full installation, you can install php extensions on an existing installation of PHP.
  • You can upgrade to a higher version of PHP from an existing version.

Install PHP on Windows manually

You have to download zipped binary version of PHP from http://www.php.net/downloads.php.

Extract the downloaded file to php folder which must be created at the root of any of your windows drives (e.g. c:\php or d:\php).

Enter php folder and rename the file php.ini-recommonded to php.ini.

Open the file php.ini with any text editor and find extension_dir within the file.

Change the extension directory, i.e. if you have installed php in php folder of D drive, setting will be extension_dir=D:\php.

Now you open Environment Variables (MyComputer -> System Properties -> Environment Variables), under system variables, select Path and click Edit,
in the Variable value, go to the end of the list and put a semicolon, then  add  D:\php;D:\php\ext assuming D:\php is the location of your php installation.

Then Click on New under system variable and add PHPRC against Variable name and D:\php against Variable value.

Restart your system.

Install PHP on Windows using Windows installer 

Simply run the .msi Windows installer file and follow the installation wizard.

Testing if PHP is installed properly

Create a php file containing code <?php echo phpinfo(); ?> and save it as test.php.
Run this file on your web server and if you get an output like this:

install PHP on Windows
then you have installed PHP properly.

Install PHP extensions on Windows

What is a PHP extension?

A PHP extension is a piece of code which is not part of the core PHP and you need it to explore certain functionalities of PHP (e.g. for using mysql you need mysql extension of PHP).

Many extensions are available out of the box in the PHP installer downloaded from php.net or in the .msi package. But many need to be obtained separately from php.net.

In Windows, extensions come in the form of a  .dll file which you can download from php.net.

How do you configure an extension on Windows?

You need to change the setting of extension dir in php.ini file. For example, If you are using PHP 5.0.3, and you have installed php in c:\php, then you have to set extension_dir = C:\php\ext in your php.ini file.

After downloading the files needed, you have to open php.ini and enable a line pointing to an extension in question.

For enabling extensions, you have to uncomment a line in your php.ini file. For example, for enabling mysql extension, you have to change; extension = php_mysql.dll to extension = php_mysql.dll in your php.ini file.

You also need to restart your web server and php in order to complete the installation of a specific extension.

Sample php.ini

Previous: PHP Home
Next: Install php on Linux

PHP: Tips of the Day

PHP: Unzip a file with php

I can only assume your code came from a tutorial somewhere online? In that case, good job trying to figure it out by yourself. On the other hand, the fact that this code could actually be published online somewhere as the correct way to unzip a file is a bit frightening.

PHP has built-in extensions for dealing with compressed files. There should be no need to use system calls for this. ZipArchivedocs is one option.

$zip = new ZipArchive;
$res = $zip->open('file.zip');
if ($res === TRUE) {
  echo 'woot!';
} else {
  echo 'doh!';

Also, as others have commented, $HTTP_GET_VARS has been deprecated since version 4.1 ... which was a reeeeeally long time ago. Don't use it. Use the $_GET superglobal instead.

Finally, be very careful about accepting whatever input is passed to a script via a $_GET variable.



As per your comment, the best way to extract the zip file into the same directory in which it resides is to determine the hard path to the file and extract it specifically to that location. So, you could do:

// assuming file.zip is in the same directory as the executing script.
$file = 'file.zip';

// get the absolute path to $file
$path = pathinfo(realpath($file), PATHINFO_DIRNAME);

$zip = new ZipArchive;
$res = $zip->open($file);
if ($res === TRUE) {
  // extract it to the path we determined above
  echo "WOOT! $file extracted to $path";
} else {
  echo "Doh! I couldn't open $file";

Ref : https://bit.ly/37op2mt