codeigniterdeploymentcpanelshared-hostingcodeigniter-4

Uploading CodeIgniter4 to Shared Hosting via cPanel


I used Composer to setup CodeIgniter4 in my local PC. And I have completed the development also.

The problem is, am trying to deploy this application to a Shared Hosting that has cPanel.

I have zipped the contents (except the spark and build files) to the /public_html/ folder in my Shared Hosting. Because the primary domain points to this /public_html/ and I can't change it.

The problem now am facing is, if I access www.mysite.com/public, it loads the site. But won't load if I access just the domain name www.mysite.com

My directory/file structure is as follows (in the server):

enter image description here

So I basically want the site to be served when I access just the domain. My second question is, from the screenshot I shared, is there any files or folders that is not required to be in the production server?


EDIT:

This is the .htaccess file in /public_html/ that I tried:

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

Solution

  • Try adding this to your /public_html/.htaccess:

    DirectoryIndex /public/index.php  
    RewriteEngine On
    RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico) 
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
    RewriteRule ^(.*)$ public/$1 [L]