我刚刚创建了一个 codeigniter4 项目,我想将它上传到共享主机上。但是我的网站无法访问,它给出了服务器错误。
1 回答
出于安全原因,codeigniter4 文件夹被制作成这样一种方式,即所有库和代码文件夹都在公用文件夹之外。通过 url 只能访问公用文件夹。要将其托管在共享托管上,您的目录结构应如下所示。
--home/root (sharehosting root directory)
|__ public_html (or your domain root folder)
| |__assets
| |__ index.php
| |__ .htaccess
|
|__ codeigniter (create a folder with any name you like)
|__ app(all the files and folder in app folder)
|__ system
|__ writable
|__ .env (dot env file here)
现在您需要更改一些值以启动并运行您的 codeigniter4 项目
在
public_html
文件夹index.php
文件中更改$pathsPath = FCPATH . '../app/Config/Paths.php';
为$pathsPath = FCPATH . '../codeigniter/app/Config/Paths.php';
在
app/Config
文件夹App.php
文件中更改$baseURL = 'http://192.168.0.111/';
为$baseURL = 'http://yourdomain.com/';
.
在此更改之后,您的站点将启动并运行。要在子域中部署,并且如果您的子域根文件夹位于 public_html 中,那么您应该更改$pathsPath = FCPATH . '../app/Config/Paths.php';
为$pathsPath = FCPATH . '../../codeigniter/app/Config/Paths.php';
在public_html/yourdomain
文件夹index.php
文件中,然后该目录结构保持不变。重要提示:公用文件夹内容应放在您的子域文件夹中。