2

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.

Revious
  • 187
  • 1
  • 12
  • 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 09:24
  • 1
    Do you have PHP opcode caching / user variable caching enabled? Without caching Wordpress is slow. – Tero Kilkanen Sep 26 '16 at 09: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 09:49
  • @Orphans: thanks, I will try to understand which version of PHP I am using – Revious Sep 26 '16 at 10:49
  • @Sven: I've installed memcached but I'm not sure if I'm using it... I'm not very experienced... – Revious Sep 26 '16 at 10:54
  • 1
    You can host multiple websites on nginx. See these for examples: https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-on-centos-7 http://stackoverflow.com/a/11778085/1590323 – jobukkit Sep 26 '16 at 10:54
  • "admin-ajax.php takes 7 seconds to render".... So if you delete all of the code from that file and just go with ` – MonkeyZeus Sep 26 '16 at 12:51
  • @MonkeyZeus: no, a fraction of seconds. I've 37 plugins and 3000 users per day. – Revious Sep 26 '16 at 13:02
  • 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
  • @MonkeyZeus: PHP7 is compatible with WP? – Revious Sep 26 '16 at 20:34
  • @Revious [**Sure**](https://wordpress.org/support/topic/wordpress-and-php-7/) but I don't know if all 37 of your plugins are going to be flawless so try https://wordpress.org/plugins/php-compatibility-checker/ – MonkeyZeus Sep 26 '16 at 20:38
  • [**PHP version 5.6 or greater**](https://wordpress.org/about/requirements/) is the first thing listed. – MonkeyZeus Sep 26 '16 at 20:42

3 Answers3

9

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.

Tim
  • 31,888
  • 7
  • 52
  • 78
  • 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 08: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. – user 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
4

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

Mircea Vutcovici
  • 17,619
  • 4
  • 56
  • 83
0

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:

Listen 1.2.3.4:80

In nginx configuration:

listen 5.6.7.8:80