How to run multiple versions of PHP on IIS simultaneously - php

I have developed a website named vishwasthali.org in PHP and have hosted it in IIS7 on a third-party server. Everything else works fine, except for the code for database access that I have written using MySQLi API. The code works fine on the localhost, but not on the server. Using phpinfo() on the server and my machine, I found that:
(1) On my machine (running in Windows 7 32-bit, Apache hosting environment), the PHP version is 5.3.8, and mysqli version is 5.0.8-dev, and
(2) On the server (running on Windows Server 2008, IIS7 hosting environment), the PHP version is 5.2.14 and mysqli version is 5.0.51a.
Here are the screen shots of phpinfo() on the server:
Here is the sample of the 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); does display mysqli. That means, the code does detect mysqli. But the statement $stmt is not prepared. Even the $mysqli->error; does not display any error, might be because of PHP being running on IIS.
Now I have two options, either change the code for database access to classic mysql API, or to upgrade the PHP and MySQLi versions on the server by downloading latest PHP binaries from the php.net. I won't like to go with the first option (that definitely works), hope you know why. The latter is not in my hands. Can't think anything more than these.
I suppose replacing the php_mysqli.dll on might upgrade the mysqli version, not sure. But what about PHP version?
What can I do in this case. Will an upgrade of PHP and MySQLi versions on the server solve my problem? If YES, can it affect other PHP websites running on the server?
Thanks in advance.

All right. Here's the solution. Different PHP versions can be enabled and running side-by-side in IIS7. Here's the procedure that I have successfully tested on my machine. I am only briefing the process, considering that you are familiar with the IIS and FastCGI. If not, see the link: http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis'
Download any different versions of non-thread safe zip packages with binaries of PHP from http://www.php.net/downloads.php.
Extract them to separate folders in your hard-drive like C:\PHP5.2.14, C:\PHP5.4.3, etc.
Open the php.ini files in all the folders and add/uncomment and change following settings in all of them.
session.save_path = "C:\Windows\Temp"
expose_php = Off
;; Choose any path here, but mostly preferred is this
open_basedir = "C:\inetpub\wwwroot"
extension_dir = "ext"
fastcgi.impersonate = 1
cgi.fix_pathinfo=1
cgi.force_redirect = 0
;; You can chose different time zones for different web-sites
date.timezone = "you time zone"
;; Enable any extensions that you want to per website, e.g.
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. Simply change the path of Executable in the Edit Module Mapping dialog box. Name the Mappings as convenient to identify them easily, like PHP 5.2.14 via FastCGI and PHP 5.4.3 via FastCGI.
In the IIS section in IIS Manager, open FastCGI Settings. Here, check whether there are as many entries as the number of PHP versions you want to run. If not, click Add Applications from the right-pane. Select a 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 your website folder to C:\inetpub\wwwroot or whatever path you choose in open_basedir setting in php.ini. In the IIS Manager, expant Sites->Default Web Site from the left pane. Select the website that you want to target to a specific version of PHP.
Open Handler Mapping, with a website selected from the left pane. You will find many mappings here. Look only for those entries that have been created by you (those which have path as *.php). Among them, retain the only one that you need for the particular web-site selected and Remove the others. This WILL NOT delete the mappings from you machine, but only from the web-site selected. You website will now run only on the PHP version whose Mapping you have retained. Do the same for any websites that you want to target to a specific PHP version. You can test it by running phpinfo() in the websites.
After you add new websites to wwwroot, they won't have any handler attached. Add a new handler targetting the desired PHP version. You are done.
This may not be 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 it helps, in case someone needs this.
Regards

There are a few things quite wrong here!
a) The difference between your development environment and your live site is too large! At least use the same web server and the same PHP 5.x version!
b) NEVER publicly make your phpinfo() accessible, it is a very large security risk! A hacker can get loads of great information from it.
c) Even when using prepared statements you should sanitize your user data before you use it in a query!
I don't think your problem has anything to do with the different mysqli versions. Maybe you should first make sure you use the same web server and php version in both environments and then ask again with more code, (e.g. how you make the connection) if it still doesn't work.
Yes, updating PHP can affect other projects on the server but that just means you need to update these projects, which you should do anyways!
And no, downloading PHP from php.net is not the right way in your case. You should use tested and approved versions provided by the respective repositories.

Related

On Windows 8 and Internet Information Service 8.5 - how to setup PHP?

Let me begin by saying that I am very new to Microsoft's Internet Information Service. I need to setup IIS on my PC and it should also execute PHP files. So far I got everything installed and running - the latest PHP and enabled IIS service. I can view the Default Webpages (*.html) files ONLY. It will not execute PHP files. If I try to request any PHP files, I get 403 error.
I have been researching online and seems to be more confused about setting up PHP (extension) on IIS. Some websites say you need to configure PHP through its MANAGER. Others say I need to add Role and FastCGImodule through IIS manager. According to Microsoft I need to rename php.ini-development to php.ini and point php to some DLL file.
I am using Windows 8, IIS 8.5 and PHP 5.6. I hope someone could point me in the direction.
You can set this up manually or with the IIS Manager. I would set this up my own, so you know whats going on.
You will need to setup the CGI role feature. This includes FastCGI. Here is some information how to do that: http://www.iis.net/configreference/system.webserver/cgi
Then you will need the PHP package somewhere. Lets say in C:\PHP. You can change that if you want.
You will need the fastCGI settings. You can easily set this up by commandline:
%windir%\system32\inetsrv\appcmd set config /section:system.webServer/fastCGI /+[fullPath='C:\php\php-cgi.exe',activityTimeout='1200',requestTimeout='1200',arguments='-c%20C:\php\php.ini']
This example uses a timeout of 20min.
This will set the handler:
%windir%\system32\inetsrv\appcmd set config /section:handlers /+[name='PHP_FastCGI',path='*.php',verb='*',modules='FastCgiModule',scriptProcessor='"C:\php\php-cgi.exe|-c%20C:\php\php.ini"',responseBufferLimit='0',resourceType='Either']
php.ini setup:
[cgi-fcgi]
fastcgi.impersonate=1
cgi.force_redirect=0
cgi.fix_pathinfo=1
For write access you will need to grant "modify" access for the the IURS.
More Information: http://php.net/manual/de/install.windows.iis7.php
I did try the answer posted to heart, but I kept running into problems. In fact, I also followed the Microsoft step by step PHP setup tutorial to the TEETH. I still couldn't get PHP working on my IIS. Although Microsoft warned against using Windows Platform Installer(WPI), I downloaded WPI and ran the installer. Under frameworks, I found PHP 5.6 and clicked on Add button. Then, clicked on the Install button. It took only about 30 seconds to install. Just to be sure. I checked IIS manager and there it was PHP Manager. After opening PHP manager I noticed that all the settings were there and enabled and it already had 15 different extension enabled. Plus, it also had about 35 extension disabled, but it gives you option to enable them right there.
Now, my PHP files are rendered as expected. I even did phpinfo(); and the browser displayed all the PHP settings and information. :)

Installing OpenSIS?

Im using OpenSIS version 5.2. I am trying to install it but after step 2 it just shows a blank box, I cannot proceed to step 3. I have installed this successfully in my other computer but in this one I cannot. They have the same apache, mysql, and PHP version. What should I do?
Thanks in advance.
i hope im not too late. I had the same issue when installing openSis. The third page just loaded blank with no errors. Turns out I am on php 7.0 which dropped all support for php-mysql extension. So i now have to downgrade to php 5.6 or something. Hacked the source a bit and this error gave me a clue:-
An old question but still this problem exists and the solution to that is:
Open the php.ini file in your PHP folder and search for max_execution_time.
When you find it, increase it to 3600 and save the file. Maximum execution time of each script, in seconds, i.e. max_execution_time=3600
Then restart Apache.
Try openSIS installation again.
Basically turned error logging on and it turns out the blank page was caused by the session_state directory not have the correct permissions. That is for my install the PHP.ini file had put it in my documents and settings\local settings\temp\php or something like that. What you need to do is change the directory in the PHP.ini file to point to say c:\temp (make sure it exists!) and set the permission. To fault find grant everyone access to see if it works then work back from there.
The next issue was the install wouldn't connect to my SQL Server express database, so I was madly replacing dll's as per the WIKI!
Turns out though that the SQL Server express install by default doesn't allow named pipes or TCPIP connections hence cannot connect! You need to check this protocols are enabled
To enable TCP/IP:
From the Start menu, choose All Programs, point to Microsoft SQL Server 2005, point to Configuration Tools, and then click SQL Server Configuration Manager.
Optionally, you can open Computer Manager by right-clicking My Computer and choosing Manage. In Computer Management, expand Services and Applications, expand SQL Server Configuration Manager.
Expand SQL Server 2005 Network Configuration, and then click Protocols for InstanceName.
In the list of protocols, right-click the protocol you want to enable, and then click Enable.
The icon for the protocol will change to show that the protocol is enabled.
After this it was smooth. WIKI needs updating badly!

Sqlrelay framework on PHP environment, inconsistency between web and cli

all.
I'm configured sqlrelay to manage mysql server's pool as the query traffic goes high.
(http://sqlrelay.sourceforge.net/)
I was happy when I successfully installed sqlrelay on my machine, but it does not properly working so far..
For your information, I've installed apache and php, mysql using YUM on centos 6.3.
The thing is, when I see phpinfo() on console (php -i), it prints sql_relay's information in middle of the output. (and query statement using sqlrelay is working well!)
When I see phpinfo() on webpage, however, there is no sql_relay section through the page.. and of cource, query statement using sqlrelay does not working at all.
anyone can help me out to address this issue?
Some time has passed, but here's a suggestion for anyone interested. In the first section of phpinfo() output I'd first check that the php.ini where the module is loaded are included. Depending on the configuration you may have a different php.ini for every virtual host.

php odbc_connect to mssql works in linux/ubuntu command line not browser

I really feel like I have done an exhaustive search on this matter, found similar issues and have tried a number of things without success, so I am for the first time posting a question here:
I do a lot of web pages/web programming (PHP/jQuery mostly) and host these pages on my digital library department's Drupal/Ubuntu Server. I just code them and post them via Dreamweaver, as I don't have much use for the Drupal front end. I just need the server for my pages.
Anyway, I am wanting to make some PHP pages that can connect to our library catalog, so I have been working from the command line of the Drupal/Ubuntu server. I installed unixODBC, had some troubles, installed FreeTDS, set up the drivers and the DSN.
Finally...
I was able to get a connection to our catalog via tsql and run a query.
I made a basic PHP script to test the connection:
It works from the Ubuntu command line of the server (connection successful).
It doesn't work when I load it in a browser. I get the dreaded:
Warning: odbc_pconnect(): SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect in /var/www/mydirectory/mytestpage.php on line 15
UPDATE: I installed a test Ubuntu Server in a partition on my laptop, where I started clean, installed Apache2/PHP5(with mssql and odbc modules, etc)/FreeTDS, etc. I got a tsql connection. I made the basic PHP script and ran it successfully from the command line. Then I navigated to the php page from a browser and it worked! I still need to get this to happen on the Drupal server version, but now I have at least narrowed down the issue to something on the Drupal server.
I searched and found such possible causes as:
File permissions, which I think I got corrected, but no go
That maybe I had set up a User DNS and not a System DNS which I tried my best to correct with the proper "odbcinst" command options
That maybe php needs to be running in CGI mode instead of as a module. But that seemed unlikely from what I read. And I am not sure how that would affect Drupal. (There are limits to the system wide changes I should make here.)
A number of people said it was SElinux blocking Apache from displaying the page in the browser, but temporarily disabling SElinux didn't work.
Thanks for any assistance!
Check you have enabled the mssql.so etc at the following location
/etc/php5/apache2/php.ini, you will be having another at /etc/php5/cli/php.ini
in ubuntu php.ini will be maintained separately for cli & mod_php apache configuration
If you are going to test your odbc sources on the commandline, I would advise you use the isql utility instead of tsql. isql uses the DSN you defined in odbc.ini to connect to the database, while tsql connects directly to your database.
If it works with isql, it should work on your webpage as well.
Also check the Drupal/Ubuntu Server files /etc/odbc.ini (your DSN sources) and /etc/odbcinst.ini (TDS Driver settings) to see if they match the ones on the working Ubuntu installation.
My guess is it has something to do with the php. ini file. On my Ubuntu system I've got 2.
One in /etc/php5/apache2/php.ini
And one in /etc/php5/cgi/php.ini
The values in the apache2 path will need to be adjusted to allow the connection. Unfortunately outside of that I'm not too much use as I use MySQL and Mongo
Copy your php.ini from work server to non-work server, add make needed environment variables accessible before starting your web server, and make sure your web-server has full access to your odbc and odbcinst ini-files. And so, using mssql knowledge base or help.

PHP 5.3 - getting it to run on Apache server?

I've set up my own Apache server; with MySQL, PHP and PHPMyadmin.
It used to work previously when I did it before on various computers; but that was the older versions I dealt with, not the latest. However, it's been a while since I've updated my PHP version, so that's why I'm asking this.
What configuration changes do I need to make to get 5.36 to work properly with Apache?
Currently any .htm files can display properly in http://localhost, but no .php ones.
All I see is a text file, so what's gone wrong with this?
The server is not public - in fact, it's on a Windows Vista Home Edition install, and it's a development one. I don't need to worry about anything else just yet, as this is a totally new install.
What config changes do I need to make?
I tried:
# mod_php5
Include conf/extra/suite-php5.conf
but that didn't work, so what's the solution with PHP 5.36?
Should I re-enable the above line (it's currently commented out with the # symbol).
So far the server works; but it's not serving up PHP pages, which is strange.
Anyone got any ideas why? I would gladly appreciate your help!
Won't post the httpd.conf since it's being developed right now though.
No more VC6 versions of PHP 5.3.x?
From the release announcement:
Windows users: please mind that we do no longer provide builds
created with Visual Studio C++ 6. It
is impossible to maintain a high
quality and safe build of PHP for
Windows using this unmaintained
compiler.
For Apache SAPIs (php5_apache2_2.dll), be sure that you
use a Visual Studio C++ 9 version of
Apache. We recommend the PHP builds as
provided by ApacheLounge. For any
other SAPI (CLI, FastCGI via mod_fcgi,
FastCGI with IIS or other FastCGI
capable server), everything works as
before. Third party extension
providers must rebuild their
extensions to make them compatible and
loadable with the Visual Studio C++9
builds that we no longer provide.
Check your config files for http and php. I haven't done this in a while, but you need to add the file type .php to list of files types that you want Apache to serve. READ the config file carefully.
Also, inside your http config file there should be some additional lines that tell Apache where to find php, vis-a-vis the php.ini file. You need to set up your path information inside the config file and in the environment/system variables section of your Microsoft OS.

Categories