Installing PHP on Windows
Note: You are currently viewing documentation for Moodle 2.6. Up-to-date documentation for the latest stable version of Moodle may be available here: Installing PHP on Windows.
PHP File Selection
Moodle will run on a minimum of PHPv5.3.3 but that is intended for Linux distributions that are actively maintained by vendors such as Redhat, CentOS, Debian or Ubuntu. In case of Windows ALWAYS install latest stable PHP version from http://windows.php.net/download/ !
Download the latest version of PHP, the ZIP file, NOT the msi. The ZIP file is, for our purposes, considerably more easy and reliable to use in all Windows installations.
Download and Unzip
Once downloaded, open Windows Explorer and with a right click, unzip to your destination path, say G:\php. The Apache server can be on the G:\ so I am putting PHP into the same drive. You can put it anywhere you want, but keeping the Apache server, PHP and the MySQL installations all on the same drive makes sense for many installations. Security, access, load sharing and a range of other issues may cause different configurations to occur, but for the most basic installs, PHP can be on the same drive as the server.
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.
Editing Environmental Variables
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 statement, add the text ";G:\php;G:php\ext" Note the first character is a semi-colon, this is a separator, 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 PHP in the path statement, 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.
Next, 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.
Editing the php.ini file
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 the status bar at the bottom of the editing program screen will indicate where the insertion point, the cursor, actually is.)
About line 300, there should be a line that reads: max_execution_time = 30. Change that to read max_execution_time = 180 This variable determines how much time should pass before reporting it cannot find something, or something is not working. That is seconds and if a script cannot run in 3 minutes, it is not likely to run, therefore you may have a problem.
Do not reset the next line, leave memory limit at 128M.
Scrolling down to about line 490 you will find: post_max_size = 2M Change it to read post_max_size = 512M that will make a difference later, when you are uploading 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. This means that you will have a range of options, starting from about 10KB to 512MB, that will appear in your Moodle's upload file size.
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 =, that is, a semi-colon precedes the word "extension", it means that 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.
Configuring PHP and Apache
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: LoadModule is one word. This should be about line 58.
The Apache configuration file uses the # key as a comment marker. Any line added or edited must not have that # marker at its beginning.
At line 61, or thereabouts, add in the text LoadModule php5_module "G:/php/php5apache2_2.dll" (Use your own path) For later versions of Apache, PHP extension numbers might read something like php5apache2_3.dll. (This was current at the time of writing.)
Around line 240 you will find 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 critical 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. Scrolling down a little further, to about line 385, add in the line
AddType application/x-httpd-php .php.
About 10 lines below that we see #AddHandler cgi-script .cgi, leaving that line and in the next line we add
AddHandler application/x-httpd-php .php
- Note In XP
- At the very end of the file add the line PHPIniDIR "G:\php" EXACTLY as is here, except with your path.
- Note 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.
The Apache documentation does mention adding this statement but does not specify where it should go. For some reason, it works as outlined here.
Save the file and close it.
First Test and restart
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. If zipped, then unzip it and place 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 and Vista.)
Once restarted, the Apache icon should be displaying the green arrow.
Specific PHP Testing.
Open your text editing program.
Create a new file and enter the text
<?php phpinfo(); ?>
Save the file as, say, info.php in the document root folder, as specified in the php.ini and httpd.conf files.
Open your browser and aim it at "http://localhost/info.php" and you should see something like the image to the right.
If you have saved the file to the right place, and installed php properly, and edited the Apache httpd.conf file DirectoryIndex correctly, 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.
If the file is not displaying properly, for example you see it is properly tabled and has headings at the start, but a couple of tables down it then just reads the php.ini file, you know that you have edited the httpd.conf file correctly, but the php.ini file is not quite right. Go back to the instructions above and check them against what you have done. While you are almost there, PHP will not work until it is completely correct, you may have a semi-colon where there needs to be a colon. It will be something simple and easily overlooked.