Lightweight PHP server to bundle with application? - php

Does there exist some sort of PHP server that can be bundled with a locally-deployed application? It sounds wonky, but the end result is I can't use a remote web server to do anything. Clients will be downloading a package, and the plan is to use a Java backend that reads from a flat file. The flat file contains settings and is modified through a GUI written in HTML/JS, and this is where the server would come in. The forms in HTML should be able to submit to the server, which does a simple file write to the flat file.
Is there any simple, lightweight server that has that simple feature? When running the executable for the application, it would start the installation process for the server before moving the web GUI files to the appropriate locations.
Note that I'm doing this for a client, so I can't quite change the reqs and would rather not discuss their effectiveness. I would be ever thankful if people had suggestions for the server though!

You should check out roadsend php.
It can compile php scripts into a binary with its own build in server.
https://github.com/weyrick/roadsend-php

Nanoweb might do the trick for you, it's an HTTP server written in PHP. So long as the client has a PHP install you should be able to package things up nicely. In fact with a little extra effort you should be able to package up the PHP binary along with your code.
Nanoweb: http://nanoweb.si.kz/

Since PHP 5.4, PHP have a built-in web server and this works on any system where PHP binaries exists.
$ cd ~/public_html
$ php -S localhost:8000
I can't think of any lighter server...
http://php.net/manual/en/features.commandline.webserver.php

If you have a java backend, what do you need php for?
You could simply bundle a small java based webserver.
http://java-source.net/open-source/web-servers

A while ago I created a small web interface for Transmission (mac/linux bittorrent client) that needed to run a local web server with a custom PHP setup. I used lighttpd + php w/ fastcgi. When zipped up, I believe, it weighted in at <3MBs. If you don't need to run any PHP lighttpd is only a few MB's (and light on resources) and offers a very flexible configuration.
Source: http://svn.recurser.com/transmission/trunk/cocoa/

If you're already using Java, you may want to look at Quercus, an implementation of PHP and many common extensions in Java. It's a bit restrictive, but it may fit your needs.

Like unomi, I don't really understand the situation, but I'll assume you do...
Apache is by far the most popular and best-tested platform on which to run PHP, but in theory it should run on any web server that supports CGI/FastCGI. Alternatives include Lighttpd, nginx, and a few dozen others.
Whatever you choose, the key is to pre-configure it and keep it self-contained in its own folder. I think Apache would easily work here. Set it to port 43948 or something; remove all unnecessary modules; pare down the httpd.conf to its most basic requirements; allow only local connections; and write clickable scripts (.bat or .sh or what have you) to start and stop it.

This project is an interesting option...
An embeddable web server designed for (and written in) PHP. it handles
the control of the assigned port, setting common environmental
variables (such as $_SERVER, $_GET, $_POST and $_COOKIE) and calling a
function or method in your application to delegate the request.
The web server is able to be packaged in, and controlled from, your
application. Therefore eliminating the requirement that your user have
a standard web server installed and configured to use your web
application. Combined with a database such as a flat-file database, a
Berkley DB or SQLite, PHP Embeddable Web server can remove the need
for the user to have any specialised libraries installed, except PHP
(which is preinstalled in many Unix and Linux distros).
I have used this. It does work.. It is cool. As easy as...
# php server.php
You kind of have to get your hands dirty.. but it's TINY, a single file, and HIGHLY configurable... Word of warning though.. don't bother with this unless you know what a header, a class, a method, and an object, etc... And be prepared to apply that knowledge.

Related

How does PHP works and what is its architecture ?

Guys recently I decided to go back to PHP and do some more complex stuff than a simple log in page. For 3 years I've been programming with Java/JavaEE and have a good understanding of the architecture of of Java Applications. Basically, a virtual machine ( a simple OS process ) that runs compiled code called byte code. a simple Java web server is basically a java application that listens on provided TCP port for Http requests and responds accordingly of course it is more complicated than that but this is its initial work.
Now, what about PHP ? How does it work ? What, in a nutshell, is its architecture.
I googled about this question but in 90% the articles explain how to implement and construct a web application with PHP which is not what I am looking for.
The biggest difference between a Java web server and PHP is that PHP doesn't have its own built-in web server. (Well, newer versions do, but it's supposed to be for testing only, it's not a production ready web server.) PHP itself is basically one executable which reads in a source code file of PHP code and interprets/executes the commands written in that file. That's it. That's PHP's architecture in a nutshell.
That executable supports a default API which the userland PHP code can call, and it's possible to add extensions to provide more APIs. Those extensions are typically written in C and compiled together with the PHP executable at install time. Some extensions can only be added by recompiling PHP with additional flags, others can be compiled against a PHP install and activated via a configuration file after the fact. PHP offers the PEAR and PECL side projects as an effort to standardise and ease such after-the-fact installs. Userland PHP code will often also include additional third party libraries simply written in PHP code. The advantage of C extensions is their execution speed and low-level system access, the advantage of userland code libraries is their trivial inclusion. If you're administering your own PHP install, it's often simple enough to add new PHP extensions; however on the very popular shared-host model there's often a tension between what the host wants to install and what the developer needs.
In practice a web service written in PHP runs on a third party web server, very often Apache, which handles any incoming requests and invokes the PHP interpreter with the given requested PHP source code file as argument, then delivers any output of that process back to the HTTP client. This also means there's no persistent PHP process running at all times with a persistent state, like Java typically does, but each request is handled by starting up and then tearing down a new PHP instance.
While Java simply saves persistent data in memory, data persistence between requests in PHP is handled via a number of methods like memcache, sessions, databases, files etc.; depending on the specific needs of the situation. PHP does have opcode cache addons, which kind of work like Java byte code, simply so PHP doesn't have to repeat the same parse and compile process every single time it's executing the same file.
Do keep in mind that it's entirely feasible to write a persistent PHP program which keeps running just like Java, it's simply not PHP's default modus operandi. Personally I'm quite a fan of writing workers for specific tasks on Gearman or ZMQ which run persistently, and have some ephemeral scripts running on the web server as "frontend" which delegate work to those workers as needed.
If this sounds like a typical PHP app is much more of a glued-together accumulation of several disparate components, you'd be correct. Java is pretty self-contained, except for external products like RDBMS servers. PHP on the other hand often tends to rely on a bunch of third party products; which can work to its advantage in the sense that you can use best-of-breed products for specific tasks, but also requires more overhead of dealing with different systems.
This is how does PHP work:
(one of the best over the Internet)
In general terms, PHP as an engine interprets the content of PHP files (typically *.php, although alternative extensions are used occasionally) into an abstract syntax tree. The PHP engine then processes the translated AST and then returns the result given whatever inputs and processing are required.
Below image will depict more information
Source: freecodecamp.org

Integrate a php module in a Java web application

I am having one enterprise application developed using j2ee technology. I also have some php application. I want to merge the php application in my enterprise application to enhance the functionality without rewriting the code in j2ee. Could anyone please suggest me how to do this. I did some research on this and found following options
PHP & Java bridge - In this I will run tomcat behind apache server. The php module will be in apache and j2ee app in tomcat. This seems to be the opposite of how I would want my app to run. As the user registers in j2ee app and will also use the module build in php. So I would want my tomcat server to be oin front.
Install php on tomcat and run the php module in tomcat server. I tried many times to configure this with PHP5+ and tomcat6+ but not able to do that. I also could not find proper php & tomcat version combination which works together.
Please help me to find the best option (open for any new options as well) keeping application performance in mind.
running the PHP part on Apache httpd and the java part on Tomcat "behind" it is not that wrong. The fact that Tomcat is behind apache server is only a matter of connection flow, but from a user POV /forum/page.php will be handled by PHP, while /supercomputation/dothat will be handled by java.
The only problem is how you put the two together on the same page, if you need to, cause in this case only server side includes, iframes or javascript pop on my mind.
Another approach is to install PHP on a separate server, even another httpd on a different port, eventually listening only on 127.0.0.1, and then use a java server side component to "fetch" PHP output and merge it in the page generated by tomcat.
It might sound a hack, but it's not that hard at all, is already supported by many frameworks, and I've seen enormous web sites in production with a java based "frontend" that aggregated contents coming from other PHP and Python subsystems.
Whatever solution you decide to adopt, you'll need to setup some coordination between the two systems ... for example, single authentication for users. How to do that heavily depends on how those applications are designed, and will probably need some tuning here and there.

Running PHP scripts without having to install software?

Is there anything I can use to have PHP execute in a self contained environment without having to install server software?
haven't learned other languages :-(
I wanted to write a simple php/XML webapp that can be used on a desktop machine with no admin rights. It's for daily data entry stuff myself and others have to do when certain tasks are completed. Its a work machine and security is super high so can't have the details traversing the internet to my hosting.
Any suggestions?
XAMPP Portable might be what you are looking for. You don't need admin rights to run it.
http://portableapps.com/apps/development/xampp
Regardless of what language you use, in order to have a webapp, you need a web server of some sort, to listen to requests and send a response back (even if it's just listening to localhost). It is possible to run php from a command line without a server, but I don't know if you want to convert your application to a command line one.
Assuming you're using Windows, there are solutions for compiling PHP into an exe file (a quick google search found Phc-win, for example). However, I've never actually done this myself so this be sure to fully investigate what this would entail! You'd most definitely need to rewrite your views to use some way of creating actual dialogs in Windows (ie. WinBinder, or wbObjects).
(Of course, if you wanted to convert it to a desktop app the best solution is to actually use a language meant for desktop development, but if you only know PHP and don't want to spend the time learning something else, this could suffice, I guess.)

Run Apache / PHP / MySQL (CakePHP) application on a USB stick?

I have an existing CakePHP that runs on a LAMP environment and need to install it on a USB drive for mass public distribution.
There are a few requirements:
Protect the source code
No installation required
Windows support essential
MAC & Linux would be a bonus
Must run offline, without Internet connection
Ability to sync with server for data transfer and updates
I have conducted a large amount of research into the options and am keen to learn what other developers think.
Potential solutions:
- Flash / XML
- Adobe AIR app
- USB webserver (Server2Go, Portable Apps XAMPP)
Has anyone used any of the above, any comments would be greatly appreciated.
Thanks
Similar thread here :
Portable USB Webserver
If you ask me, XAMPP should do, because it offers a "plain unzip" version. There's lots of variety out there - Bitnami also offers a nice bunch of stacks, although they may not be good for this particular task.
To keep the same scripts in both Windows and Linux, you could consider using UnxUtils which is a port of all common Linux commands. This will be very handy if you are good at Linux bash shell scripting but not good at Windows batch files.
Protecting the source code is a bit troublesome. Do you really, really need to do so? Because there's a ton of great open source code out there which already does practically everything in most common business domains - sourceforge.net.
And if someone's taking your code and calling it their own, you can just name them on the internet if you can prove it. That itself will be bad publicity for them. That said, I obviously don't know your specific need. So that is just my opinion.
You will have problems with this, no matter how you go about it. Each step is a little more unusual it seems.
You'll need to use a source code obfuscator to protect your source. I recommend the one by Zend, not from experience, but because Zend makes awesome products. Never used a source protector myself.
You'll need three custom LAMP/MAMP/XAMP installs, one for each target OS. They should point to a directory that is shared on the USB drive. Make sure you configure them to use an unprotected port, otherwise the user will need admin privileges to run the server software. And getting the server stuff up and running will likely result in a few hiccups as well.
I would actually recommend finding something that will allow you to distribute a binary, or something like an AIR app that is intended for this type of distribution. You may have to rewrite lots of code, but it'll be easier to fix than all the niggling little install errors you'll see on the client end. To package scripts into binaries without rewriting stuff, check out http://www.scriptol.com/apollo.php and similar products.
But I'd suggest you make a standalone app in adobe air that will sync with your server (maybe even some google gears integration, to have it function offline). Don't try to force a PHP app into this distribution model, it'll create nightmarish problems.
This is what I used to run a CakePHP app from a DVD. Worked on USB too (while I was still developing it).
http://www.server2go-web.de/
Server2Go is a Webserver that runs out of the box without any installation and on write protected media. This means that web applications based on Server2Go can be used directly from cdrom, a usb stick or from any folder on a hard disk without the hassle of configuring Apache, PHP or MySQL.
Server2Go allows you to create a standalone working web site or PHP application on a CD-ROM.
It's really nice.
You can use MAMP for Mac, you'll just need to edit the config to properly point the sites directory.
however you would have the problem that the mysql db would not necessarily work with windows. if you switched the db to sqlite, you could sync the sqlite db file fairly easily.
XAMPP would work for the windows side
sorry dont know about the linux side.
Out there is a CakePHP InstaWeb Server
http://bakery.cakephp.org/articles/view/the-cakephp-instaweb-webserver
that runs on python and doesn't need an installation. This plus some additional goodies should get you already half the way.

WebServer for existing app

We have an existing windows desktop app written in C# 6 that uses an MDB MS access database for its storage. I need to write a web interface that can read that php webpage and maybe write to it later on.
This web interface will be included with our current installer for the application or as a simple addon. The user should only have to click start server and it should just work serving the php pages from the installation directory.
I was playing with gwan, nginx, quickphp. Only the last one seems simple enough to work.
So my question is what do or would you use to achieve this? Are there alternatives to quickPHP?
Distribution. I'd also like to have something we can include in the installer. I dont want the user to have to do and download any additional apps.
I know you said PHP, you also mentioned your app is written in C#.
You might want to take a look at aspnetserve if you are willing to write the web part in .NET. It might be possible to use PHP with it, but I don't know.
Either way I have found it very useful in several projects.
If you can live with other types of server side scripting than php, Microsoft's Cassini server looks like potentially a very good match (.net based, source available, small, ...).
Oddly enough it's hard to find a "canonical" url for it but Googling or searching here on SO brings back plenty of links.
Edit: an at first sight surprising feature may be that out of the box Cassini only seems to listen to localhost (127.0.0.1). However, as explained here,
Cassini only listens to localhost requests (for security reasons) -- it
uses IPAddress.Loopback in the code. You can find the code in Server.cs and
you can change it to IPAddress.Any to enable access from other machines. Of
course, you'd be opening up the port for outside access, so you need to be
aware of the security implications.
Or go with UltiDev Cassini
EasyPHP
Lampp
For a light-light-weight server without installation you can look at nanoweb portable. I am not sure how performant it is though.
Are there alternatives to quickPHP? The user should only have to click start server and it should just work serving the php pages from the installation directory.
G-WAN works like this (zero-configuration): scripts and "edit & play".
And G-WAN v3.10+ supports C#, Java and PHP scripts (all natively).

Categories