7. PHP + ShimmerCat¶
Here is a simple application that talks to a PHP backend:
This is a very basic PHP application.
To run it, open a couple of terminals in the folder
that you get after uncompressing the .zip file (i.e., the
folder where the README file is) and in one
of the terminals execute shimmercat devlove, while
in the other execute your favourite PHP script host.
Examples of the later would be:
php-cgi -b 127.0.0.1:8095
or
hhvm -m server -p 8095 -d hhvm.server.source_root=`pwd`/backend
or if you want to use FastCGI with HHVM:
hhvm --m server -d hhvm.server.type=fastcgi -d hhvm.server.port=8095
Of course, it’s also possible to use PHP-FPM, but we don’t cover it here because PHP-FPM always requires long, well-thought configuration files that deserve their own series of articles.
In all the cases, ShimmerCat will detect automatically if the PHP backend is talking
FastCGI or HTTP/1.1 (unless the protocol is indicated in the devlove.yaml).
This detection however is only made the
first time that the server can successfully connect to the backend.
If after that the protocol of the backend changes without restarting
ShimmerCat, you will likely get a screen like the one below:
7.1. Notes¶
The example above is made using electric domains and the re-write engine.
7.1.1. Frontend assets and PHP files are separated.¶
A little bit unconventionally for PHP, we put backend
files in a different folder than frontend files.
We find that this is more secure than mixing them, since it makes a lot
harder to just fetch the PHP sources of the application by unauthorized
agents.
However, this separation is not compulsory;
it is possible to set root-dir and document-root to point to the same directory.
In the example above, CSS, Javascript and image files should be put as usual below
the root-dir.