Note: You are currently viewing documentation for Moodle 3.2. Up-to-date documentation for the latest stable version of Moodle is probably available here: Installing PHP on Windows.

Installing PHP on Windows

From MoodleDocs
Revision as of 11:06, 28 January 2010 by Colin Fraser (talk | contribs)

Download the latest version of PHP, the ZIP file, NOT the msi. There are a number of reasons for this, but it is actually easier and more reliable to use the ZIP file in all Windows installations.

Once downloaded, open Windows Explorer and with a right click, unzip to your destination path, say G:\php. The Apache server is on the G:\ so I am putting PHP into the same drive.

Staying in Windows Explorer, open the G:\PHP folder and you will see a file there called "php.ini-recommended". Either copy and paste or simply rename this file to "php.ini". This contains all the essential directives that will allow PHP to run on your computer, but we will need to configure it, and a couple of other files, to make it work for Moodle.

First, we shall set the environmental variables we need to ensure the PHP can be used by Apache.

In all versions of Windows:

Right click the My Computer icon and open the Properties dialogue.

Go to "Advanced" or "Advances System Variables" and then to "Environment Variables" and in the "System variables" section select "Path" and click the Edit button.

At the end of the path statment, add the text ";G:\php;G:php\ext" Note the first character is a semi-colon, this is a seperator, it separates different parts of the path statement, do not forget to put it in, and do not put it at the end of the line. There are no spaces in the path statement. I have used the path to my PHP server and extension files. Without including thPHP server in the path stateement, Apache will not find it and not be able to use it. Save the file by clicking on OK. Close and exit the My Computer Properties dialogue.

Secondly, we need to configure, or fine tune if you like, PHP to suit Moodle.

There are a number of things we need to do here, and we will try them in order.

Scrolling down through the php.ini file, you should be able to see the line numbers to the left of your text editor. (If not there, then usually on the status bar at the bottom of the program screen.)

About line 300, there should be a line that reads: max_execution_time = 30. Change that to read max-execution_time = 180 This variable dertimes how much time should pass before reporting it cannot find something, or something is not working.

Leave memory limit at 128M.

Scrolling down to about line 490: post_max_size = 2M Change it to read post_max_size = 512M that will make a difference later, when you are downloading in Moodle.

About line 538 the line should read doc_root = Change it to read doc_root = "G:\Server\Apache\htdocs" (or YOUR path to your active web folder.)

At about line 542, the line should read extension_dir = "./" but change it to read extension_dir = "G:\php\ext" (This is how it appears in my environmental variables, use your own path.)

Around line 600, you will find the text upload_max_filesize = 2M change that to read upload_max_filesize = 512M

Setting the post_max_size and upload_max_filesize will allow you to set your upload file size in your Moodle.

At this point, you have set the environment now you need to make it work for Moodle.

Starting about line 635, you will see the text ;;;;;;;;;;;;;;;;;;;;;; ; Dynamic Extensions ; ;;;;;;;;;;;;;;;;;;;;;; It is these extensions that we have been referring to as "ext". These extensions are important as they are the tools that provide additional functionality in the Windows environment.

If a line begins with ;extension = a semi-colon precedes the word extension, it means thast this extension is commented out, it is inactive. To activate the extensions we need, we simply delete the semi-colon. Delete the semi-colon from these lines - if there is one there. extension=php_curl.dll extension=php_exif.dll extension=php_gd2.dll extension=php_gettext.dll extension=php_imap.dll extension=php_ldap.dll extension=php_mbstring.dll extension=php_mcrypt.dll extension=php_mime_magic.dll extension=php_ming.dll extension=php_mssql.dll extension=php_mysql.dll extension=php_mysqli.dll extension=php_openssl.dll extension=php_pdf.dll extension=php_pdo.dll extension=php_pdo_mssql.dll extension=php_pdo_mysql.dll extension=php_sockets.dll extension=php_sqlite.dll extension=php_xmlrpc.dll extension=php_xsl.dll extension=php_zip.dll

Some of these, like the ldap extension, you may not need, but include it anyway.

Save and close the file.

Once that is done, we need to make sure that Apache can not only access PHP but can use it.

Using your text editor, navigate to open the "..\Apache\conf\httpd.conf" file. Once opened, search for the text "LoadModule" note: one word. This should be about line 58.

The Apache configuration file uses the # key as a comment marker. Any line added or editied must not have that # marker at its beinning.

At line 61, or thereabouts, add in the text LoadModule php5_module "G:/php/php5apache2_2.dll" (Use your path)

Around line 240 tyou will fint the following text: <IfModule dir_module>

        DirectoryIndex index.html index.htm index.shtml

</IfModule> The DirectoryIndex determines what type of files Apache can use to create its index files. While not so important with HTML pages, this is critcal for PHP pages, so change the section to read:

<IfModule dir_module>

    DirectoryIndex index.php index.php4 index.php3 index.cgi index.pl index.html index.htm index.shtml index.phtml
    #  DirectoryIndex index.html index.htm index.shtml

</IfModule>

We then need to find the line TypesConfig conf/mime.types which is about line 366 and a little below that we see the AddType statements add in the line AddType application/x-httpd-php .php at about line 385.

About 10 lines below that we see #AddHandler cgi-script .cgi and in the next line we add AddHandler application/x-httpd-php .php

In XP At the very end of the file add the line PHPIniDIR "G:\php" EXACTLY as is here, except with your path.

In Vista and Windows 7 At the very start of the file add in the line PHPIniDIR "G:\php" EXACTLY as is here, except with your path.

Save the file and close it.

Once you have done that then you can open a cmd window, again, and no matter where it opens you should be able to type in php -v and it will tell you what version of PHP you are using. It will tell you also if there is any of the dll files missing from the ext folder, for example you have uncommented the extension = hp_pdf.dll file, but it may not be there, so search for it on the Web and download it into the ext folder.

Windows, being Windows, requires a restart at this point, to ensure that the php server has been properly embedded into the Apache Server. (While this step may not be necessary in Windows 7, it is needed in XP.)

Once restarted, the Apache icon should be displaying the green arrow.

Open your text editing program.

Create a new file and enter the text <?php

phpinfo();

?>

Save the file as info.php in the document root folder, as specified in the php.ini file.

Open your browser and aim it at "http://localhost/info.php"

If you have saved the file to the right place, and installed php properly, it should now be showing the PHP configuration file. Scroll through it, and it should be showing you a set of tables with all the information about PHP.

See Also