CodeIgniter Forums

Full Version: CodeIgniter not running on localhost after installing in htdocs of xampp
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
CodeIgniter Newbie here!
I have CodeIgniter installed in htdocs of xampp but when I try to run localhost/CodeIgniter, I dont get the welcome page. Rather, I get a directory listing of CodeIgniter. I am unable to post an image here but when I run localhost/CodeIgniter after running the XAMPP server, I get the following (accompanied by info on size and modification):

Index of CodeIgniter
Parent Directory
License
composer.json
env
phpunit.xml.dist
public/
spark
There's a couple of ways you could tackle this. I think the easiest one would be to edit your apache main .conf file. (Usually, this file is located on C:/xampp/apache/conf/httpd.conf if i'm not mistaken). Once you're there, put something like this at the end of the file:

Code:
    Alias /codeigniter/ "C:/xampp/htdocs/Codeigniter/public"

    <Directory "C:/xampp/htdocs/Codeigniter/public">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory> 

Note that the 'public' part is important, since Codeigniter 4 was build to run from the public folder inside the project. After you've saved changes restart your XAMPP/Apache

Now we need to go inside your project folder and edit the public/.htaccess file. Find the 'RewriteBase' line, remove the comment deleting the `#` and insert /Codeigniter after RewriteBase so it looks like `RewriteBase /Codeigniter

Now you should be able to access your project on localhost/Codeigniter.

Also, don't forget to properly edit your BaseURL on the .env file accordingly.

Also, be careful with upper case letters on your project folder's name when using this approach. Even tho Windows is not case sensitive, i think this could still cause some issues
This type of "error" happens when the apache server does not detect the index.xxx file, in Codeigniter 4 this file, index.php,  is located in the public folder.
In my opinion the best way to install and use CI4 is through Apache's "virtual servers", vhosts. It doesn't require a high level of knowledge, actually just configuring the httpd-vhosts.conf file located in apache\conf\extra.
Below is a basic example of configuration:

# Virtual Hosts
#
# Required modules: mod_log_config
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/ci4/public"
    ServerName localhost
    ErrorLog "logs/wdsite-error.log"
</VirtualHost>

Commented lines are preceded by #. In this example the installation is in C:/xampp/htdocs/ci4/public, noting that I am referring to the Windows environment.
If you downloaded CI4 first you must create the folder where the files will be unzipped: xampp\htdocs\ci4, in this case the ci4 folder must be created, unzip it in this path. To use composer open a command prompt and in C:\xampp/htdocs or on the disk where xampp is installed enter with the following command:
composer create-project codeigniter4/appstarter ci4

where "ci4" will be the folder where the files will be installed, you can choose whatever name you like.

These steps are part of the initial chapter of the CodeIgniter manual, which I strongly suggest you refer to.
https://codeigniter.com/user_guide/index.html