fred02138
fred02138

Reputation: 3371

PHP: JSON support missing after updating PHP version

I have a simple website hosted on a shared Linux server (by a company whose logo is an alligator). The default PHP version is 5.6.30. The cpanel for the server provides a page called MultiPHP Manager that enables me to update my site to PHP 7.x (same problem appears whether it's 7.0, 7.2, 7.3, or 7.4).

After updating to 7.x, the PHP JSON module seems to be missing (not reported in phpinfo()) when I run PHP through the web server (CGI, I think), but there is JSON support at the shell level.

I made this test file:

<?php
if (function_exists('json_decode')) {
    echo "JSON enabled";
}
else echo "JSON NOT enabled";

If I get a bash shell with ssh and run php json.php, it works (says enabled). But, if I run this file via the web server in public_html, it comes back disabled.

The tech support for the hosting service has been useless.

Upvotes: 2

Views: 1183

Answers (1)

fred02138
fred02138

Reputation: 3371

Ok, I believe I've figured this out.

This host uses suPHP to run PHP. By default, suPHP will not look in public_html or the home directory for a php.ini file. So, you need to add these lines to the .htaccess file in public_html:

<IfModule mod_suphp.c>
  suPHP_ConfigPath /home/username/public_html
  <Files php.ini>
    order allow,deny
    deny from all
  </Files>
</IfModule>

Once that's in place, you can add this line to the php.ini file in the public_html folder:

extension=json.so

And, of course, if you require other modules, you will have to add extension= lines for those as well. What a pain . . .

Upvotes: 2

Related Questions