1
votes

Updated, I'm having some issues with deploying codeigniter project on Ubuntu server, i get 404 Apache error when i click on links.

When i put the project in http://roy.my-domain.com/ = /var/www/html/ folder - it's all works fine - but when i added sub directory http://roy.my-domain.com/roy/ = /var/www/html/roy/ - i get 404 errors .

When my url is http://roy.my-domain.com/roy/index.php/about - i get codeigniter 404 error and not apache2.

The 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

Here are my settings :

0 . Checked for rewrite mod in Apache - got "Module rewrite already enabled"

1 . My project is in /var/www/my-project/

2 . In contains the following : application system public_html index.php .htaccess

  1. The .htaccess file :

    < IfModule mod_rewrite.c > RewriteEngine On RewriteBase /html/my-project/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d

    # Rewrite all other URLs to index.php/URL RewriteRule ^(.*)$ index.php?url=$1 [PT,L]

    < /IfModule > < IfModule !mod_rewrite.c> ErrorDocument 404 index.php < /IfModule >

  2. The apache2.conf :

    < Directory /var/www/ > Options Indexes FollowSymLinks Require all granted < /Directory >

    < Directory /var/www/html/ > Options Indexes FollowSymLinks AllowOverride All Require all granted < /Directory >

  3. The config.php :

    $config['base_url'] = 'http://roy.my-domain/my-project/'; $config['index_page'] = ''; $config['uri_protocol'] = 'AUTO';

  4. The index.php :

    (don't work with ../system and ../application) $system_path = 'system'; $application_folder = 'application';

  5. The controllers :

    (codeigniter default view) Welcome.php About_Controller.php

  6. The views: (codeigniter default view) welcome_message.php about.php

Locally - all works fine...Thanks

3
Could you provide Apache error log?Viktor
Hi -Thanks - there is no error from Apache server - i can't view any pages other then main page - when click on links - i get 'page cannot be displayed' errorRoyBarOn
Viktor - i've set $config['index_page'] = ''; and now i get an error - i update my post with the error contentRoyBarOn
So, now must be some errors in Apache error log.Viktor

3 Answers

3
votes
<Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
 </Directory>   

.htaccess:

    RewriteEngine On
    RewriteBase /html/project/

    RewriteCond %{THE_REQUEST} \s/+(.*?)/{2,}([^\s]*)
    RewriteRule ^ %1/%2 [R=302,L,NE]

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)/{2,}[?\s] [NC]
    RewriteRule ^ /%1/ [L,R=301]

    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI}  [R=301,L]

    RewriteCond %{REQUEST_URI} system|application
    RewriteRule ^(.*)$ index.php?/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]

Try this configuration and don't forget to reload Apache.

3
votes

This error can be triggered by the following:

  • server misconfiguration (httpd.conf)

  • .htaccess issues

  • mod_security or similar

    1. Upload your project in "var/www/my_project".

    2. In config file:
      $config['base_url'] = '';
      $config['index_page'] = '';

    3. Add this code into your .htaccess file to remove index.php and put this .htaccess file in main folder.

       <IfModule mod_rewrite.c>
         RewriteEngine On
      
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
      
        # Rewrite all other URLs to index.php/URL
        RewriteRule ^(.*)$ index.php?url=$1 [PT,L] 
      
         </IfModule>
         <IfModule !mod_rewrite.c>
              ErrorDocument 404 index.php
         </IfModule>
      

And Set AllowOverride to All in your httpd.conf

set the correct permission on the /cache folder, rather than just making the folder writable you need to make it reclusively writable.

I hope it will work for you.

2
votes

A simple step for setup CodeIgniter.

  1. Download and extract your CodeIgniter public_html or var/www/project where your domain point.
  2. Open your project as URL : https://example.com/project . If you get welcome CodeIgniter message then you have to install CodeIgniter successfully.

  3. Make sure, mod_rewrite enabled on your server.

  4. In database.php > pass your credential
  5. write code in .htaccess to remove index.php from url:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

I think it will be the complete process for setup the project.Make sure mod_rewrite enable on server. Thanks