PHP and Django: Nginx, FastCGI and Green Unicorn? - php

I'm curious... I'm looking to have a really efficient setup for my slice for a client. I'm not an expert with servers and so am looking for good solid resources to help me set this up... It's been recommended to me that using FastCGI for PHP, Green Unicorn (gunicorn) for Django and Nginx for media is a good combination to have PHP and Django running on the same slice/server. This is needed due to have a main Django website and admin, but also to have a PHP forum on there too.
Could anyone push me to some useful resources that would help me set this up on my slice? Or at least, any views or comments on this particular setup?

I think one solution could be using a combination of PHP as apache module or through FastCGI and use mod_proxy apache module to do some reverse proxy to access your administration app running with gunicorn
You can have a setup like :
Front HTTP Server apache on port 80 : www.host.com:80
Backend HTTP Server gunicorn on another port : other.host.com:8080 or localhost:8080 publicly accessed with mod_proxy and url like www.host.com/admin/
Media HTTP Server : media.host.com, if it has to be on the same system you can use mod_proxy and run the NGINX server on another TCP port.
Note that you should not be able to get the best performance with the NGINX as a media server hidden behind apache with mod_proxy.
This part of setup relies upon the possibility of having more than one public IP adress on this slice.

I found this question and almost went down the path of using Green Unicorn myself. Just a note that uWSGI seems to give significantly better performance than Green Unicorn, see a set of benchmarks here.
Linode has a great howto for configuring uWSGI with Nginx on Ubuntu (it works fine on Debian too).
I'm now using this setup and very happy with it so far.

For the PHP part consider to install any PHP accelerator like eAccelerator or any other bytecode cache.
This is a more general article but could also be interessting for you.
For the Django part I have no idea / experience.

I've been trying to run django behind nginx with WSGI module. It runs OK and pretty fast.
You'll have to compile your own nginx, but it's really painless.

Related

GKE / running php apps / exposing via nginx or apache?

Not that much experienced in php, currently running a php app
The cluster uses an nginx ingress load balancer
The php container currently uses nginx (FROM that one https://hub.docker.com/r/wyveo/nginx-php-fpm/), so the pod is exposed via nginx
I'm having some weird behaviours by using this image, so I had in mind to give apache a shot, in case it would provide a more stable result
That is, it does not change the game; is there any other ways to run a php app in such context ? What would be the best way ?
Have you checked the official images?
For safety is better to use official images rather than other ones.
Check the php official repo, they have a version with apache installed.
I am not a php expert either, but the configurations I have made usually use apache to handle requests.
The official repo:
https://hub.docker.com/_/php
Check the tags that use apache. There are versions in stretch and alpine.

XAMPP can be used for production server which has windows OS

I am confused regarding using XAMPP as a bundled software for PHP , Mysql , Apache.
My specific requirements are as below
Production server needs to Windows OS (as i need some third party tools to be integrated and need to execute that by command lines and those thirt party tools supports only Windows OS)
Need to make application in Zend Framework 2.0
The points in which i have doubts are ,
We can run this application in IIS , but is ZF2 have performance issue with IIS ?
Can xampp used on production server ?
is there any alternate way to install PHP , Apache , Mysql individually , and it should be secure and reliable method .
Any help is appreciated.
Thanks in advance.
The performance will increase if you select the right components on windows.
For instance, if you use IIS, then also use the Wincache PHP extension.
In general: it is possible to secure a development server stack.
Install the stack and alter the settings until you get a safe environment.
I would suggest to use Nginx as the webserver and MariaDb as the database.
You might choose InnoDb for performance reason.
There is also the option to add Naxsi Firewall Rules to Nginx to secure the server.
For high-performance, especially streaming you might try this: http://nginx-win.ecsds.eu/
It's also worth to look at WPN-XM (sorry, shameless plug).
Keep in mind, that updating the components of your production system is key to keep it safe.
Keeping a production server environment save is easier on Linux, where you have a proper package management tool (e.g. apt-get).
But afaik, WPN-XM is the only server stack with a software registry on windows, which allows that.
For running Zend Framework 2 you need PHP.
You might also consider tweaking the Nginx configuration and add some rewrite rules for short-urls. But a small config like this would suffice: https://stackoverflow.com/a/19734670/1163786
To answer question 2 from your comment: Yes, Nginx and Apache can work together.
Nginx will act as reverse proxy before Apache and will only serve static files.
All request for static files will be very fast and it will consume less memory for concurrent requests because Nginx is event-based.
Apache would handle the non-static parts/ dynamic parts.
"I want Apache , PHP and Mysql only , so is that will be supported by Nginx."
It's possible.
Static request would be handled by Nginx.
Dynamic request would be handled by Apache, so ZF2 is served by Apache/PHP.
XAMPP, with a "secure" config, can be used in a production environment..but it's not recommended. XAMPP is just a stack of software for easy deploying a fully developer friendly environment.
With IIS you can gain performance, cause of it's caching mechanisms.
I would install MySQL, PHP without any software stack like XAMPP and add the IIS to the Windows Server. Configure everything and you are good to go.
If you don't wont to use IIS or Apache, try to have a look to nginx.

Is there some kind of portable server for running PHP web apps, something like for RoR or Django?

Currently I'm working on some PHP porjects. And it's a little bit difficult to navigate always through approximately 100 folders to the destination one. Also it's not very comfortable to create virtual hosts for Apache. And it would be much more comfortable to run from CLI command like "someserver start ." and then just go to the localhost:8080 in favorite web-browser and start enjoying the development process.
If you are thinking along the lines of a built-in server like Mongrel is for Ruby, then No. This doesn't exist for PHP as of PHP 5.3.6. A patch offering that is under discussion though:
CLI version of PHP will have a new command-line option -S followed by a host address (either in numeric or alphabetic) and a port number delimited by a colon, which will launch a builtin web server listening on the given address and port
php -S localhost:8000 docroot
Links:
Alexey Zakhlestins on PHP's Webserver
PHP Wiki Request for Comments: Built-in web server
Webserver Patch
For a complete self contained web development setup, you can use XAMPP. To simplify things further you can then just develop out of the htdoc or www folder provided by xampp.

Best single server solution for GWT, PHP, and SSL

So right now I'm rocking Apache 2.2, which I've had running for a couple years (only for local purposes). With Apache, I have PHP 5 installed. Recently I installed Tomcat 7 for Java Servlet support (GWT specifically). I also have Tomcat supports SSL (on a separate port which is annoying but manageable for now).
Here's my problem. GWT cannot use PHP pages and PHP cannot use SSL (unless I install that on Apache). What would be the best solution to get GWT, PHP, and SSL on single server or at least able to interact.
I was thinking maybe install PHP on Tomcat because it already has GWT and SSL ready but a quick Google search didn't show promise on this. Another option I've heard is that Apache can forward certain requests (such as Java Servlets) to Tomcat. I'm hoping someone has a quick answer to save me the headache of Googling.
Also, Apache is running on port XXX1, Tomcat XXX2, and Tomcat SSL XXX3. Is there a way to get these all on a single port? I'm guessing it'd have to be configured at the router/gateway and forwarded to each correct port?
Use Apache as a proxy for Tomcat, and have the SSL configured on Apache. You'll need to use mod_proxy for this. A sample configuration would look like this:
ProxyPass /tomcat/ http://127.0.0.1:XXX2/
You'd then access the Tomcat resources by prefixing a /tomcat/ to the URL path.
Resin is a Java application server with a full PHP5 implementation.
http://quercus.caucho.com/
Just completing the answer given by Jon, take a look to this configuration to serve the Tomcat applications from Apache.
Tomcat, it seems, can run PHP. Found that answer on another Thread which points to this handy tutorial. I'd still like to know if anyone has another solution?

recommended production environment for php5 application on windows?

We are about to deploy a php5 / symfony / mysql application on a windows stack (windows 2003 server)
Our IT department doesn't have much experience administering any other stuff but microsoft technology, so I'd like to know what configuration would you propose for a production environment...
apache and php on windows?
php on iis?
etc...
the application should use integrated security (that means the have should have some way to find get the domain/username of the logged user, in classic asp is as easy as Request.ServerVariables(“AUTH_USER”) )
it would also be very useful if you could point me to documentation on the subject.
This question and especiually the links in it may answer parts of your question: Apache vs. IIS PHP performance comparison
PHP works fine with IIS, although I've only been able to configure it to run with the site in the IIS directory hierarchy. (c:\inetpub\wwwroot). I've never been able to get it to run with a virtual directory outside that hierarchy.
Also, assuming that IIS is running (it is by default in Server 2003), IIS and Apache can't share port 80. If you have both running on the same box, one or the other will get port 80, but not both.

Categories