404 Page Not Found when run Codeigniter project inside var/www/html/ on Ubuntu 16.04 LTS?
For your question in setting up the apache
virtual host configuration: Here's how it goes. If you have [root] privilege, Open your [Terminal] and go to this directory: /etc/apache2/sites-available
Then create a new virtual host configuration, For now, we will name this configuration the name of your project.
sudo vim mahasiswa.conf
or sudo nano mahasiswa.conf
<VirtualHost *:80> ServerName local.mahasiswa.com DocumentRoot /var/www/html/mahasiswa <Directory /var/www/html/mahasiswa/> AllowOverride All Require all granted Allow from all </Directory></VirtualHost>
1) ServerName: serves as the the DNS (Think of it as another server name aside from http://localhost or http://127.0.0.1)
2) DocumentRoot: from the word itself, is your [project]'s directory (e.g /var/www/html/mahasiswa)
3) Directory: are used to enclose a group of directives that will apply only to the named directory, sub-directories of that directory, and the files within the respective directories. In this case, we wanted to place control access rights to a directory:
AllowOverride All (This can be either All or None)
Require all granted
Allow from all
You can learn more of this here: http://httpd.apache.org/docs/current/mod/core.html#directory
Going back, Once you've saved this new configuration, Go to your /etc/hosts
(hosts file) (e.g sudo vim /etc/hosts
) and add the ff:
127.0.0.1 localhost local.mahasiswa.com
Once you've saved these changes on your [hosts] file, Execute this command:
sudo a2ensite mahasiswa.conf
sudo a2enmod rewrite
This will now [enable] your new site configuration and enable the [url rewrite] module as well. Then execute this afterwards:
sudo service apache2 reload
From the command itself, it means you need to reload [apache2] thus the configuration takes affect afterwards.
Then try to access your new domain name: local.mahasiswa.com.You should be able to see your CI
pages you've needed.
For further reference, check [Digital Ocean] guide here: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-16-04
Hope this helps for your case.
Edit: In naming the [controller] file(s) (e.g mahasiswa), You might need to set [UpperCase] instead of [lowercase] format to (e.g Mahasiswa)
Enable mod_rewrite
sudo a2enmod rewritesudo systemctl restart apache2