HowdyPython Posted August 28, 2013 Share Posted August 28, 2013 I just rent a VPS on DigitalOcean (SSD, 1GB ram) and I'm running CentOS 6. Should I use apache or nginx for a PHP CRUD application? I never had a SSD before and I'm not sure if anything changes. Quote Link to comment https://forums.phpfreaks.com/topic/281647-apache-or-nginx/ Share on other sites More sharing options...
will35010 Posted August 28, 2013 Share Posted August 28, 2013 The big thing with SSD is getting a lower disk TPS rate. I personally like to setup Apache to run on port 8080 and Nginx to run on port 80 to act as a reverse proxy to lighten the load on Apache. I also setup and tune php apc. This setup has allowed me to run some high traffic sites on really low cost boxes. Quote Link to comment https://forums.phpfreaks.com/topic/281647-apache-or-nginx/#findComment-1447217 Share on other sites More sharing options...
gizmola Posted September 5, 2013 Share Posted September 5, 2013 With a standard mod apache worker setup, apache forks child processes to handle requests. Of course you can see this doing a ps aux | grep apache or similar command, or you can run top and take a look at what is happening. Depending on the size of memory allocation of your php scripts, you may find that as time goes on, you get a set of apache processes with a significant memory footprint. It really depends on your code. In order to make this efficient apache will continue to reuse these child processes for a certain number of requests before the process is killed and a new one is created (this is configurable of course). This is a reliable and efficient configuration, with the downside that requests for static resources like images, css and .js files also have to be served by apache processes that have memory footprints reflecting their creation to serve a php request, even though (for that request) all that extra memory is not used. The net effect is that total memory becomes a fixed resource that limits the amount of requests the server can handle. In comparison, nginx with php-fpm will utilize php-fpm to serve the php requests, and of course there is still the same php memory issue, but as nginx is not allocating the php memory, it is much more efficient from a memory utilization standpoint, when serving the static elements of your site. As will pointed out you still will want to use apc in either scenario, so that your php scripts are coming out of a shared memory cache rather than being compiled on each request. Alternatively, you could do what he suggested and run nginx and apache (it's similar to nginx - php-fpm) but I lean towards using the php-fpm application server setup, since that's essentially what you are really doing in that sort of setup, but if you're more comfortable with apache, as he stated, it's a proven setup to have nginx proxy the requests for php scripts through to apache. If you do stay with apache it is important to go through the list of default modules and disable every single one that isn't absolutely essential, in order to minimize the amount of memory apache requires. This is an important first step, even if you just want to stay with apache for whatever reasons, in order to get the maximum capacity possible. Quote Link to comment https://forums.phpfreaks.com/topic/281647-apache-or-nginx/#findComment-1448310 Share on other sites More sharing options...
kicken Posted September 5, 2013 Share Posted September 5, 2013 The main issue I've had with switching to nginx is apps with extensive use of .htaccess/mod_rewrite rules can sometimes be a pain to convert over to the proper nginx configuration. If that is not an issue for you, then nginx + php-fpm seems to be a pretty nice setup. Apache + worker mpm + php-fpm is a decent setup as well. You separate apache from PHP so static resources do not incur any overhead from PHP, and the worker mpm is a mix of threaded and multi-process setups so rather than one process per request you only need a couple processes, each of which has several threads for processing requests. I've been going this route as it seems to provide about as good of performance as nginx + php-fpm while still maintaining .htaccess compatibility. Quote Link to comment https://forums.phpfreaks.com/topic/281647-apache-or-nginx/#findComment-1448356 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.