Is it possible to write PHP in an ASP.NET page [duplicate] - php

A portion of our site is done in PHP and a portion of our site is done in ASP.Net. We just set up a new web server with Windows Server 2008 R2 which has IIS 7.5 installed.
I understand that IIS 7+ supports PHP, but can PHP and ASP.Net run side-by-side within a single web site in IIS, or would I have to set up one web site for the PHP pages and one web site for the ASP.Net pages?

You should be able to run both in the same site, but be sure that the AppPool for the site runs a "classic" ASP.NET pool configuration. The default AppPool routes everything through ASP.NET, and you won't want that for your PHP pages.
Other than that, you should be fine. Query strings, files, and back-end databases will be the best way to share data between pages.

Yes you can use both under the same website. Since the file extensions are mapped to specific external processes, they are called independently. You can even use Asp.Net to secure .php files with FormsAuthentication by implementing wildcard mappings within IIS (I know 6/7 have this, not sure about 5). Mixing data across them is tricky because they will have separate external processes and thus separate sessions. Most cookies will be readable across both, but secured cookies will not be.

Yes you can, but watch out for this:
If you have a wordpress on your "root", and asp.net apps in folders under it
(e.g. http://root.com/aspnetapp1/),
and if you follow these suggestions about "urlrewrite" for permalinks in wordpress, you can have trouble if you try to configure "wildcard handlers" in the apsnetapp1.
To avoid issues, the web.config of the wordpress root app must also have that setting:
<location path="." inheritInChildApplications="false">
<system.webServer>
...
</system.webServer>
</location>
Or else, your wildcard handler will never raise because index.php from root will catch all your requests to url like: http://root.com/aspnetapp1/api/*

Yes, it will be not a problem. Even some Windows Shared Hosts offer PHP plans - Windows Hosting PHP.

Yes, PHP can be seamlessly implemented into ASP.NET 3.5 / 4.0
Go to http://phalanger.codeplex.com/ (or http://www.php-compiler.net/) and download the latest version of Phalanger. Install into Visual Studio and voila!
Phalanger – the PHP compiler for .NET
Welcome to Phalanger – full-featured PHP runtime & compiler for
.NET/Mono frameworks. Phalanger is modern open-source implementation
of PHP, compatible with the vast array of existing PHP code. In
addition Phalanger gives PHP-application developers lot of new
possibilities; from improving performance and using modern
environments, to taking advantage of seamless unique .NET integration.

ASP and PHP can be used on windows boxes. As long as they're completely separate and aren't dependent on each other. For example, using query strings (i.e file.php?var=1&var2=bla) things get messy when you need to transfer those variables over to the ASP file or vice versa.
So as long as the 2 systems are totally independent of each other, then it should work fine.
You may also find some incompatibility with cookies and sessions. Those too can be passed but not easily.

ASP.NET and PHP Support
Develop, deploy and easily manage Web applications using your choice
of languages. From ASP.NET to PHP, IIS7 provides a powerful and
flexible Web server environment for the world’s most popular Web
applications.
(Source: http://www.iis.net/overview/choice/aspnetandphpsupport )
I tried put a test.php file (with conent: <?php phpinfo(); ?> ) to existing ASP.NET website (use real server at https://somee.com ). I knew that ASP.NET and PHP have worked together.
Read more:
http://www.w3schools.com/aspnet/webpages_php.asp
https://technet.microsoft.com/en-us/library/hh994592.aspx

You can run both on the same site, but won't be able to talk to each other unless you setup some sort of messaging system or share storage.They are basically applications of complete different nature.
Another possibility is to call your .NET code from PHP:
A piece of code written in C# like this:
string javascript = "";
Microsoft.Ajax.Utilities.Minifier m = new Microsoft.Ajax.Utilities.Minifier();
Microsoft.Ajax.Utilities.CodeSettings settings = new Microsoft.Ajax.Utilities.CodeSettings();
settings.OutputMode = Microsoft.Ajax.Utilities.OutputMode.SingleLine;
settings.PreserveFunctionNames = false;
string minified = m.MinifyJavaScript(javascript, settings);
Will look like this on PHP:
$minifier = netMinifier::Minifier_Constructor();
$settings = netCodeSettings::CodeSettings_Constructor();
$csssettings = \ms\Microsoft\Ajax\Utilities\netCssSettings::CssSettings_Constructor();
$settings->OutputMode(\ms\Microsoft\Ajax\Utilities\netOutputMode::SingleLine());
$settings->PreserveFunctionNames(FALSE);
$settings->QuoteObjectLiteralProperties(TRUE);
$result = $minifier->MinifyStyleSheet($css, $csssettings, $settings)->Val();
From:
http://www.drupalonwindows.com/en/blog/calling-net-framework-and-net-assemblies-php

Related

Use Sinatra to serve php files

I am using Sinatra to design a web interface for some research we are doing. However, I also want to be able to use phpMyAdmin for database administration. Is there any way to get Sinatra to serve up php? I know that it can be done with some tweaks to Apache, but since I do not control our setup, I was hoping to be able to do it from within Sinatra.
The server I'll be working on is Windows (don't know what version), has Ruby 1.9.2, PHP 5.3.5, and Apache 2.2, and there are no other web facing or database related projects on it.
My goal is to be be able to access it like this:
researchserveraddress/app/admin/index.php
where
researchserveraddress/app/ would be the main page of our app (served by Sinatra).
I'm sorry if I'm unclear, I do not have very much experience with servers and deploying an app, so far, everything I have done has been locally.
You could use rack-legacy, which allows Sinatra to serve PHP files. It simply uses php-cgi to run the scripts. For example, put phpMyAdmin under directory admin and put something along these lines to config.ru:
require 'app'
map "/admin" do
use Rack::Legacy::Php, 'admin'
use Rack::Static, :urls => ['/'], :root => 'admin'
run lambda{|env| [200, {'Content-type' => 'text/plain'}, 'OK']}
end
map "/" do
run Sinatra::Application
end
(If you're not familiar with using config.ru with your Sinatra app, see this part of Sinatra docs).
I'd suggest to configure Apache instead if possible. It strikes me as a cleaner solution and it would be also more efficient, but that's probably not a problem if you're only using it for phpMyAdmin.
Sinatra can't interpret the PHP files so any embedded variables will be left unprocessed.
You COULD use Sinatra to redirect the requests to the appropriate PHP page, which is then handled in the normal fashion by the PHP processor.

Convert PHP-MySQL web application to desktop app (exe)

I have developed a PHP-MySQL web application, which is a school-based project.
My client wants this application to be converted into a .exe file such that it can be installed on his desktop and use it.
How the PHP website can be converted to a .exe file and can it be run without the need of a database/server software?
Please advice.
The convenient solution is not to convert the website to .exe. I think it will be better if you have portable server/php/mysql and make the website work from a usb or CD with autorun.
NuSphere's PhpDock claims to do this: It serves as a deployment helper and comes with a bundled web server. However, I don't know about the database part, and it's not free.
PhpDock enables you to deploy any PHP web application as a Stand Alone Windows Desktop application w/o any changes in the code.
I don't know that particular product, but I have been using their IDE for years and am quite happy.
try using a site-specific browser. it will make a desktop app that is basically a portal running to your webapp. try this one:
https://mozillalabs.com/prism/
It allows alot of advanced features like system tray icons and such. I have used it many times!
Hope this helps, JL
Short answer: Not possible.
Long answer: It depends.
You could install a web- and database server on his machine (or create an installer that does it) and run the application locally on his machine.
or
You keep the application on a server and just provide a launcher that opens his browser and points it to the URL of the application.
As Artefacto mentioned, it might be a good idea to switch to SQLite instead of MySQL but depending on how your application is written it might require a lot of code and SQL Query changes.
No. You have at least to remove the dependency on MySQL (and use e.g. sqlite instead).
Then, you would either have to:
Convert the webpages to windows dialogs. This would completely change your application (e.g. what would originally be http "form submissions" would be someting completely different). At this point, it'd much easier to write a .NET application
Bundle a web server (e.g. Apache) with PHP installed.
Another try would be to turn your php project into PHP-GTK (http://gtk.php.net/).
Yet another one is to give HPHP a try (https://github.com/facebook/hiphop-php/wiki/) and try to turn the generated C code into something like a .DLL in .NET and use it for the logic while coding the UI in say, C#.
Just create a simple program in C or C++ that will just add icon in Start menu, desktop and Quickstart. If your client clicks the icon it will open the default OS browser and point it to URI of your application online.
That might fool your client :)
Or maybe it will be enough for him (he might be asking you to convert it to exe because he can't remember URI or something - ask him what is the reason).
You can use xampp open-source project to pack your PHP site into an executable file.
Use the following steps:-
1. Download Xampp source code.
Add your PHP file inside htdocs directory(Ref:- https://sourceforge.net/p/xampp/code/HEAD/tree/win32/xampp/htdocs/).
Now compile the XAMPP source code and distribute it.
For DATABASE creation and initial data loading in the database, you can code your site in such way that if database is not created, it redirects the page to install.php which do the database creation and data loading task using sql file provided(you need to add SQL file containing database structure and required data).
Don't forget to delete the SQL file post installation of database.
Not sure that's gonna be possible but have a look at:
WinBinder
WinBinder is a new open source
extension for PHP, the script
programming language. It allows PHP
programmers to easily build native
Windows applications.
(source: winbinder.org)
Solution 1:
There are several solutions to convert your web application into a desktop application, the one I prefer is the open source solution: PhpDesktop, but unfortunately it only supports SQLite.
Best Solution:
To convert your PHP application with MySQL I know a paid solution that does this: 'ExeOutPut For Desktop', it is the best for this job
Php desktop is the way to go, it's actually very simple to modify to the version of PHP you want to use and is open source too https://github.com/cztomczak/phpdesktop

Is is possible to run Coldfusion & PHP on the same server and website?

I would like to be able to port some new site pages over to PHP using the same db as in the coldfusion site. Is it possible to have PHP run pages in say other directory and go back and forth ?
Many thanks for your reply.
Terry
As others have said, yes, it is possible. Your configuration doesn't really matter, (unless you're looking for help getting it setup), because it can be done on any modern webserver (Apache, IIS, etc).
Something to think about, though, is the default document. If your web application uses urls like:
http://example.com/myApp/ (no index.cfm or index.php in the url)
Then you need to be aware of the explicit order of default documents. If you have both an index.php and an index.cfm template in the same directory, which will execute?
If your default document list is (a variation of):
index.cfm index.php default.aspx index.html
Then the ColdFusion page will be the one to execute. On the other hand, if the default document list is (a variation of):
index.php index.cfm default.aspx index.html
Then the PHP page will be the one to execute.
Yes, this is possible, I have this available on my production web server (RedHat but it shouldn't matter). If you're looking for details on configuration I couldn't help you though, I had my host set it up. I wouldn't imagine a standard install of both would conflict, just set up the proper handling for each file extension and you should be good to go, keeping them in separate directories or mixing them in one.
It is possible as long as you are running the same web server (i.e. IIS or Apache) for both ColdFusion and PHP. If you let us know what your environment is, people may be able to further assist you - but the answer to your question is yes.
Yes,
It's technically no different to Windows servers which have both PHP and .Net installed, or a Linux server with Perl and PHP.
Speaking generally, after installing the languages you're using you set up your web server to handle files of different extensions. This is done differently depending on whether you're using IIS or Apache, but you effectively say .php files should be handled by the PHP interpreter and .cfm files handled by the Coldfusion interpreter.
As others have said, its entirely possible and not hard to setup. Just watch out for Default Document as Adam Tuttle said.
I will take it a step further: you even run CF and PHP in the same application server!
Use Cauchos Resin for CF and its Quercus support for PHP:
http://quercus.caucho.com/
Of course, if your PHP app is non-trivial and/or relies on some custom extensions or extensions that Quercus doesnt support than your SOL. But might be interesting to check out.

Mixing Python web platforms PHP, e.g. - Mediawiki, Wordpress, etc

Is anyone developing application integrated with Mediawiki - using Django or other Python web development platforms using mod_wsgi?
Would be very interested to find out what has been done in this direction and maybe there is some code available for re-use. (I've started creating wiki extensions working with MW database in python whose output is injected via Apache's include virtual directive. it works ok, but a bit slow so far - maybe I can optimize it though)
Basically I would like to have certain parts of displayed wiki pages be prepared with python.
Has anyone reproduced common MW skins in python templates?
edit: found this nice video showing how PyCon site does just that (not with MW though) - using custom template loader
http://showmedo.com/videos/video?name=pythonNapleonePyConTech2&fromSeriesID=54
Thanks.
There are so many different ways to do this.
You can make a mediawiki skin that uses iframes and inserts things from a Python server.
You can write a python app that accesses mediawikis data somehow and outputs it.
You can put a Python server in front that extracts the content from mediawiki and put's it into a page that is otherwise generated from Python.
You can use deliverence to skin mediawiki, and use it's pyref functionality to call pythonscripts and insert that into the skin (I think, I haven't done that myself).
Which way is best for you completely depends.
Can't you use Mediawiki HTTP based API? Loose coupling is great.

Making a distribultable standalone program in PHP

I've decided to code some applications in PHP that are supposed to run offline in the user's machine. However, I can't seem to find an user-friendly install wizard to create a local server in where the script will run. Any ideas?
PS: Here's an example of what I want: http://www.nolapro.com
You could go to the old school route and try using PHP-GTK.
Text Tutorial here: http://www.kksou.com/php-gtk2/References/Compiling-standalone-PHP-GTK2-applications-on-windows-using-PriadoBlender.php
or you could go the route that I believe has much more promise: Adobe AIR + PHP
It has the added bonus of running on any platform!
Video tutorials here: http://www.vtc.com/products/Adobe-AIR-PHP-Development-Tutorials.htm
There's also a new player in the game, Appcelerator. It lets you write your code in whatever language you want (PHP, Ruby, Python, etc) and compile it for the platform of choice (iPhone, Android, Windows, OSX). Parts of it are still beta, but it looks unbelievably slick & cool, and there are lots of tutorial videos. http://www.appcelerator.com
I hate to advocate this, because it just feels so wrong. You would probably be better off using a language inteded for use for stand-alone applications, if you're going to be doing this often or in a production setting.
With that said, a colleague of mine used to use the Bambalam PHP to EXE Compiler for this. He actually had a profitable product built around it.
Bambalam will generate an EXE that doesn't rely on any external DLLs, based on your PHP code.
http://www.bambalam.se/bamcompile/
If you have a webapp written, you maybe want to deploy on client, a possible way is use wapache, which is a standalone apache bundled with your application, and an integrated (IE) browser control inside.
http://wapache.sourceforge.net/
A new feature of PHP 5.4 & 6 can help you, the builtin web-server.
http://php.net/manual/en/features.commandline.webserver.php
With this feature you can host locally your php app without external webserver, and access on localhost.
If you really talking about a client application you are really wrong to do this.
If you want to wrap a server + browser to deploy your web based application so it runs local you might check out three options:
1) Deploy a simple webkit browser (you can get a QT Webkit Browser in 30 lines of code) and an apache server that is installed somewhere standalone (not via the apache control script as this uses port 80 and i probably conflicts with another installed webserver.
2) Look at the Firefox PRISMA solution. I have read about this only in a news article but it wrapps the firefox around one single start URL. You have to deploy a webserver in the same way as
3) Try to wrap it as a HTA application. Search the corresponding info on MSDN.
I would prefer (1) as you can add special application interacting code as needed.

Categories