Best Apache + PHP configuration for a fresh server?

Razva

Member
Aug 30, 2012
16
1
3
cPanel Access Level
Root Administrator
Hey,

I'm currently deploying a fresh cPanel server (bare-metal). I don't need to migrate any old accounts so I can just have a fresh start.

I would like to:
  • offer "modern stuff" like http/2, compression, amp etc
  • use php-fpm as much as possible
  • offer caching (memcache, opcache etc)
  • isolate users/threads while dropping suPHP
  • allow users to benefit from WordPress's auto-upgrade feature (so Apache should run each user's processes via user, similar with the old suPHP configs)
  • support PHP7x exclusively (so no 5x required)
  • not use CloudLinux (CentOS 7)
  • have a snappy/light&functional config, without installing a ton of legacy stuff
The questions are:
  • What Apache MPM should I choose? Prefork doesn't allows http/2, right?
  • What Apache Modules should I choose?
  • What's the best/recommended caching method (memcache, opcache etc)?
Thank you,
Razva
 

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,304
363
Houston
Hello @Razva

To answer your questions please see the following:

What Apache MPM should I choose? Prefork doesn't allows http/2, right?
Prefork does allow http/2 but it does come with restrictions. Please see apache's documentation on this here: HTTP/2 guide - Apache HTTP Server Version 2.5 but you'd probably be just as well off if you're using worker unless you need prefork for compatibility reasons

What Apache Modules should I choose?
We can't tell you all the apache modules you'll need but you might want to look up some for your specific needs though you will get a lot of these on a default cPanel installation but here are some other threads that go over this info:

apache modules required

And documentation on modules as well as default apache profiles that come with cPanel's EA4:
Apache Modules - Easy Apache - cPanel Documentation


What's the best/recommended caching method (memcache, opcache etc)?
I'm not sure if I can tell you which would be better for you since they serve somewhat different purposes but here is some further information on both opcache and memcache:

Apache Module: MemCache - Easy Apache - cPanel Documentation
PHP Extension: OPCache - Easy Apache - cPanel Documentation

To Memcache or Not?
Installing memcached on WHM server
Installing memcache and memcached with EasyApache4


Is "All PHP Options + OpCache" option safe to use?
PHP-FPM and Opcache
Configuring Opcache across multiple accounts
 

Razva

Member
Aug 30, 2012
16
1
3
cPanel Access Level
Root Administrator
but you'd probably be just as well off if you're using worker unless you need prefork for compatibility reasons
What "compatibility reasons" should I consider? Is there some user script/cms that might not work in a certain configuration, or we're talking about this?

We can't tell you all the apache modules you'll need
The question is basically about suPHP vs ruid vs "other cgi modes". I'm interested in something that offers caching + user isolation + scripts should be run under/for each user (needed for cms's auto-upgrade functions) + fpm.

I've read a ton of stuff/docs and things got really "blurry" at this point. There's fpm and lsphp, there's ruid and workers and prefork and and and. Obviously a lot of stuff doesn't work with "the other stuff" so everything needs to be combined in an acceptable manner. Hence the subject of this thread.

So again, my target is to:
  • run "modern" protocols (http/2 etc)
  • run "as much fpm as possible" as it has obvious speed/memory advantages
  • allow caching as this is vital for "everything 2018"
  • allow CMS auto-upgrades (so files written via apache/fpm should be owned by the user not by the daemon)
  • have a setup as secure as possible for a non-CloudLinux environment
Thank you
 

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,304
363
Houston
Hi @Razva

prefork is basically compatible with basically everything but in your case since you want to use http/2 due to the restrictions imposed I think you'd be better off with worker .
From Apache:
This Multi-Processing Module (MPM) implements a non-threaded, pre-forking web server. Each server process may answer incoming requests, and a parent process manages the size of the server pool. It is appropriate for sites that need to avoid threading for compatibility with non-thread-safe libraries. It is also the best MPM for isolating each request, so that a problem with a single request will not affect any other.
You can read about here: prefork - Apache HTTP Server Version 2.4

You can also read the other MPM descriptions such as worker here worker - Apache HTTP Server Version 2.4

I would suggest reading about them both, stackoverflow has some great discussions on the benefits and demerits of them both which I would suggest looking into.

If you're going to be using CloudLinux the following goes over the most Optimal base EasyApache profiles for CloudLinux EasyApache Profile Stage - Easy Apache - cPanel Documentation - LSPHP wouldn't be a bad choice if you're going with CloudLinux as well. There's some wonderful information on LSPHP at Cloudlinux's docs here: CloudLinux Documentation

I understand it's a lot of information and it can be daunting but we can't point to one configuration and say "that's the one" as a lot of it is going to depend on preference. You might also want to work with a system administrator to determine the best configuration for your content. If you don't have one you may find one here: Resources | cPanel Forums.

Thank you,
 

Razva

Member
Aug 30, 2012
16
1
3
cPanel Access Level
Root Administrator
If you're going to be using CloudLinux the following goes over the most Optimal base EasyApache profiles for CloudLinux
As specified before I don't want to use CloudLinux, hence the questions about fpm/lsphp.

The default cPanel install (after fresh install) has "nghttp2" (+libnghttp2). I couldn't find them on EA4. Any hints on this?

Thanks
 
Last edited:

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,304
363
Houston
Hello

Those are http/2 C library and tools they're necessary for the function of http/2:

ea-nghttp2.x86_64 : Meta-package that only requires libnghttp2
ea-libnghttp2.x86_64 : A library implementing the HTTP/2 protocol

you can read about them here:
Nghttp2: HTTP/2 C Library - nghttp2.org

The actual http2 module is:

ea-apache24-mod_http2.x86_64 : HTTP2 module for Apache HTTP Server

You can use LSPHP without CloudLinux as well. They have instructions on how to install it on their site here: litespeed_wiki:cpanel:easyapache4-config [LiteSpeed Wiki]

But keep in mind if you don't want CloudLinux you'll need to use Litespeed (LSWS) as the webserver in order to utilize lsphp (it can be installed but the only way it would be useful without CloudLinux is to use Litespeed)
 

vlee

Well-Known Member
Oct 13, 2005
373
26
178
Spokane, Washington
cPanel Access Level
Root Administrator
You also can use mod_mpm_event with http/2

I run my server with mod_mpm_event with http/2

event - Apache HTTP Server Version 2.4

I have customized my servers in such as mod's and extensions in EasyApache and seem to work good.

It is all up to you on what and how you want your servers to do.
 
  • Like
Reactions: cPanelLauren