php – Apache configure ServerPath for CodeIgniter-ThrowExceptions

Exception or error:

I’m very new to Apache and CodeIgniter. Trying to route /var/www/html to http://localhost/ and /var/www/CodeIgniter to http://localhost/codeigniter

Apache conf:

<VirtualHost *:80>
    ServerName localhost
    ServerPath /codeigniter
    DocumentRoot /var/www/CodeIgniter
    <Directory /var/www/CodeIgniter>
          Allowoverride All


$config['base_url'] = 'http://localhost/codeigniter';

http://localhost/codeigniter gives me codeigniter, but http://localhost/ also gives it to me when I expect /var/www/html

What should I change?

How to solve:

Nowhere do you configure your DocumentRoot in the snippet you give – thus we have no clue that you might be serving anything from /var/www/html.

I’d expect a directive DocumentRoot /var/www/html somewhere within your VirtualHost (I prefer such a directive in the VirtualHost, not in the global server configuration). From there on, let’s look at the Apache httpd documentation:

There are frequently circumstances where it is necessary to allow web
access to parts of the filesystem that are not strictly underneath the
DocumentRoot. httpd offers several different ways to accomplish this.
On Unix systems, symbolic links can bring other parts of the
filesystem under the DocumentRoot. For security reasons, httpd will
follow symbolic links only if the Options setting for the relevant
directory includes FollowSymLinks or SymLinksIfOwnerMatch.

Alternatively, the Alias directive will map any part of the filesystem
into the web space. For example, with

Alias "/docs" "/var/web"

the URL will be served from

i.e. I’d expect an Alias, to do the job.

Alias "/codeigniter" "/var/www/CodeIgniter"

All in all, closer to (this is not complete/tested):

<VirtualHost *:80>
  ServerName localhost
  DocumentRoot /var/www/html
  Alias "/codeigniter" "/var/www/CodeIgniter"

(add Options, Directory, other directives and permissions etc. to taste)

Leave a Reply

Your email address will not be published. Required fields are marked *