Codeigniter and Virtualmin / Webmin Error 500

SYSTEM INFORMATION
OS type and version: Ubuntu Linux 20.04.3
Webmin version: 1.981
Virtualmin version: 6.17-3
Related products version: CodeIgniter 4 (composer installation) / Apache 2

I have been looking to find a solution to this issue. It seems that for some reason I am getting a error 500 regardless what I do when I am installing CodeIgniter (php framework).

It is a fresh virtual host, the only thing that is installed on it are required packages from CodeIgniter.

Laravel works just fine out of the box, CodeIgniter however does not, anyone else experienced this?

Anything specific in the error log?

1 Like

well yes and no.
according to codeigniter this is the .htaccess file that it is shipping with, but this triggeres following issues.

https://github.com/codeigniter4/CodeIgniter4/blob/develop/public/.htaccess

I know for a fact that Options -Indexes is something that Apache2 is not a a valid config setting and will not allow apache to start propedly, i have tried this last night.

/public/.htaccess: Option All not allowed here
AH00670: Options FollowSymLinks and SymLinksIfOwnerMatch are both off, so the RewriteRule directive is also forbidden due to its similar ability to circumvent directory restrictions 

I had issues with custom coded routers such as alto router but that got fixed and never saw an issue again. I simply cannot twist my head around this one. :confused:

Have you tried changing

Options +FollowSymlinks

to

Options +SymLinksIfOwnerMatch?

yes, the welcome splash page shows up since its a static page (as it is when ci4 is installed with composer)

however once few lines of code is written i get an error saying:

AH00670: Options FollowSymLinks and SymLinksIfOwnerMatch are both off, so the RewriteRule directive is also forbidden due to its similar ability to circumvent directory restrictions

What happens if you comment out:

Options All -Indexes

and

Options +FollowSymlinks

then apache will not start

Are there any errors in the Apache log file?

e.g. tail -n 20 /var/log/apache2/error.log

No, there are no logs of apache failing to start.

However.
I saw a misconfiguration of Directory Root, this might be when I removed

Options All -Indexes & Options All -Indexes

first time, and apache refused to start. Since Options and rewrite rules are in that area.

"mpm_event:notice" for pid whatever... bla bla bal doing gracefull restart normal behaviour.

I´ve had issues with Alto Router (a php router to rewrite url´s) but have fixed it with apache directory config this time i have not been lucky.

Apologies for the delay in replying.

In these cases, I often try and start from scratch, as changing Apache rules can often lead to untraceable changes that stop it from working.

To help you further I had a stab at this myself.

In Virtualmin, I created a new virtual server, downloaded the latest version of CI4 (4.1.5) and extracted it to the public_html folder.

I then clicked on ‘Website Options’ and changed the ‘Website documents sub-directory’ to:

public_html/CodeIgniter4-4.1.5/public

This changes the Directory tag in Apache to:

<Directory /home/ci4/public_html/CodeIgniter4-4.1.5/public>

This makes sure that Apache uses the index.php as the front router file in the public folder.

You then need to comment out the following, in the public_html/CodeIgniter4-4.1.5/public/.htaccess file:

Line 2: #Options All -Indexes (this is already set in the Apache config for the Virtual Server)

and change Options FollowSymLinks to

Line 11: Options +SymLinksIfOwnerMatch (which provides symlink protection)

By default you’ll get a 301 redirect to https…and (hopefully):

Hi Paul
thanks for your effort and sorry for now my late reply.

I will take a look at it, it has been a hectic December here with this COVID so have not been able to test further…

I have a CI4 as far as you have so, as it is now looks fine. next part will be when CI4 needs to do some routing… (if someone should use CI4 as a frontend) for me CI4 will be used as a API

Here is the full solution:

PHP config: FCGId
PHP version: 8.0.15

Tested on: Codeigniter: 4.0.15, 4.0.18

as @pixel_paul sugested everything can be done in .htaccess file. here is the complete and slightly modified .htaccess file:

# Disable directory browsing
# Options All -Indexes

# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------

# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymLinks must be enabled for this to work.
<IfModule mod_rewrite.c>

	Options +SymLinksIfOwnerMatch
	RewriteEngine On

	# If you installed CodeIgniter in a subfolder, you will need to
	# change the following line to match the subfolder you need.
	# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
	#RewriteBase "/"
	
	# Redirect Trailing Slashes...
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteRule ^(.*)/$ /$1 [L,R=301]

	# Rewrite "www.example.com -> example.com"
	RewriteCond %{HTTPS} !=on
	RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
	RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

	# Checks to see if the user is attempting to access a valid file,
    # such as an image or css document, if this isn't true it sends the
    # request to the front controller, index.php
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d

#RewriteRule ^([\s\S]*)$ index.php/$1 [L,NC,QSA] (orginal line)
	RewriteRule ^([\s\S]*)$ index.php?/$1 [L,NC,QSA]

	# Ensure Authorization header is passed along
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    ErrorDocument 404 index.php
</IfModule>

# Disable server signature start
    ServerSignature Off
# Disable server signature end

you need the index part aswell so you get the sessions transfered aswell ;). thanks for your help @pixel_paul

Best Regards
Hamzalija Meco

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.