Pages

Search This Blog

Wednesday, January 1, 2020

Codeigniter mode rewrite not working in AWS EC2 Ubuntu

The server is newly deployed in AWS EC2 running Ubuntu 16.04, Apache/2.4.18 web server with PHP 7.0.33

After uploading the new Codeigniter files into the server, the route is not working. In my case, i am uploading the files to /var/www/html/myfiles and i access through IP address for example:
http://xxx.xxx.xxx.xxx/myfiles

The files in running well in my local.

There are a few steps that need to perform in order to get it working

Step 1 — Enabling mod_rewrite
We need to activate mod_rewrite. It’s already installed, but it’s disabled on a default Apache installation. Use the a2enmod command to enable the module:

sudo a2enmod rewrite

This will activate the module or alert you that the module is already enabled. To put these changes into effect, we need to restart Apache.

sudo systemctl restart apache2


Step 2 — Enable AllowOverrideAll in default.conf

sudo nano /etc/apache2/sites-available/000-default.conf

Inside that file, you will find a <VirtualHost *:80> block starting on the first line. Inside of that block, add the following new block so your configuration file looks like the following. Make sure that all blocks are properly indented.

/etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>
    <Directory /var/www/html>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>

    . . .
</VirtualHost>

Save and close the file. To put these changes into effect, we need to restart Apache.

sudo systemctl restart apache2

Now, we need to create an .htaccess file in the web root.

sudo nano /var/www/html/.htaccess

Add this line at the top of the new file to activate the rewrite engine.

/var/www/html/.htaccess

RewriteEngine on

Save the file and exit.

Now, it working well when I access to http://xxx.xxx.xxx.xxx/myfiles



No comments: