## Uninstall PHP from IIS

Categories:

PHP Installation guides for IIS are a dime a dozen on the Internet these days (though there are only a handful I've seen that I'd consider accurate), however there is not a lot of guidance for uninstalling PHP from IIS. Being able to fully, and cleanly uninstall PHP from your Windows environment is very important for troubleshooting and ensuring a clean environment to do PHP upgrades. This guide details the steps you need to take to fully and cleanly uninstall PHP from IIS.

Uninstall PHP from IIS

First step is to remove your PHP scriptmaps from the IIS metabase, so after backing up your metabase we'll use David Wang's excellent chglist.vbs script to recursively remove all PHP scriptmaps . Open a command prompt on your IIS server, navigate to the directory containing chglist.vbs and enter the following;

chglist.vbs W3SVC/ScriptMaps .php /REMOVE /RECURSE /COMMIT

This command will recursively search through your entire metabase and remove any php scriptmaps, no matter where they might be hiding. If you mapped PHP using another extension (e.g .php3) then you'll need to modify your command to reflect this. You can using the IIS GUI manager to remove PHP, however there is considerable potential for missing a PHP scriptmap or two. Using a script is by far the most robust way of removing your PHP scriptmaps.

Remove PHP environment variables and registry settings

During you PHP installation you should have added your PHP installation directory to the PATH environment variable, and depending on what Installation guide you followed you may also have created the PHPRC environment variable. These will now need to be removed by right clicking on My Computer, selecting properties, clicking the advanced tab and clicking the environment variables button at the bottom. This will bring up a screen with two panels, use the bottom one name system variables to remove your PHP installation directory from the PATH variable, and to delete the PHPRC variable (if it exists).

PHP is able to use the Windows registry to define items such as php.ini paths, and even for setting per directory PHP configuration values. To remove these you need to run Regedit.exe and browse to HKEY_LOCAL_MACHINE\SOFTWARE and depending again on the PHP installation methods used in the past you should see a Key called PHP. Simply select this key with your mouse, press the delete key and confirm the deletion.

Removing PHP files

This is where things can get quite messy as several of the most popular PHP installation guides for IIS advise you to copy PHP files your Windows\System32 directory. While this works, it is not advised as it leaves you wide open for serious file conflict issues during future upgrades of PHP. Depending on the guide you followed you may have been instructed to copy just certain files, or even all files. The end result is that due to file name changes between PHP versions, and differences in installations of PHP on different servers there is no easy one size fits all sure fire way for removing all PHP files from your Windows system directory. About the best that can be done is to generate a list of all the files in your current PHP directory, and then run a script to delete them from you Windows system directory if they exist. First thing to do here is generate you list of PHP files (change x:\path\to\php to the path of your PHP installation);

dir x:\path\to\php /S /B>php_filelist.txt

This will list every single file in your PHP directory (including sub directories) and output them to a file called php_filelist.txt. Next thing to do is to use a small batch script to cycle through this list of files and delete them from your Windows System directory. Copy the following code into a new text file called something like DelPhpWin.cmd and double click it to run it. I can be anything you like, as long as it ends with either a .bat or .cmd extension.

@echo offFOR /F %%I IN (php_filelist.txt) DO del /F /Q %systemroot%\System32\%%~nxI

Once this is complete simply delete your PHP installation directory and you will have completely removed PHP from your Windows environment. The only caveat (as mentioned above) is that due to changes in file names between PHP versions and differences in server configurations the PHP file removal script above cannot guarantee all PHP files are removed as it only uses your existing PHP files a template of what it should be looking for. If you have any comments or feedback on this article, feel free to post a comment below. If you have any specific questions or support enquiries please post in the forums.

Average rating

### UnInstall PHP from IIS -- Great job!

I wanted to say I apreciate the effort here! I couldn't I couldn't find a removal on the php site.

It seems to me they could do something similar, and should have a copy of thier installation file names to write a decent removal app.

Thanks!

Fred perkins

### equivalent for IIS 5.1

I've got the same need but on an XP Pro machine with IIS 5.1.

I am wondering how applicable these steps are to my installation.

### Should be the same

The install process (and therefore uninstall process) is very much the same for IIS 5.1. About the only difference with 5.1 is that you won't have a web service extension as they only came in with IIS 6.
----------------
Dominic Ryan
5 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.7176149487495422, "perplexity": 2716.07000907086}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2016-44/segments/1476988721558.87/warc/CC-MAIN-20161020183841-00206-ip-10-171-6-4.ec2.internal.warc.gz"}