如何在共享主机上托管 codeigniter 4 网站?
How to host codeigniter4 website on sharehosting?
我刚刚创建了一个 codeigniter4 项目,我想将它上传到共享主机上。但是我的网站无法访问,服务器报错。
出于安全原因,codeigniter4 文件夹采用了一种方式,即所有库和代码文件夹都位于 public 文件夹之外。通过 url 只能访问 public 文件夹。
要将其托管在托管您的目录结构的共享上,应该如下所示。
--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,那么您应该在 public_html/yourdomain
文件夹 index.php
文件中将 $pathsPath = FCPATH . '../app/Config/Paths.php';
更改为 $pathsPath = FCPATH . '../../codeigniter/app/Config/Paths.php';
,遵循该目录结构保持不变。 重要:public文件夹内容应放在您的子域文件夹中。
我刚刚创建了一个 codeigniter4 项目,我想将它上传到共享主机上。但是我的网站无法访问,服务器报错。
出于安全原因,codeigniter4 文件夹采用了一种方式,即所有库和代码文件夹都位于 public 文件夹之外。通过 url 只能访问 public 文件夹。 要将其托管在托管您的目录结构的共享上,应该如下所示。
--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,那么您应该在 public_html/yourdomain
文件夹 index.php
文件中将 $pathsPath = FCPATH . '../app/Config/Paths.php';
更改为 $pathsPath = FCPATH . '../../codeigniter/app/Config/Paths.php';
,遵循该目录结构保持不变。 重要:public文件夹内容应放在您的子域文件夹中。