How to run multiple versions of PHP on IIS at the same time

I created a website called vishwasthali.org in PHP and hosted it in IIS7 on a third-party server. Everything else works fine except for the database access code I wrote using the MySQLi API. The code works fine on the local host, but not on the server. Using phpinfo() on the server and my machine, I found that:

(1) On my machine (running on Windows 7 32-bit Apache hosting environment) PHP version 5.3.8 and mysqli version 5.0.8-dev and

(2) On the server (running Windows Server 2008, the IIS7 hosting environment), PHP version 5.2.14 and mysqli version 5.0.51a .


Here are the screenshots of phpinfo() on my machine: enter image description hereenter image description here


Here are screenshots of phpinfo() on the server: enter image description hereenter image description here


Here is an example mysqli code.

 session_start(); include_once 'code_files/conn.php'; $stmt = $mysqli->prepare('SELECT * FROM adminusers WHERE Username = ? AND `Password` = ?'); $stmt->bind_param('ss', $_POST['Username'], $_POST['Password']); $stmt->execute(); $result = $stmt->get_result(); if($result->num_rows > 0) ........ else ........ 

Using echo get_class($mysqli); shows mysqli . This means the code detects mysqli. But the statement $stmt not prepared. Even $mysqli->error; does not display any errors, possibly due to the fact that PHP works in IIS.

Now I have two options: either change the database access code to the classic mysql API, or update the versions of PHP and MySQLi on the server by downloading the latest PHP binaries from php.net . I will not like the first option (which definitely works), hope you know why. The last is not in my hands. I can’t think of anything more than these.

I believe that replacing php_mysqli.dll with updating the mysqli version may be uncertain. But what about the PHP version?

What can I do in this case. Will updating versions of PHP and MySQLi on the server solve my problem? If YES, can this affect other PHP websites running on the server?

Thanks in advance.

+7
source share
2 answers

Good. Here is the solution. Different versions of PHP can be enabled and run side by side in IIS7. Here is the procedure that I have successfully tested on my machine. I only instruct the process, given that you are familiar with IIS and FastCGI. If not, see Link: http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis'

  • Download any different versions of secure mail packages without a ceiling with PHP binaries from http://www.php.net/downloads.php .
  • Extract them to separate folders on your hard drive, for example C: \ PHP5.2.14 , C: \ PHP5.4.3 , etc.
  • Open the php.ini files in all folders and add / uncomment and change the following settings in all of them.

    session.save_path = "C: \ Windows \ Temp"
    expose_php = Off
    ;; Choose any path here, but mostly it is preferable. open_basedir = "C: \ inetpub \ wwwroot"
    extension_dir = "ext"
    fastcgi.impersonate = 1
    cgi.fix_pathinfo = 1
    cgi.force_redirect = 0
    ;; You can choose different time zones for different websites.
    date.timezone = "your time zone"
    ;; Include any extensions you want on the website, for example,
    extension = php_mysql.dll
    extension = php_mysqli.dll

  • Open IIS Manager . Add as many handler mappings as the number of PHP versions you want to install. Just change the Executable path in the Modify Module> dialog box. Name the mappings, how convenient it is to easily identify them, for example PHP 5.2.14 via FastCGI and PHP 5.4.3 via FastCGI .

  • In the IIS section of IIS Manager, open FastCGI Settings . Here, check to see if there are as many entries as the number of PHP versions you want to run. If not, click Add Applications in the right pane. Select php-cgi.exe from the folder of the required PHP version in the Full path field in the "Add FastCGI Application" dialog box. Click OK.

  • Now copy the folder of your site to C: \ inetpub \ wwwroot or any other path selected in the open_basedir setting in php.ini. In IIS Manager, expand Sites-> Default Web Site from the left pane. Select the website to which you want to target a specific version of PHP.

  • Open Display Handler , with the website selected from the left pane. Here you will find many images. Look only at the entries that you created (those that have a path like *. Php ). Among them, save only the one you need for the selected website, and Delete the rest. This will NOT remove the mappings from your computer, but only from the selected website. Now your website will only work with the version of PHP whose display you saved. Do the same for any websites that you want to target a specific version of PHP to. You can test it by running phpinfo() on websites.

After adding new websites to wwwroot , they will not have any handler. Add a new handler that sets the desired version of PHP. You are done.

This is not the best procedure. But it worked for me. For verification see this link:
http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis/#PHP_Versioning '

Hope this helps if someone needs it.

Hi

+6
source

There are a few mistakes here!

a) The difference between your development environment and your live site is too great! At least use the same web server and the same version of PHP 5.x !

b) NEVER publicly create access to your phpinfo (), this is a very big security risk! A hacker can get a lot of information from him.

c) Even with trained operators, you must misinform your user data before using them in a query!

I do not think your problem has anything to do with different versions of mysqli. Perhaps you should first make sure that you are using the same web server and php version in both environments, and then request more code again (for example, how to make the connection) if it still does not work.

Yes, updating PHP can affect other projects on the server, but it just means that you need to update these projects, which you should do anyway!

And no, loading PHP from php.net is not suitable for your case. You must use the verified and approved versions provided by the respective repositories.

+3
source

All Articles