How to run codeigniter4 in shared hosting ? |
Hello,
I am learning framework from the beginning and I would like to use Codeigniter for my projects. As I am working with a shared hosting I would like to know how to install Codeigniter4 in shared hosting properly. I have read the user guide and also search through the forum but there is no good solution. Some people saying to move the public folder contents to the root directory and some suggestions to create an index.php file in the root and point it to the public/index.php folder. But there is no proper guideline. Can anyone give me a proper guideline to how I can run my application in the shared hosting? I saw the Codeigniter3 user guide, and it was super easy for the beginner. There should be some proper guideline for the beginner. Can anyone help?
well not only do i have shared hosting but i also am using domains via "add on domains" and " sub domains" as part of my hosting.
I have a web up using CI4 but won't paste the url since i had a previous post deleted ,which i assumed was due to some sort of ban on promoting webs. Anyway there was not that much to do really. In my control panel for hosting there is an option to set the "document root ". When i look at my hosting and directories, generally the document root is the same as the directory name. But with CI4 because the bootstrap index.php is inside the "public" directory of your app; you need to set the document root of your domain to domain/public For App.php located at app/Config/App.php you need to set the base url (line 24 of APP.php) to your domain. eg on my local host is was : public $baseURL = 'http://127.0.0.2'; so i changed it to: public $baseUrl= 'http://myDomainName.com'; Then the next issue is moving from http to https For that i changed : public $baseUrl= 'http://myDomainName.com'; to : $baseUrl= 'https://myDomainName.com'; then in the .htaccess file located in public directory I changed : RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L] to: RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L] Now on my hosting they have a "Lets Encrypt" facility So i basically set up SSL using lets Encrypt and found every thing worked.When i looked at the .htaccess file i noted "lets Encrypt" had done some over writing . BAsically to go from localhost to live thats all i did
(03-24-2020, 10:53 AM)Ithinkscaptain-sensible Wrote: well not only do i have shared hosting but i also am using domains via "add on domains" and " sub domains" as part of my hosting. But I think this is not the solution. What if I want to do it in my main domain? Every hosting provider does not provides SSH access.
But I think this is not the solution. What if I want to do it in my main domain? Every hosting provider does not provides SSH access.
if its your main domain no problem , but you still going to have to set document root to public . When say you are developing in a directory called 'mydev' make sure you go inside that directory ,zip every thing and load that up to your hosting space . I am not actually talking about getting access to server via SSH what i mean is set up a certificate so as to enable https in url rather than http. You can of course still use http but google is penalizing those webs that do not have https. https of course is encrypted in summary i have found there is no big deal with going from local development to live
Hey
there is nothing or not much in here because CI has nothing to do with server administration. I strongly recommend to search the web for (what you probably mean and want to do) virtual hosting. There are plenty of good sources out there, even a few almost ready to go configuration examples you can modify for your needs. I'd strongly recommend to NOT TO put your public folder into the root folder of the application. So far I can judge it are your abilities to deal with access rights and the like not sufficient to deal with such a delicate task. Here I put you my localhost configuration which is easy to transfer onto a distant server. The naming can be different depending on what kind of OS you are using. httpd.conf Code: # The CI vhost file: Code: # Don't forget to modify your /etc/hosts file: Code: # Hope it helps and I understood your question right.
This thread may be useful especially how to reset your own application and system paths instead using default paths:
https://forum.codeigniter.com/thread-75640.html
Before this thread get's out of hand (with providing incorrect answers), what software does your hosting provider use for your shared hosting. Cpanel? Not pointing finger here, but some posts in this thread does not help @shahadathossain at all.
The content of /public should be in your shared hosting providers /public_html or sometimes named /public. Normally this are the directory your FTP-client automatically enters. This are the folder generally refereed to as document root / root directory. Every folder and files not being inside /public should be placed one directory up. Normally you can press .. (folder named ..) in your FTP-client and in that folder you should place everything else (app, system, tests, writable etc). CodeIgniter 4 have just been released, therefor there are no tutorial for everything. And shared hosting all differ so we can't give explanations on all hosting providers. With CI4 vs CI3 we have taken security one step further, as in CI3 index.php where alongside your application and system, meaning you could drop all those files directly when connecting with your FTP-client. But that's not the case anymore, as it's not a good practice considering the security issues that can occur.
(03-25-2020, 12:00 PM)jreklund Wrote: Before this thread get's out of hand (with providing incorrect answers), what software does your hosting provider use for your shared hosting. Cpanel? Not pointing finger here, but some posts in this thread does not help @shahadathossain at all.if i have done anything to mislead @shahadathossain or if i have not understood his issue i have no problem in being told in what way. Where i am coming from is from a point of using shared hosting and successfully having codeigniter 4.0.0-rc3 work on live hosting with https . Thus my contribution is from a standpoint of getting it working live
(03-25-2020, 12:00 PM)jreklund Wrote: Before this thread get's out of hand (with providing incorrect answers), what software does your hosting provider use for your shared hosting. Cpanel? Not pointing finger here, but some posts in this thread does not help @shahadathossain at all. Yes, my hosting provider is using Cpanel. I understand the security concern here. But the thing is, its actually a bit complex for a beginner to start with Codeigniter4 deployment to the live server where Codeigniter3 was super easy. So, now do I have to put the "public" folder contents to the "public_html" folder and keep other files/folders outside the public_html folder. Is that correct?
That's correct. If you upload everything as is (renaming /public into /public_html), you will end up with the following structure in Cpanel, based upon /.
/public_html are always your main domains document root, and that can't be changed. Only subdomain and addon domains have that ability (through Cpanel itself). Code: | .gitignore And that can also cause som clutter, if you want to have another website later on (subdomains / addon domains) with different Document root. And here you can actually create /subdomain.domain.com/public as the document root. And upload the CI folder into /subdomain.domain.com and it will work out of the box. My recommendation are always placing codeigniter4 files inside another folder, so that you don't clutter /, the folder name codeigniter4 can be whatever you want. May be the domain name. Code: +---codeigniter4 But for this trick to work, you need to open your /public_html/index.php and change into the following: PHP Code: $pathsPath = FCPATH . '../codeigniter4/app/Config/Paths.php'; |
Welcome Guest, Not a member yet? Register Sign In |