Peter Davies

Ramblings

Apache 2.4 on RHEL 6 from Software Collections

RHEL 6 ships Apache 2.2.15 and that is what it will stay on for the life of the release. If you want 2.4 (event MPM, Require access control, better proxy and FastCGI support) you don't replace the system package, you install 2.4 next to it from a Software Collection. My short note from a few days ago got it running; this is the full version, including the parts that bit me when I pointed an existing Virtualmin server at it.

Where to get httpd24

There are two sources:

# RHEL with a Software Collections subscription
subscription-manager repos --enable rhel-server-rhscl-6-rpms
yum install httpd24 httpd24-mod_ssl

# or the community repository
curl -s https://repos.fedorapeople.org/repos/jkaluza/httpd24/epel-httpd24.repo > /etc/yum.repos.d/epel-httpd24.repo
yum install httpd24-httpd httpd24-mod_ssl

Where everything lives

A collection installs under /opt/rh/<collection>/root, so nothing collides with the base system. Check what you got:

rpm -ql httpd24-httpd | grep sbin
/opt/rh/httpd24/root/usr/sbin/apachectl
/opt/rh/httpd24/root/usr/sbin/fcgistarter
/opt/rh/httpd24/root/usr/sbin/htcacheclean
/opt/rh/httpd24/root/usr/sbin/httpd
/opt/rh/httpd24/root/usr/sbin/rotatelogs
/opt/rh/httpd24/root/usr/sbin/suexec

The other paths worth knowing:

/opt/rh/httpd24/root/etc/httpd/conf/httpd.conf   main config
/opt/rh/httpd24/root/etc/httpd/conf.d/           extra config, ssl.conf
/opt/rh/httpd24/root/etc/httpd/conf.modules.d/   LoadModule lines
/opt/rh/httpd24/root/usr/lib64/httpd/modules/    the 2.4 modules
/opt/rh/httpd24/root/var/www/html/               default document root
/var/log/httpd24/                                logs
/etc/rc.d/init.d/httpd24-httpd                   init script

The binaries aren't on your PATH. Either use the full path or start a shell with the collection enabled:

scl enable httpd24 bash
apachectl -V

Swap the services

Stop 2.2, start 2.4, and make sure only 2.4 comes back after a reboot:

service httpd stop
chkconfig httpd off
service httpd24-httpd start
chkconfig httpd24-httpd on

Browse to the server and you should get the 2.4 test page. Don't yum remove httpd: Virtualmin, Webmin and a number of other packages depend on it, and you may want to switch back.

Making Virtualmin use it

Virtualmin writes its virtual hosts into /etc/httpd/conf/httpd.conf. The quickest way to get 2.4 reading the same config is to replace the collection's config file with a link to the old one:

cd /opt/rh/httpd24/root/etc/httpd/conf
mv httpd.conf httpd.conf~24
ln -s /etc/httpd/conf/httpd.conf httpd.conf

Then tell Webmin which Apache to drive. In Webmin go to Servers, Apache Webserver, Module Config and set:

Apache server root directory    /opt/rh/httpd24/root/etc/httpd
Path to httpd executable        /opt/rh/httpd24/root/usr/sbin/httpd
Path to apachectl               /opt/rh/httpd24/root/usr/sbin/apachectl
Command to start Apache         service httpd24-httpd start
Command to stop Apache          service httpd24-httpd stop
Command to apply configuration  service httpd24-httpd reload

Leave the config file path pointing at /etc/httpd/conf/httpd.conf so new virtual servers keep landing in the file 2.4 is now reading. Afterwards run System Settings, Re-Check Configuration in Virtualmin so it picks up the new version number; it writes slightly different directives for 2.4.

Fixing the 2.2 config

This is where the time goes. The 2.2 file won't start under 2.4 as it is. Always test before restarting:

/opt/rh/httpd24/root/usr/sbin/apachectl -t

The changes I had to make:

ServerRoot and modules. The old file has ServerRoot "/etc/httpd" and a block of LoadModule ... modules/mod_x.so lines, which resolve to the 2.2 modules. Point ServerRoot at /opt/rh/httpd24/root/etc/httpd, delete the old LoadModule block and pull in the 2.4 one instead. 2.4 also needs an MPM chosen explicitly and a couple of modules that used to be built in.

ServerRoot "/opt/rh/httpd24/root/etc/httpd"
Include conf.modules.d/*.conf

Access control. Order, Allow and Deny are gone in favour of Require:

# 2.2
Order allow,deny
Allow from all

# 2.4
Require all granted

mod_access_compat will keep the old syntax working while you convert, but don't mix both styles in one block; the results are hard to predict.

Removed and renamed directives:

NameVirtualHost     remove it, 2.4 ignores it and warns
LockFile            replaced by Mutex
SSLMutex            replaced by Mutex
MaxClients          now MaxRequestWorkers
MaxRequestsPerChild now MaxConnectionsPerChild
DefaultType         remove it

PHP. The mod_php from the base RHEL 6 PHP 5.3 packages is built against 2.2 and will not load into 2.4. Run PHP through FastCGI instead: Virtualmin's per-domain fcgid mode works once mod_fcgid for httpd24 is installed, or use a PHP collection that ships a module for httpd24.

The other trap is that you are editing the config of the web server you are connected through, if you manage the box through Webmin. Keep two SSH sessions open: edit in one and test and restart from the other, so a broken config never leaves you without a way back in.

Logs now go to /var/log/httpd24/ for anything not defined per virtual host, so check there when it refuses to start.

Today: RHEL 6 left maintenance support in November 2020. If you're still on it, the job is moving the sites to a current release, not upgrading Apache in place.