On a VPS with centos panel I've Apache as webserver and Nginx as reverse proxy.

I've heard that the second is faster than Apache to handle PHP requests and I'd like to configure it as WebServer for 1 website, but I still need Apache for another one.

Is it possible?

My goal is to speed up the serving time of php pages. For example wp-admin/admin-ajax.php takes 7 seconds to render!!! I would expect 0,5 seconds.

  • 1
    You should consider going with php-fpm instead of cgi. That speeds up thing alot on apache and nginx. Apache 2.4 works great with PHP-FPM – Orphans Sep 26 '16 at 9:24
  • 1
    Do you have PHP opcode caching / user variable caching enabled? Without caching Wordpress is slow. – Tero Kilkanen Sep 26 '16 at 9:37
  • 13
    If Apache is that slow, there is a problem somewhere in your environment and you should try to fix that problem instead of just randomly replace components of your setup. – Sven Sep 26 '16 at 9:49
  • 1
    You can host multiple websites on nginx. See these for examples: digitalocean.com/community/tutorials/… stackoverflow.com/a/11778085/1590323 – stomstack Sep 26 '16 at 10:54
  • 4
    @Revious I highly doubt Apache or Nginx is going to improve your speeds in the slightest bit. I'm no WordPress expert but 37 plugins sounds like a lot and I have a feeling that they are not very well optimized. Are you using PHP 5 or 7? If you are using PHP 5 then the upgrade to 7 should cut your load times in half but 3.5 seconds still sounds quite slow. – MonkeyZeus Sep 26 '16 at 13:09

AFAIK you can't have two processes listening on the same port (80/http) on one machine, so probably not in parallel as such.

However you could have Nginx listening on port 80, Apache listening on another port (81), and have Nginx pass applicable requests to Apache. Each would then pass the request off to wherever it needs to go, PHP for example. However this is probably very similar to what you have now, so I'm not quite sure it's what you're looking for.

Perhaps if you describe your setup and goals a little more fully we could help more.

Update PHP being slow is unlikely to be with the web server. You'll need to look at the resources used, dig into the code, check logs, and see what's going on. You can use Nginx Page Caching or Microcaching for rapidly changing websites to massive increase the speed for anonymous users. Caching reduces server load so also reduces page generation time for logged in users.

PHP isn't the fastest language around, though if properly resourced it's ok. HHVM is another PHP interpreter that's faster than PHP5, but I found it didn't work well for Wordpress with the plugins I use. PHP7 is faster, but again I had trouble with some plugins.

You've said it takes 7 seconds to render the page. Have you done a test using something like webpagetest.org to determine what part of the page load is slow? It can help tell you if it's page generation, dependent resources, etc.

You should also consider a CDN, such as CloudFlare, which has an effective free tier.

  • I've edited the question. The problem is with PHP. It's incredibly slow in my opinion. But I'm not very experienced in this field. – Revious Sep 26 '16 at 8:12
  • 3
    You cannot have two processes bound to the same IP address, port and protocol (TCP, UDP, ...) triplet. You can, however, have two processes that are bound to different triplets. So if the OP can change the IP address or port (protocol is usually more involved...) that either web server is bound to, then it is possible to run multiple web servers on a single host. – a CVn Sep 26 '16 at 11:23
  • @MichaelKjörling: Nitpick: "triple" (or "tuple" more generally) :) – Lightness Races in Orbit Sep 26 '16 at 11:40
  • 1
    I've expanded my post based on the new information available – Tim Sep 26 '16 at 18:30

This kind of performance problem is almost never caused by apache. I would run a PHP profiler and see what is slow. Check CPU usage and disk I/O usage. Do not waste you precious time in replacing the webserver when it is not the bottleneck. Take a look on the USE method (usage, saturation, errors): http://www.brendangregg.com/USEmethod/use-linux.html


Assuming you really need to run two different web servers concurrently on port 80 and you have two public IP addresses available, you could configure each Apache and nginx to listen on different IP addresses.

In Apache configuration:


In nginx configuration:


Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.