Codeigniter site migration to PHP7

I’ve been running a low-volume hobbyist site on DH for about 15 years now.

My last major re-write of the CodeIgniter source was ten years ago.

Now that the shared servers are being mass-migrated to PHP 7+, I need to upgrade the framework and tweak one or two deprecated PHP uses.

I have the migrated code working on my local WAMP workstation under PHP 7.4.

It will not work correctly on the DH server, LAMP.

One of the things I do in the old site is remove the framework’s index.php file from the URLs.

Works fine under the old CodeIgniter 2.x/PHP 5.6 configuration, not so under CodeIgniter 3.1.11/PHP 7.4 using the same basic configuration as the old server and htaccess file.

I haven’t hit on the proper configuration to get the code running on my dev subdomain yet and web searches find basic information dating back ten years or more.

Anyone have any input?

Thanks.

You could post your .htaccess file here (redact anything private), and see if anyone here can spot a problem.

The standard setup for CodeIgniter is described at:

https://codeigniter.com/user_guide/general/urls.html?highlight=rewriterule

This is a copy of the .htaccess file that has been in service for the CodeIgniter 2.0.2 site:

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript application/javascript text/css
AddOutputFilterByType DEFLATE application/javascript

RewriteEngine on

RewriteCond $1 !^(index.php|rss-feed.php|robots.txt|phpinfo.php|favicon.ico|apple-touch-icon.png|apple-touch-icon-47x47.png|apple-touch-icon-57x57.png|apple-touch-icon-72x72.png|apple-touch-icon-114x114.png|apple-touch-icon-129x129.png|index_header.php|index_navjavaphp.php|index_archivenavjavaphp.php|images|css|CSS|js|tmp|_Counters|Collections|awstats)
RewriteRule ^(.*)$ /index.php?/$1 [L]

This has been in service for ten+ years with the CI 2.0.2 code (I never felt a need to upgrade CI until now).

The CI config references:

$config[‘uri_protocol’] = ‘AUTO’; // used on the v2.0.2 site
$config[‘index_page’] = “”; // used on the v2.0.2 site

My web searches - so far - have returned CI configuration messages in this context ( removing the index.php reference in the URLs ) that date back ten or more years. I haven’t seen anything relating solely to CI 3.x, or even PHP 7.x

I’me leaning to to the problem being related to PHP 7.x, but I will also go through the CI migration notes for the chain all the way back to v2.0.2.

Note: I’m not a CodeIgniter expert (only played with it), so I’ll just ask some possibly stupid questions in the hope of helping.

Stupid question: Is the uri_protocol setting case-insensitive? The 3.1 Old docs refer to auto instead of AUTO.

Are your .htaccess rules working correctly under your local WAMP with Apache 2.4 (i.e. matching DH’s Apache)?

From the rewrite rule, it looks like you are using the query-string to pass the URI. Possibly making that explicit with in the uri_protocol setting might help? i.e.:

$config['uri_protocol'] = "query_string";

Alternatively, maybe switching to the path_info protocol (CI’s default?) and using the default CI .htaccess rules would help?

Actually, looking at the 3.1 configuration template, it looks like AUTO isn’t a supported option:

Thanks for the help…

Not a stupid question at all… on point, actually. I haven’t checked, but I would imagine that the $config[‘uri_protocol’] is either not case sensitive, or wasn’t under CI2.x.x.

EDIT: I just checked the CI 3.1.11 code and it does seem to be case-sensitive, looking for upper case values. I’m kind of surprised that they didn’t slap a strtoupper() on the value before testing it.

While I did have that .htaccess file in my WIMP site root, I have just removed it and it appears to still work locally. I haven’t done an exhaustive test.

This is an excerpt from the configuration file on my running DH/CI2.0.2 site:

if (stristr(PHP_OS, ‘WIN’)) {
$config[‘uri_protocol’] = ‘REQUEST_URI’;
} else {
$config[‘uri_protocol’] = ‘AUTO’;
}

I have different values based upon OS.

I have already tried cycling through the available values, to no noticeable effect.

I’ll revisit this in reply to your next message…

Good catch! I’d missed that.

From my CI2.0.2 config:

| 'AUTO'			Default - auto detects
| 'PATH_INFO'		Uses the PATH_INFO
| 'QUERY_STRING'	Uses the QUERY_STRING
| 'REQUEST_URI'		Uses the REQUEST_URI
| 'ORIG_PATH_INFO'	Uses the ORIG_PATH_INFO

I went through all of the migration notes from v2.0.2 (the one I use now) and v3.1.11 (latest version I am attempting to upgrade to) and don’t recall seeing that mentioned. I’ll have to review them.

EDIT: While reviewing the URI handler, the AUTO value is still in there, but the case resolves to the REQUEST_URI default

I use the newer CI v3.1.11 on a few sites at work, but they are a WIMP stack and I don’t believe I’ve ever bothered with removing the index.php file from the URIs there.

At this point, what I plan to do is build a new testing subdomain with PHP 7.4 and slap in a default install of CodeIgniter and try to get it running. Then, if successful, I’ll add in parts of my current site until it breaks.

It seems like the CodeIgniter sample .htaccess assumes that PHP is running as an Apache module, whereas DreamHost runs PHP via CGI/FastCGI/PHP-FPM. The different setups treat PATH_INFO differently, so rewriting to index.php/$1 doesn’t work (unless you adjust PHP’s INI setup).

However, with a fresh CodeIgniter download, I found that either of the following rewrite rules worked for accessing the welcome controller (example.com/welcome). The first is the rule that WordPress recommends:

...
RewriteRule ^(.*)$ index.php [L]
...
RewriteRule ^(.*)$ index.php?/$1 [L]
1 Like

I’m reviving the thread again, as I am now forced to get things running after the PHP migration.

I did a bit of a delve into my site and I discovered that the $_SERVER array isn’t giving me what I thought it was.

I just did some quick testing and found something really odd:

When I log the $_SERVER superglobal when I call the site without a controller/method pair and correctly routes to the default controller, i.e. http://domainname.com, I am seeing

[PATH_INFO] => /site/info
[SCRIPT_NAME] => /index.php
[REQUEST_URI] => /index.php/site/info
[QUERY_STRING] => 

which is the useable value codeigniter is looking for, the REQUEST_URI.

If I log the $_SERVER superglobal when my pages fail the redirect to the default, i.e. http://domainname.com/index.php/site/info, I see this

[SCRIPT_NAME] => /index.php
[REQUEST_URI] => /
[QUERY_STRING] => 

[PATH_INFO] isn’t even set.

Being set to read the REQUEST_URI means codeigniter is getting lost.

That strikes me as weird.

Progress has been made… at least marginally.

My problems accessing the main site/method code are actually a file name-casing issue, since Windows isn’t a case-sensitive file system.

I’ll see how things prograss.