Switch from mod_fcgi to mod_php?

Our Nextcloud instance needs to use mod_php instead of mod_fpm or mod_fcgi so that it can copy large files to Samba shares. I'm not using the official CentOS 5.4 PHP repo because Nextcloud needs PHP 5.5 or higher. Instead I'm using Remi's PHP 7 repo.

From Nextcloud support:

How fast is the connection between your server and the SMB storage?

Official support (and test) is only for mod_php. There are often some issues with mod_fcgid and I can't tell you if there are some general restrictions or if it's just have to figure out a good setup (in contrast to mod_php or nginx, there is no example config to start from).

https://help.nextcloud.com/t/samba-mounts-and-file-locked-error/7116/5

Is there a way for me to do this?

Comments

Howdy -- it's no problem to use mod_php, though Virtualmin's ability to use multiple PHP versions only works when using CGI or FCGID.

With mod_php, that's an Apache module that works a bit differently, I don't know of a way to run multiple versions of that.

The key would be to figure out if your particular repository provides mod_php (which it probably does), and if so, to make sure it's being loaded into Apache.

That's typically setup in a conf file located in "/etc/httpd/conf.modules.d".

You'd likely need to disable the standard CentOS mod_php version in there while you're at it.

And then, take a peek at the various php configs located in /etc/httpd/conf.d, you'd want to disable the ones that come with your distro, and just use the ones for your particular third party repository.

I think the above should do what you're after, though I've never attempted to setup mod_php with an alternate PHP version before (and definitely not from the remi repo).

Give that a shot though, and let us know if that does the trick!

Just to be on the safe side, you may want to backup all those config files before making any changes.

Doesn't seem like mod_php is installed? Although when I grep'd for mod_php, it returned: [root@nextcloud ~]# yum list mod* | grep php * remi-php71: ca.mirror.babylon.network

Installed Packages mod_dav_svn.x86_64 1.7.14-10.el7 @base
mod_fcgid.x86_64 2.3.9-4.el7 @base
mod_perl.x86_64 2.0.10-1.el7 @epel
mod_ssl.x86_64 2:2.4.6-40.el7.centos.4.vm.2 @virtualmin Available Packages ModemManager.i686 1.6.0-2.el7 base
ModemManager.x86_64 1.6.0-2.el7 base
ModemManager-devel.i686 1.6.0-2.el7 base
ModemManager-devel.x86_64 1.6.0-2.el7 base
ModemManager-glib.i686 1.6.0-2.el7 base
ModemManager-glib.x86_64 1.6.0-2.el7 base
ModemManager-glib-devel.i686 1.6.0-2.el7 base
ModemManager-glib-devel.x86_64 1.6.0-2.el7 base
ModemManager-vala.x86_64 1.6.0-2.el7 base
mod_auth_cas.x86_64 1.1-3.el7 epel
mod_auth_gssapi.x86_64 1.4.0-1.el7 base
mod_auth_kerb.x86_64 5.4-28.el7 base
mod_auth_mellon.x86_64 0.11.0-2.el7 base
mod_auth_ntlm_winbind.x86_64 0.0.0-0.15.20070129svn713.el7 epel
mod_auth_openid.x86_64 0.8-1.el7 epel
mod_auth_openidc.x86_64 1.8.8-3.el7 base
mod_authnz_external.x86_64 3.3.1-7.el7 epel
mod_authnz_pam.x86_64 0.9.3-5.el7_2 base
mod_autoindex_mb.x86_64 2.18.1-2.el7 epel
mod_evasive.x86_64 1.10.1-22.el7 epel
mod_flvx.x86_64 0-0.7.20100525git.el7.1 epel
mod_form.x86_64 0.2-1.el7 epel
mod_form-devel.x86_64 0.2-1.el7 epel
mod_geoip.x86_64 1.2.10-1.el7 epel
mod_gnutls.x86_64 0.6-1.el7 epel
mod_intercept_form_submit.x86_64 0.9.8-2.el7 base
mod_lcgdm_dav.x86_64 0.18.0-1.el7 epel
mod_ldap.x86_64 1:2.4.6-40.el7.centos.4.vm.2 virtualmin mod_limitipconn.x86_64 0.23-14.el7 epel
mod_log_post.x86_64 0.1.0-7.el7.1 epel
mod_lookup_identity.x86_64 0.9.5-1.el7 base
mod_mirrorbrain.x86_64 2.18.1-2.el7 epel
mod_nss.x86_64 1.0.14-7.el7 base
mod_passenger.x86_64 4.0.53-4.el7 epel
mod_perl-devel.x86_64 2.0.10-1.el7 epel
mod_proxy_html.x86_64 2:2.4.6-40.el7.centos.vm.1 virtualmin mod_proxy_uwsgi.x86_64 2.0.14-3.el7 epel
mod_qos.x86_64 11.5-1.el7 epel
mod_revocator.x86_64 1.0.3-21.el7 base
mod_ruid2.x86_64 0.9.8-2.el7 epel
mod_security.x86_64 2.7.3-5.el7 base
mod_security_crs.noarch 2.2.9-1.el7 base
mod_session.x86_64 1:2.4.6-40.el7.centos.4.vm.2 virtualmin mod_speedycgi.x86_64 2.22-16.el7.1 epel
mod_wsgi.x86_64 3.4-12.el7_0 base
mod_xsendfile.x86_64 0.12-10.el7 epel
modello.noarch 1.7-4.el7 base
modello-javadoc.noarch

Does this make sense?

What output do you see if you run the command "ls /etc/httpd/conf.modules.d"?

ls /etc/httpd/conf.modules.d 00-base.conf 00-lua.conf 00-proxy.conf 00-systemd.conf 02-perl.conf 10-subversion.conf 00-dav.conf 00-mpm.conf 00-ssl.conf 01-cgi.conf 10-fcgid.conf 15-php.conf

On our Virtualmin server, which is using the SCL repository, mod_php is provided in the php56-php-5.6.29-1.el7.remi.x86_64 package.

There is a file named "libphp56-php5.so", and it's loaded using a line like this in the conf.modules.d directory:

<IfModule prefork.c>
  LoadModule php5_module modules/libphp56-php5.so
</IfModule>

What you would need to do is determine what package, if any, provides the mod_php module in the repository you're using, and then install and configure that particular package.

Sorry I'm really not familiar with packages from the remi repo, and how to get them to work.

You'd probably need to try it and see what happens.

Though I suspect you'd be able to have both of those installed at the same time, but I have never tried it before.

Mostafa's picture
Submitted by Mostafa on Sat, 01/07/2017 - 01:47

Yes, php70-php provides mod_php for php 7.0 , and you should note that mod_php can only be used when apache is set to use mpm_prefork. You dont need to remove php-fpm as it does not interfere with mod_php, and virtualmin (5.05gpl) still does not support it! (We are waiting for the next release of virtualmin which supports php-fpm)

Thanks, Mostafa. So what is the best way to switch my virtual host so that it uses mod_php instead mod_fcgi?

Mostafa's picture
Submitted by Mostafa on Sat, 01/07/2017 - 12:28

There is nothing special to do, mod_php is supported by Virtualmin, you just need to install php70-php package and make sure that apache in running with mpm prefork:

[root@ ~]# httpd -M | grep -i "php\|mpm" mpm_prefork_module (shared) php7_module (shared) [root@ ~]#

and then

virtualmin modify-web --all-domains --mode mod_php

Thanks again. So it looks like it's all there:

httpd -M | grep -i "php|mpm" mpm_prefork_module (shared) php7_module (shared)

But when I tried virtualmin modify-web --all-domains --mode mod_php, it returned: The selected PHP exection mode cannot be used with nextcloud.sesp.northwestern.edu

Changes web server settings for one or more domains.

virtualmin modify-web --domain name | --all-domains [--mode mod_php|cgi|fcgid] [--php-children number | --no-php-children] [--php-version num] [--php-timeout seconds | --no-php-timeout] [--ruby-mode none|mod_ruby|cgi|fcgid] [--suexec | --no-suexec] [--proxy http://... | --no-proxy] [--framefwd http://... | --no-framefwd] [--frametitle "title" ] [--style name] [--content text|filename] [--webmail | --no-webmail] [--matchall | --no-matchall] [--includes extension | --no-includes] [--default-website] [--access-log log-path] [--error-log log-path] [--document-dir subdirectory | --fix-document-dir] [--port number] [--ssl-port number] [--url-port number] [--ssl-url-port number] [--fix-options] [--letsencrypt-renew months | --no-letsencrypt-renew]

Mostafa's picture
Submitted by Mostafa on Sun, 01/08/2017 - 01:29

OK, I can reproduce this error, this's a bug in virtualmin that doesn't detect mod_php7 in apache 2.4 in Centos while it's installed. You may alter this issue to a Bug report.

I can see in php-lib.pl that virtualmin is looking for mod_php7 which is OK since the same name is used in /etc/httpd/conf.modules.d/15-php70-php.conf for the module however vm can't find it for some reason.

The issue appears to be from apache module of webmin since I can't see Configure Apache Modules in the apache module of webmin while Always detect Apache modules automatically? = Yes is set properly.

Darn, ok. This project is time sensitive so maybe I'll remove all of Remi's packages and go with php 5.6 from SCL.

sespit, if you run into that issue with the SCL packages, let us know and we can troubleshoot that with you.

FYI, I checked the Virtualmin code and there are some places in which mod_php7 is not detected properly. This will be fixed in the next release.

Hey Jamie,

How soon will that next release come? Would it be worth waiting for the fix?

Thanks,

Ryan

Or would it be possible to get a patch?

I can send you a fix if you like - which Linux distribution are you running, and which Virtualmin version (GPL or Pro).

Virtualmin Pro on Centos 7.3. Thank you!

Ok, emailing you an RPM now..

Thanks so much Jamie. Almost out of the woods.

I installed the RPM via rpm -Uvh, restarted the server, then reran the Virtualmin Pro configuration check to make sure VM is picking up the new settings.

However, since the change I'm not able to upload any files. I get a "Forbidden" message in Nextcloud. Might it be related to this? http://mysql-apache-php.com/fileupload-security.htm

Well, the problem with using mod_php is that it's not really designed for a multi-user setup. It runs everything as the Apache web server, rather than as your Virtual Server owner.

So if you wish to use mod_php, you'd need to ensure that the directories your web app needs to write to are writable by the Apache user (which I believe is "apache" on CentOS).

Ok, so even though Virtualmin created it's own user, I should change the ownership of all the files in public_html to apache:apache ?

PHP code only runs as the Virtual Server owner when using FCGID or CGI.

When using mod_php, all PHP code is run as the "apache" user.

In that case, any folder or file that your app needs to write to must either be mode "777", or owned by the "apache" user.