2
votes

It's my first time i'm uploading codeigniter project to production and i'm getting error 404 from Apache server.

error : Not Found The requested URL /index.php was not found on this server. Apache/2.4.18 (Ubuntu) Server at roy.my-domain.com Port 80

I've read every article for 2 days and didn't found a solution....

So here are my settings :

Checked for rewrite mod in Apache - got "Module rewrite already enabled" My project is in /var/www/roy/ so the url is roy.my-domain.com/roy

  1. Apache2.conf

    <Directory /var/www/html/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
    </Directory>
    AccessFileName .htaccess
    
  2. .htaccess

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /roy/
    RewriteRule ^([a-z0-9_-]+)\.html$ index.php/page/$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(index\.php|asset|robots\.txt)
    RewriteRule ^(.*)$ index.php/$1 [L]
    </IfModule>
    
  3. config.php

    $config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/roy/';
    $config['index_page'] = '';
    
  4. autoload.php (i'm using Twig)

    $autoload['libraries'] = array('database','session','twig');
    
    • I added permissions to both logs and cache dir
  5. The controllers structure

    name Login.php - 
    class Login extends CI_Controller
    
2
Did you have the same path structure on your development server? Just to clarify, is roy.my-domain.com/roy the publicly accessible URL?MrWhite
w3dk - Yes - i did have the same path - the project is working well on developmentRoyBarOn

2 Answers

3
votes

Create a site folder inside your html one. Then, put your roy site there. Then, I would do it this way:

1 - apache2/sites-enabled/roy.my-domain.com.conf

<VirtualHost roy.my-domain.com:80>
    DocumentRoot /var/www/html/site
    ServerName roy.my-domain.com
    <Directory /var/www/html/site>
        Options FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

2 - .htaccess

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

3 - If it's not development, it's never a good practice to use the $_SERVER['HTTP_HOST'] superglobal. Can be changed from the client side. Just use the right url.

After you're done all that, restart apache. In Ubuntu is: $ sudo service apache2 restart

0
votes

I assume your .htaccess file is in the /roy subdirectory?

Since you are making use of path information (ie. /index.php/<path-info> on the URL to route the request, it's possible that AcceptPathInfo is disabled on the server. If it's disabled then such a request would result in a 404.

So, try enabling this at the top of your .htaccess file:

AcceptPathInfo On