PHP script execution mode issue

11 posts / 0 new
Last post
#1 Tue, 06/20/2017 - 13:26
Parapluie

PHP script execution mode issue

I have upgraded my php from 5.3.3 to 5.4.45.

After the install, the server still served up html, but merely downloaded php scripts to my client machine.

I think I have narrowed down the issue, but I need help from this community.

I have found that switching Virtualmin/Server-Configuration/Website-Options/PHP script execution mode from the Virtualmin default of "FCGId" to "Apache mod_php (run as Apache's user)" will allow the script to be run, even though it only serves up a blank page.

The approach I would prefer to take would be to use the Virtualmin default of "FCGId". I suspect the php is producing blank pages due to some permissions error, and using the permissions structure created by the original Virtualmin virtual server install would bypass the need to reset permissions manually. (Ugh.)

Can you please let me know what the issue with FCGid might be? (ie. What the code should look like, and where in the Virtualmin system it should be located?)

System deets: CentOS release 6.9 (Final) 2.6.32-696.1.1.el6.x86_64 PHP Version 5.4.45 Let me know if you need more info.

Thanking you in advance.

Tue, 06/20/2017 - 15:33
adelphia
adelphia's picture

If it's downloading your PHP scripts / webpages rather than displaying them, take a look here...

Chris: Adelphia Interactive
Desktop: Windows 10 Pro x64
Server: Ubuntu 16.0.4.2LTS
Webmin/Virtualmin: Latest (daily updates)

Wed, 06/21/2017 - 07:38 (Reply to #2)
Parapluie

A.

I've been to that page and tried my best to follow it's instructions. Here are the relevant lines from my conf file:

DSO section includes:

LoadModule php5_module modules/libphp5-zts.so
LoadModule php5_module modules/libphp5.so

Directory section:

<Directory /home/myvirtualserver/public_html>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source  .phps
AddType application/x-httpd-php5.4 .php5.4
</Directory>

The file I am editing is: /etc/httpd/conf/httpd.conf. I note this just in case the virtualmin structure uses another file.

Wed, 06/21/2017 - 13:10
adelphia
adelphia's picture

Well, it depends how you have VM configured. Typically I believe, by default, VM uses host files generated in /etc/apache2/sites-available but if you forced it to use http.conf then that would be the correct location. If it uses what I believe are the default settings then it would use the path I have stated and there would be an individual file for each domain. Juts out of interest, do you get any errors generated when you run the VM re-check configuration (under Virtualmain -> System Settings).

Chris: Adelphia Interactive
Desktop: Windows 10 Pro x64
Server: Ubuntu 16.0.4.2LTS
Webmin/Virtualmin: Latest (daily updates)

Wed, 06/21/2017 - 14:17
Parapluie

Yeh… this could be part of the problem. I do not have an /etc/apache2 directory.

If I look under homes/myvirtualserver I do not see an apache2 directory there either.

On a side note, homes/myvirtualserver contains both an fcgi-bin directory, and an etc directory containing a php.ini file, and php5 and php5.4 directories.

Here is what Re-check configuration renders unto us:

The status of your system is being checked to ensure that all enabled features are available, that the mail server is properly configured, and that quotas are active ..
Your system has 7.66 GB of memory, which is at or above the Virtualmin recommended minimum of 256 MB.
BIND DNS server is installed, and the system is configured to use it.

Mail server Postfix is installed and configured.

Your Postfix version does not support per-domain outgoing IP addresses.

Apache is installed.

The following PHP versions are available : 5.4.45 (/usr/bin/php-cgi), 5.4 (mod_php)

PHP-FPM support was not detected : No FPM configuration directory found

Webalizer is installed.

Apache is configured to host SSL websites.

MySQL is installed and running.

ProFTPD is installed.

Logrotate is installed.

SpamAssassin and Procmail are installed and configured for use.

ClamAV is installed and assumed to be running.

Plugin DAV Login is installed OK.

Plugin AWstats reporting is installed OK.

Plugin Protected web directories is installed OK.

Using network interface eth0 for virtual IPs.

Default IPv4 address for virtual servers is 67.555.55.213.

Default IP address is set to 67.555.55.213, which matches the detected external address.

Both user and group quotas are enabled for home and email directories.

All commands needed to create and restore backups are installed.

The selected package management and update systems are installed OK.

Chroot jails are not available : The Jailkit command jk_init was not found on your system - maybe the packet is not installed?

.. your system is ready for use by Virtualmin.
Wed, 06/21/2017 - 14:45
Diabolico
Diabolico's picture

On Centos you will never have /etc/apache2 directory and all the files are located inside /etc/httpd/.

Check /etc/https/httpd.conf under ########:80 and ########:443 and you should have something like this:

AddType application/x-httpd-php .php
AddHandler fcgid-script .php
AddHandler fcgid-script .php7.1
FCGIWrapper /home/VIRTUAL_SERVER/fcgi-bin/php7.1.fcgi .php
FCGIWrapper /home/VIRTUAL_SERVER/fcgi-bin/php7.1.fcgi .php7.1

I'm using PHP 7.1 but it should be easy to change to whatever PHP version you are using.

- I often come to the conclusion that my brain has too many tabs open. -
Failing at desktop publishing & graphic design since 1994.

Wed, 06/21/2017 - 15:30
adelphia
adelphia's picture

Sorry, I missed the part about CentOS - sorry if I led you up the garden path. Hopefully Diabolico's answer may give you the results you seek.

Chris: Adelphia Interactive
Desktop: Windows 10 Pro x64
Server: Ubuntu 16.0.4.2LTS
Webmin/Virtualmin: Latest (daily updates)

Wed, 06/21/2017 - 19:43
Parapluie

That's okay Adelphia, I figured out what you meant and no garden path was trod.

But my issue stands.

Both of you, Thanks for this. I think we're getting somewhere. Here's what I have now.

Diabolico, when I copied your syntax with my own version (same for 80 and 443):

AddType application/x-httpd-php .php
AddHandler fcgid-script .php
AddHandler fcgid-script .php5.4
FCGIWrapper /home/myvirtualserver/fcgi-bin/php5.4.fcgi .php
FCGIWrapper /home/myvirtualserver/fcgi-bin/php5.4.fcgi .php5

I got a filename error "Wrapper /home/myvirtualserver/fcgi-bin/php5.4.fcgi cannot be accessed: (2)No such file or directory".

Checking the fcgi-bin directory, I see the file is called php5.fcgi. Is this the correct file?

It's contents are here:

#!/bin/bash
PHPRC=$PWD/../etc/php5
export PHPRC
umask 022
export PHP_FCGI_CHILDREN
PHP_FCGI_MAX_REQUESTS=99999
export PHP_FCGI_MAX_REQUESTS
SCRIPT_FILENAME=$PATH_TRANSLATED
export SCRIPT_FILENAME
exec /usr/bin/php-cgi

I am curious about the "PHPRC=$PWD/../etc/php5" line. What is $PWD? If I know that, then I can check that directory.

For now, I edited the path to re-link the php5.fcgi. And that's where I am now:

AddType application/x-httpd-php .php
AddHandler fcgid-script .php
AddHandler fcgid-script .php5.4
FCGIWrapper /home/myvirtualserver/fcgi-bin/php5.fcgi .php
FCGIWrapper /home/myvirtualserver/fcgi-bin/php5.fcgi .php5
Thu, 06/22/2017 - 03:16
adelphia
adelphia's picture

According to documentation, $PWD is the current working directory of PHP. This may be what's incorrect. I found this...

"PWD should be the current working directory (the directory where your .php file containing phpinfo() is stored)." Google "php pwd environment variable" and you'll find loads of info on it.

Chris: Adelphia Interactive
Desktop: Windows 10 Pro x64
Server: Ubuntu 16.0.4.2LTS
Webmin/Virtualmin: Latest (daily updates)

Thu, 06/22/2017 - 11:12
Parapluie

Wow. Whew. Prise the depths of the Web, and you shall find.

I found this after how many days?

So, I don't think the problem is in the php5.fcgi file, or in the path to the php package.

My current php scripts spit out blank pages, but a simple "echo" script and php_test() both work just fine.

I'll dig through my scripts to see what the compatibility issue is.

Many thanks to the fine citizens of this forum for your help. Adelpia and Diabolico, you both deserve medals.

Fri, 06/23/2017 - 13:42
Parapluie

Alrighty! I also got the compatibility issue figured out.

I thought I'd post the details here, for anyone finding themselves in the same boat in the future.

In short, the 3rd-party remi repository did not install the extensions in a manner usable by my set up (detailed in the OP).

Instead, php -v produced the error:

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/mysqli.so' - /usr/lib64/php/modules/mysqli.so: symbol mysql_client_errors, version libmysqlclient_18 not defined in file libmysqlclient.so.18 with link time reference in Unknown on line 0

As well as a couple of these:

PHP Warning:  Module 'mysql' already loaded in Unknown on line 0

I tried a few command-line solutions, but what worked in the end was to physically download the proper extension (from Remi's same repository, ironically --> link), and manually upload them to the proper directories:

usr/lib64/php/modules/mysqlnd_mysql.so
usr/lib64/php/modules/mysqlnd_mysqli.so
usr/lib64/php/modules/mysqlnd.so
usr/lib64/php/modules/pdo_mysqlnd.so
usr/lib64/php-zts/modules/mysqlnd_mysql.so
usr/lib64/php-zts/modules/mysqlnd_mysqli.so
usr/lib64/php-zts/modules/mysqlnd.so
usr/lib64/php-zts/modules/pdo_mysqlnd.so


Also, this version of php uses a separate directory of ini files for each active extension. You can set the extension variables here, but it is also the location where you activate the extension. Each of these files needs to be commented out:

etc/php/mysql.ini
etc/php/mysqli.ini
etc/php/pdo_mysql.ini
etc/php-zts/mysql.ini
etc/php-zts/mysqli.ini
etc/php-zts/pdo_mysql.ini


Like this:

; Enable mysqli extension module
; extension=mysqli.so


And these files (from the remi package) installed:

etc/php/mysqlnd_mysql.ini
etc/php/mysqlnd_mysqli.ini
etc/php/mysqlnd.ini
etc/php/pdo_mysqlnd.ini
etc/php-zts/mysqlnd_mysql.ini
etc/php-zts/mysqlnd_mysqli.ini
etc/php-zts/mysqlnd.ini
etc/php-zts/pdo_mysqlnd.ini


So, it's a bit of a dirty approach, but it's working like a charm.

Notes:

Floren adds some more explanation here about the strange file naming workaround.

And the "nd" (as in "mysqlnd") is explained here.

Hoping that this post helps someone out down the road.

Thanks again to Adelphia and Diabolico for all your help. I wouldn't have made it out of the gate without your posts above.

Topic locked