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):
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]
2
Answers
I suggest you do it like this:
Put the files from the "public" folder into the "public_html" folder on the server.
For the other CI directories and files, create and place in a folder called "ci", at the root of the server, do not put them in "public_html" to be safe and nobody can access.
Your index.php will be in "public_html", now you change the variable "$pathsConfig" to this path.
$pathsConfig = FCPATH . ‘../ci/app/Config/Paths.php’;
It should work…
Try adding this to your
/public_html/.htaccess
: