h1

Install PHP under Apache and Vista

June 6, 2007

I initially tried the msi installer for PHP 5. Unfortunately, it installs only PHP under CGI, which although it has some performance and security issues, might be ok for a quick and dirty development environment.

But the installer is badly broken. You’ll get an error something like

PHP Fatal error:  require_once()[function.require]: Failed opening
required ‘SAM/php_sam.php’ (include_path=’.;C:php5pear’) in
sam_factory on line 1

After fighting this for a couple of hours, I ended up installing manually anyway. I used this procedure to get PHP 5 running under Vista:

  1. Install the Apache webserver.
  2. Get the current version of PHP 5 from http://www.php.net/downloads.php#v5. (It’s 5.2.3 at this time). Get both the zip file and the PECL zip file (which includes extensions).
  3. Uninstall any previous installations of PHP 5 (Start > Control Panel > Programs and Features). You may have to reboot your machine.
  4. Disconnect from the Internet. Turn off your firewall. Turn off your virus checker.
  5. Turn off User Account Control (UAC).
  6. Get an administrator prompt by going to All Programs > Accessories. Right-Click “Command Prompt” and choose “Run as Administrator”
  7. Use the command prompt to manually remove directories containing previous PHP installations (like C:\Program Files\PHP…)
  8. Go to the directory where you’ve downloaded the PHP5 and PECL zipfiles. Extract the PHP zipfile. Rename the extracted php directory (which has a name something like php-5.2.3-Win32) to c:\php. Extract the PECL zipfile into c:\php\ext.
  9. In the command prompt, type:
    cd c:\php
    mkdir upload
    mkdir session
    copy php.ini-recommended php.ini
  10. Open php.ini in Notepad:
    1. There are many variables… the following are important. Notice that starting a line with a semicolon in the ini file comments it out.
      upload_tmp_dir="C:\php\upload"
      session.save_path="C:\php\session"
      cgi.force_redirect=0
      extension_dir ="C:\php\ext"
      display_errors = Off
      log_errors = On
      error_log = "C:\php\error_log"
    2. You might want to look at upload_max_filesize. I’ve set mine to 16M. I also set post_max_size = 16M.
    3. Enable the extensions you need by deleting the semicolon at the beginning of the line. These will depend on your application… I’m going to be using MySQL (which I’ve already installed) and Moodle (which I’ll install later). My list looks like the following:
      extension=php_bz2.dll
      extension=php_curl.dll
      extension=php_dba.dll
      extension=php_dbase.dll
      ;extension=php_exif.dll
      extension=php_fdf.dll
      extension=php_gd2.dll
      extension=php_gettext.dll
      ;extension=php_gmp.dll
      ;extension=php_ifx.dll
      ;extension=php_imap.dll
      ;extension=php_interbase.dll
      extension=php_ldap.dll
      extension=php_mbstring.dll
      extension=php_mcrypt.dll
      extension=php_mhash.dll
      extension=php_mime_magic.dll
      ;extension=php_ming.dll
      ;extension=php_msql.dll
      ;extension=php_mssql.dll
      extension=php_mysql.dll
      extension=php_mysqli.dll
      ;extension=php_oci8.dll
      extension=php_openssl.dll
      ;extension=php_pdo.dll
      ;extension=php_pdo_firebird.dll
      ;extension=php_pdo_mssql.dll
      ;extension=php_pdo_mysql.dll
      ;extension=php_pdo_oci.dll
      ;extension=php_pdo_oci8.dll
      ;extension=php_pdo_odbc.dll
      ;extension=php_pdo_pgsql.dll
      ;extension=php_pdo_sqlite.dll
      ;extension=php_pgsql.dll
      ;extension=php_pspell.dll
      extension=php_shmop.dll
      ;extension=php_snmp.dll
      extension=php_soap.dll
      extension=php_sockets.dll
      ;extension=php_sqlite.dll
      ;extension=php_sybase_ct.dll
      extension=php_tidy.dll
      extension=php_xmlrpc.dll
      extension=php_xsl.dll
      extension=php_zip.dll
  11. Right-Click on Start > Computer. Choose “Properties”, then “Advanced”. Click on “Environment Variables”. Click on PATH, then Edit… and add “;C:\php;c:\php\ext” (without quotes) to the end of the variable.
  12. Open your Apache configuration file (All Programs > Apache HTTP Server 2.2.x > Configure Apache Server > Edit the Apache httpd.conf Configuration File). Add the following lines:
    LoadModule php5_module "C:\php\php5apache2_2.dll"
    AddType application/x-httpd-php .php
    AcceptPathInfo on
    PHPIniDir "C:\php"

    Look for the DirectoryIndex line. Add ” index.php” (no quotes) to the end of that line.

    Save the file.

  13. Create a file named test.php in your Apache htdocs directory, containing this text: <?php phpinfo(); ?>
  14. Reboot your machine.
  15. Browse to http://localhost/test.php. You should see tabulated information about your working PHP installation.

78 comments to “Install PHP under Apache and Vista”

  1. Thanks, this was a lifesaver. I’d been trying to install for weeks and this works perfect.


  2. I tried to install MySQL which went pretty smooth. However, configuring it was a problem. I opened up port 3306 but it still gives me a port 3306 error. Can you help? Thank you


  3. Hi-

    I tried to install php and open to my explorer but i got error. I copied it here. Please help me. Thanks

    Server Error in Application “Default Web Site”

    ——————————————————————————–

    HTTP Error 404.0 - Not Found
    Description: The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

    Error Code: 0×80070002

    Notification: MapRequestHandler

    Module: IIS Web Core

    Requested URL: http://localhost:80/test.php

    Physical Path: C:\inetpub\wwwroot\test.php

    Logon User: Anonymous

    Logon Method: Anonymous

    Handler: StaticFile

    Most likely causes:

    The directory or file specified does not exist on the Web server.
    The URL contains a typographical error.
    A custom filter or module, such as URLScan, restricts access to the file.
    What you can try:

    Create the content on the Web server.
    Review the browser URL.
    Create a tracing rule to track failed requests for this HTTP status code and see which module is calling SetStatus. For more information about creating a tracing rule for failed requests, click here.
    More Information… This error means that the file or directory does not exist on the server. Create the file or directory and try the request again.

    ——————————————————————————–
    Server Version Information: Internet Information Services 7.0.


  4. This worked out great for me! Thank you.

    Dinah,
    Did you create the test.php file and put it in the directory “C:\inetpub\wwwroot\”?

    It looks like apache is setup properly but the browser just isn’t finding the test.php file in your wwwroot.


  5. I got php and apache to work, but still get mysql working with php.

    I installed mysql and am able to access it via the prompt.

    PhP and Apache are installed and working.

    I removed the semi-colon from the line
    extension=php_mysql.dll

    and did everything else this post describes but still get the following error when trying to view any of my php scripts that use mysql:
    “Fatal error: Call to undefined function mysql_connect() in X”
    where X equals the php file.

    I’ve uninstalled everything and re-installed it all from an Administrative Command Prompt and still get stuck with the same error.

    I’m running Vista Home on a core 2 duo, UAC is disabled.

    Any ideas?

    Thanks in advance!


  6. sorry, I meant mysql WON’T work with php. php doesn’t seem to be loading the extensions even though the extension_dir line is uncommented and pointing to the right ext dir with the pecl extension files.


  7. I got the test.php script to work. I have an index.php in my folder with the test.php script. When I try to open up index.php I get a dialog box asking me how I want to open the file. Test.php works fine. Can anyone help me on this?


  8. Another note of appreciation.

    I wasted a good 2 days of my life mucking around, trying to get PHP running under Vista.

    I read your post, followed your instructions and voila, success!

    Now, on to MySQL.

    Thanks again.


  9. Again, very nice tutorial. I was able to get both apache and php up and running in no time at all!

    cheers.


  10. Grrr - Apache installed fine, but when I added PHP, the service (apache) won’t start.

    I hate stupid Microsoft.


  11. After using the php5 msi apache can’t find the conf file. Must be permissions, but I haven’t figured it out yet.


  12. Great tutorial. Managed to get both apache and php running.


  13. Followed your directions for installing both Apache and PHP under Vista. Apache’s worked great so far, no problems, but after following directions for PHP (step by step, word for word) I get a 404 error when searching for localhost/test.php. I know it’s probably something simple, but I still can’t find it after 2 days of searching. Can anyone offer ideas? thx


  14. Hi very helpfull tutorial indeed.
    just a small advice if you still have a problem running apache after installing php try -not- to include following lines into apache config file:
    AcceptPathInfo on
    PHPIniDir “C:\php”

    RGDS,
    Max


  15. Max

    Commented those 2 lines out of the httpd file, but still no change. Still getting just a plain 404 error and I can see the file is physically where it is supposed to be (C:\apache\htdocs). Thanks for the idea.

    From the error log:

    [Sun Aug 05 09:01:15 2007] [error] [client 127.0.0.1] script ‘C:/apache/htdocs/test.php’ not found or unable to stat


  16. Hey Chris,

    1. I hope you are trying to open it like this: http://localhost/test.php because C:/apache/htdocs/test.php’ will not work.
    2. When you configure apache according to the above tutorial try to put this lines:
    (LoadModule php5_module “C:\php\php5apache2_2.dll” and
    AddType application/x-httpd-php .php)
    in a proper position in configuration file(you will see some similar fields in it).
    3. And don’t forget to restart apache every time you change something in configuration. In my case I had to restart the whole system, because (net stop/start apache did not work)

    Hope it will help.
    RGDS,
    Max

    P.S. In my case I’ve installed MySQL,PHP and apache on Vista Ultimate edition, so maybe there is a bug in other editions however I doubt this, just try to go thru everything step by step again.


  17. thank god for you. there’s no way i wanted to sit down and map config thru vista.


  18. Nice one, this tutorial and the one on Apache were great…gonna try MySQL now, fingers crossed this is gonna go jus as smooth.

    Thanks for the article


  19. I worked through this paper to install MySQL…the only real thing that was different from a regular .exe file install was disabling UAC first and then running it…working fine now!

    I did get one error just after mysql tries to connect to server but I hit the retry key and it was fine and I connected using my mysql gui “sqlyog” just fine

    http://port25.technet.com/videos/research/MySQL_Windows.pdf


  20. Fortunately I didn’t need to go through the whole script to get php and apache working on Vista… but there is now a problem I can’t work out with MS SQL. All the following is working fine on Windows XP using PHP 4.4.4.

    The php script content.php includes head.inc. In head .inc we obtain the title name for a page with a db query for example:

    $title = $db->GetOne($q) or $db->ErrorMsg().$q;

    with say:

    $q = ‘Select pname from pal where pge = $page’;

    Now I have checked the $db->Connect statement and it gets the server, database username, password etc…. perfectly and establishes a connection.

    So I can’t see any connection issues but it simply stops.

    any suggestions?
    I’ve been working on this most of the day and it’s driving me nuts.

    thanks
    Rose

    I’ve put many print statements to debug… however the print statement after the $db->GetOne statement does not print out, there is no error message, just no page displayed.


  21. Again….WONDEFUL!!!


  22. I installed the PHP 5.2.3 and PECL zip file exactly as described in this tutorial.

    Modified the httpd.conf to add:
    LoadModule php5_module “C:\php\php5apache2_2.dll”
    AddType application/x-httpd-php .php
    AcceptPathInfo on
    PHPIniDir “C:\php”

    However, C:\php\php5apache2_2.dll simply doesn’t exist in the C:\php directory. So where does this file com from? Is it built/compiled after the installation of all source code and extensions?

    Any suggestions would be greatly appreciated, Thanks!

    Ben


  23. I figured out the solution to my earlier question.

    I need to download and install php-5.2-dev (zip) from http://snaps.php.net/. That package contains lots of DLLs including the missing php5apache2_2.dll.

    Big thanks to the tutorial author. Without his installation steps I most likely am still trying to figure out how to install it under Vista.


  24. I followed guide and read all emails. I get the 404 error and can’t find test.php even though I’m using http://localhost/test.php and the file is physically where it belongs. If I load the file with File-Open, I get a message box saying “Do you want to save or open this file” and each time I click it, I get a window that appears and goes away so fast I can’t see what it would say, then I get the message box for ’save or open’ again. This repeats.

    thanks for any suggestions.
    Michael


  25. Awesome Tutorial!

    I followed every step and it worked on the first try.

    If it helps anyone, this is what I installed on Vista basic:

    php-5.2.3-Win32.zip
    pecl-5.2.3-Win32.zip

    Thanks again


  26. You are the MAN!!! It rocks…I successfully integrated PHP and Apache…on my way to MYSQL


  27. This is a great tutorial. Thanks bro

    But i still have a problem. For example… test file if i write without “php”, the file doesn’t appear. I need to write in order to get this file run successfully.

    seem oppening php coding must be written in full !!!


  28. Again, an awesome walk-thru. Worked perfectly, thanks.


  29. try this:
    LoadModule php5_module “C:\php\php5apache2.dll”
    AddType application/x-httpd-php .php .php3 .php5 .phtml
    AddType application/x-httpd-php-source .phps
    PHPIniDir “C:\php\php.ini”
    In the end of the file.

    If you are using apache 2.0.X worked for me


  30. i can open up the http://localhost/test.php and it gives me all the info…. but i can not find my wwwroot i tried searching my computer for it but still can not find it…. and i know you need one to do your php websites…. any idea what to do????


  31. hi
    i have installed apahe, it runs fine
    the trouble is that when install php…and configure the httpd.conf file
    and add
    LoadModulephp5_module “C:\php\php5apache2.dll”
    PHPIniDir “C:\php”
    it doesnt let me restart the apache…
    i am running vista….apache works fine, without the above lines….
    when i was setting up the server for php, i choose apache cgi(there were a few other opptions of apache to select from….
    any suggestions?


  32. I figured out the solution to my earlier question.

    I need to download and install php-5.2-dev (zip) from http://snaps.php.net/. That package contains lots of DLLs including the missing php5apache2_2.dll.

    Big thanks to the tutorial author. Without his installation steps I most likely am still trying to figure out how to install it under Vista.
    ben wrote above….
    where are we supposed to extract that package???


  33. i hope you come back to check on this board…for answers to your problems……jessi
    the root directory, if you havent set any……. is htdocs
    it supposed to be in your apache directory….
    htdocs, is ure root directory, unless you set one….which in your case, i think you dint….

    neway, is there anyone here who has a solution to my problem?????


  34. [...] i came across this helpful post by senese: Installing PHP under Apache and Vista. I was able to get PHP working correctly, finally! Some steps may seem unnecessary (such as [...]


  35. k does anyone have a soltution to my probelms, above???


  36. I have installed everything and everything seems to work file. But every php script that I run that has HTML embedded does not show up. It just shows up as an empty site. The Title shows up and i get no other error. Can someone help me out? thank you all in advance


  37. Since you’re running under Apache and not IIS, ought you not to leave cgi.force_redirect=0 as cgi.force_redirect=1? The web page here - http://uk3.php.net/releases/4_1_2_win32.php- is quite explicit that turning it off is needed and recommended only for IIS.


  38. Great Tutorial!

    I did have one problem, the service wouldn’t start after doing all the steps above. Changing the following line:

    PHPIniDir “C:\PHP”
    to
    PHPIniDir “C:\PHP\”

    fixed the problem.


  39. Like many other comments above, I had spent days figuring out how to set this thing up. Your tutorial really safe my life!!!

    Thank you very much!!!


  40. Thank you so much for this really helpful tutorial. I followed these instructions and Apache/PHPE worked first time. Haven’t tried MySQL yet. Brilliant!


  41. Thanks a mill…yet to try mysql. but this is a life savior!

    Apache 2.2.6 php 5.2.5..vista home prem.


  42. Thanks it works just great.


  43. You legend! You’ve saved me much head scratching. Thanks.


  44. Thanks so much for putting this up. Please keep it up here too! I was so frustrated and lost with installing PHP and getting it to work with apache. I’m a novice programmer and I thought I would use this winter break from school to learn some PHP, and you have made that possible!


  45. You can try XAMPP or WITSuite (installation video: http://www.witsuite.com/products/installer/).


  46. I have followed the tutorial above,and many other tutorials to try and get php5 working with apache on windows vista, however when i try to open localhost/test.php i get a message box asking if i want to open or save the file.If i click open it opens it upi n dreamweaver. Any ideas before i go mad and bin the laptop!!!

    Cheers in advance
    Rob


  47. i did everything stated and it turned out fine but when i try write my own code and save it in htdocs and try to access the script, via web, it doesn’t show up.
    any help??


  48. Ok the error above has been sorted, but now i start my Apache server, i see a few people have had the same problem, but cant seem to find a definative fix,have trie everything mentioned above,but still cant start it,if i change the LoadModule php5_module “C:\php\php5apache2_2.dll” to LoadModule php5_module “C:\php\php5apache2.dll” it startes but when i open localhost/test.php i just get the code displayed on the browser………any ideas for either problem????


  49. sorry,meant to say it wont start in above post


  50. After smashing my head off a wall for 5 hours and trying 3 or 4 sites with “solutions”, this one nailed it for me. My initial problems were related to IIS7 clashing with Apache. After I removed IIS7 and followed these, I was able to get it to work. I had the visible code problem too - meaning PHP interpolator is not being invoked.

    Other points - make sure Apache service is stopped (if you have php as a sub directory of Apache) and you are deleting old php versions in that dir. There was a tip about not installing Apache in a dir with spaces as in “C:\Program Files”.

    My php ini was “tweaked” already in C:\Windows - but I added the PHPIniDir “C:\Windows” to httpd-conf anyway. As %SYSTEMROOT% this should be unnecessary. I set the “Listen” parameter to 80 and Servername as localhost since i plan to do local development for testing and not actually deploy. MY ISP is not setup to allow me to “host” anyway. Maybe getting this local setup to work is a place to start for those wanting to deploy on a network or the internet, then mod the IP and port info later when you want to deploy.

    Also I found I had to Modify the Security permissions on my Apache and php folders to add my admin account and give it full control (or modify) in order to save php.ini and httpd-conf. Vista doesn’t have groups it seems, so you can’t simply add the admin account to the Administrators group.

    Thanks a million Mr. Senese for a working solution.

    Cheers


  51. Thanks for this quick and easy way to get up and running with PHP. I’m new to PHP and this was great!


  52. I have some problems getting results from form submission when using just the file name in action attribute i.e action=”update.php”. file exist but shows errors like: HTTP 404 Not Found. Am using PHP5, Apache2 on Vista home premium. Any help ‘ll be appreciated!


  53. Thank you so much!


  54. Thanks for the humungous help! However, after carefully following your instructions, I was still getting an internal server error (http #500) when trying to load the phpinfo test page.

    Joe Orr’s suggestion to add a backslash to the end of the ini path fixed the problem! Change

    PHPIniDir “C:\PHP”
    to
    PHPIniDir “C:\PHP\”

    Thank you everyone. Why the heck isn’t there a “packaged” version to do all this boloney for us? What a waste of good time! Anyway I thought I would also pass on that I just ran into something called WAMP, which may be worth exploring, as it is supposed to install Apache/MySQL/PHP onto Windows all at once! Anyone have any experience with this?


  55. [...] More incredible thanks to: http://senese.wordpress.com/2007/06/06/install-php-5-under-apache-22-and-windows-vista/#comment-262, [...]


  56. Thank you so much. I don’t want to broadcast my oops, however if it saves anyone an hour, it’s worth it. Double check that you didn’t extract your php directory in Program Files like I did… it needs to be at the root directory C:\php\. Also, I didn’t know where to put the additional config information, so the person who added “at the end of the config file” really helped me a lot. Thanks again for taking the time to post this.


  57. Hey, thanks man. Very good indeed, never could’ve done it without this, thanks for all your hard work. Had previously installed on XP and was OK but was stumped on Vista.

    BTW - I didn’t disconnect from internet, or turn off firewall or anti-virus and it sill worked a charm.

    Thanks once again, where would be without someone posting their knowledge to help the rest of us out?


  58. Can i turn on UAC after i installed php?


  59. The apache server seems to be working for me because at localhost I could see the page indicating successful installation of apache. However, when tried again I get a listing of files page instead of the apache page. What could be wrong ?


  60. By listing of files I meant that it shows me directory listing of htdocs dir instead of apache page. Please help. Thanks.


  61. Great Article! Worked great….now for MYSQL


  62. Thank you so much. I managed to get php working under windows with IIS but it was so much hassel. It too me about a week. Now I have vista with no web server. I followed you instruction and had php working under an hour. Thanks so much!!!!!!


  63. As others have reported, I also get a 404 Not Found Error when trying to access the test.php file via http://localhost/test.php, which is within /htdocs/.

    I cannot find a solution or cause to this issue. Any advice really appriciated!!! Thanks for the steps.


  64. Yo, I seriously was trying for hours and hours, trying to follow dozens of tutorials and instructions to get php working on vista for web dev purposes. I tried IIS and then tried manually installing php4 and then php5 and each time couldn’t get past the part about handler mapping cause it kept saying something about a module list. Then I tried installing Wamp server and I couldn’t get the localhost to do anything and I searched dozens of pages of forums. But anyway, as soon as I started following your instructions I knew it was going to work. It was so explicit and worked perfectly, and now I have apache and php on vista. YEAH!!!!


  65. Seems like most have configured PHP , but like most again, I am having trouble to have php work with mysql on vista under apache. PHP runs fine so far but cant connect to sql. What are the variables that need to be changed or added in php.ini anyone?
    Thanks


  66. SOLUTION TO MYSQL integration

    Ok, for all of you stuck on mySql: If you have configured php to work with above help and if you are having proble to get mysql running and if you get error msg that corresponds to something like not able to load php_mysql.dll >>
    first of all you have to enable
    extension_dir = “Your php dir\ext”
    and make sure you have
    extension = php_mysql.dll in php.ini file
    This should have been done already if you followed the instruction above.

    11. Right-Click on Start > Computer. Choose “Properties”, then “Advanced”. Click on “Environment Variables”. Click on PATH, then Edit… and add “;C:\php;c:\php\ext” (without quotes) to the end of the variable.

    now as instructed above, if you already added evironmental variable as phprc value “c:\php dir” (wherever your php dir is)
    in the list look for
    path=c:windows; c:\windows\system32;….
    lilight it and chose ‘edit’ and add at the end of the list the same value that you added for phprc (above)
    just make sure you add ; before “c\php dir”

    path=c:windows; c:\windows\system32;….
    path=c:windows; c:\windows\system32;c:\php

    this should work just fine.

    And I don’t think you have to add the path c:\php\ext in the environmental variable, just the path to the php folder should be enough.
    World is a happy place after all, specially when your mysqlstarts working. hmm time for a drink :)


  67. Thanks a lot. This is very helpful.


  68. You made my day :)


  69. Thanks a lot for such a nice step by step instructions.

    I could not get PHP started for a while, although I had the file C:\php\php5apache2_2.dll at the right location. Changed the permissions still did not help.

    Finally when i changed my httpd.conf to C:\php\php5apache2.dll instead of _2 thing then it worked. (upto test.php - yet to upload my complete application though)

    fyi - I have php5.2.5


  70. thanks man, great tutorial.
    would be really nice if we could have one for mysql as well.


  71. Perfect, First Time! Great instructions for installing Apache and PHP on Vista HP!


  72. Wow! It works!!
    Bought a book on PHP and MySQL today, fell at the first hurdle…thank you for making this easier, and letting me continue on my web developing journey! :)
    Alice.


  73. Thank you! Worked perfectly.


  74. Guys why not just used XAMPP. This is a very light way tool that can be installed with the click of a button. It is bundle up with Apache,perl,php,mysql,phpmyadmin. great tool check it out!


  75. Thanks a lot!
    After a hard day I discovered your procedure. Amazing, it works. Now PHP is integrated with Apache, and work fine under Vista Home Basic. Your tutorial is a great thing.


  76. Hey thanx that really works i have been trying all day to get apache and php working on vista ^^ next is to get my sql :s. thanx alot


  77. You Guys are rock! After reqding your above tips got the success to install the PHP on the Vista!

    Cheers!!!
    JS


  78. You Guys are rock! After reading your above tips got the success to install the PHP on the Vista!

    Cheers!!!
    JS


Leave a Comment