如何在 Rocky Linux 9 上安装 CodeIgniter

Linux命令 Edge插件网 1年前 (2023-08-10) 358次浏览 已收录 0个评论

CodeIgniter,一个强大的PHP框架,为开发人员提供了一个强大的平台,用于构建动态和功能丰富的Web应用程序。当与领先的企业级操作系统 Rocky Linux 9 的稳定性和安全性结合使用时,您可以创建尖端的 Web 项目。

如何在 Rocky Linux 9 上安装 CodeIgniter

在 Rocky Linux 9 上安装 CodeIgniter

第 1 步。第一步是将系统更新到最新版本的软件包列表。为此,请运行以下命令:

<span class="pln">sudo dnf update</span>

第 2 步。安装灯组

LAMP堆栈(Linux,Apache,MySQL,PHP)构成了许多Web应用程序的骨干。您可以在此处遵循我们的指南。

第 3 步。为 CodeIgniter 配置 Apache 。

为 CodeIgniter 设置虚拟主机可确保干净的 URL 结构并增强应用程序的性能:

<span class="pln">cd </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">httpd</span><span class="pun">/</span><span class="pln">conf</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">
sudo nano codeigniter</span><span class="pun">.</span><span class="pln">conf</span>

添加以下配置:

<span class="tag"><VirtualHost</span><span class="pln"> *:80</span><span class="tag">></span><span class="pln">
ServerAdmin webmaster@example.com
DocumentRoot /var/www/html/codeigniter
ServerName your_domain.com

</span><span class="tag"><Directory</span> <span class="pun">/</span><span class="atn">var</span><span class="pun">/</span><span class="atn">www</span><span class="pun">/</span><span class="atn">html</span><span class="pun">/</span><span class="atn">codeigniter</span><span class="tag">></span><span class="pln">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</span><span class="tag"></Directory></span><span class="pln">

ErrorLog /var/log/httpd/codeigniter_error.log
CustomLog /var/log/httpd/codeigniter_access.log combined
</span><span class="tag"></VirtualHost></span>

启用虚拟主机并重新启动 Apache :

<span class="pln">sudo a2ensite codeigniter</span><span class="pun">.</span><span class="pln">conf
sudo systemctl restart httpd</span>

第 4 步。下载并安装 CodeIgniter

现在访问CodeIgniter官方网站下载最新版本。或者,使用 或 直接下载包:wgetcurl

<span class="pln">cd </span><span class="pun">/</span><span class="pln">tmp
wget https</span><span class="pun">:</span><span class="com">//codeload.github.com/codeigniter4/framework/legacy.zip/refs/tags/v4.3.6</span>

提取下载的存档并将文件移动到 Web 服务器的根目录:

<span class="pln">unzip codeigniter4</span><span class="pun">-</span><span class="pln">framework</span><span class="pun">-</span><span class="pln">v4</span><span class="pun">.</span><span class="lit">3.6</span><span class="pun">-</span><span class="lit">0</span><span class="pun">-</span><span class="pln">ge392123</span><span class="pun">.</span><span class="pln">zip
sudo mv ccodeigniter4</span><span class="pun">-</span><span class="pln">framework</span><span class="pun">-</span><span class="pln">v4</span><span class="pun">.</span><span class="lit">3.6</span><span class="pun">-</span><span class="lit">0</span><span class="pun">-</span><span class="pln">ge392123 </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">html</span><span class="pun">/</span><span class="pln">codeigniter</span>

确保 CodeIgniter 文件和目录的权限和所有权正确:

<span class="pln">sudo chown </span><span class="pun">-</span><span class="pln">R apache</span><span class="pun">:</span><span class="pln">apache </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">html</span><span class="pun">/</span><span class="pln">codeigniter
sudo chmod </span><span class="pun">-</span><span class="pln">R </span><span class="lit">755</span> <span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">html</span><span class="pun">/</span><span class="pln">codeigniter</span>

第5步。验证安装

让我们验证一下 CodeIgniter 在 Rocky Linux 9 上的成功安装:

<span class="pln">cd </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">html</span><span class="pun">/</span><span class="pln">codeigniter</span><span class="pun">/</span><span class="pln">application</span><span class="pun">/</span><span class="pln">controllers
sudo nano </span><span class="typ">Welcome</span><span class="pun">.</span><span class="pln">php</span>

将以下代码添加到文件中:

<span class="pun"><?</span><span class="pln">php
</span><span class="kwd">defined</span><span class="pun">(</span><span class="str">'BASEPATH'</span><span class="pun">)</span><span class="pln"> OR </span><span class="kwd">exit</span><span class="pun">(</span><span class="str">'No direct script access allowed'</span><span class="pun">);</span>

<span class="kwd">class</span> <span class="typ">Welcome</span> <span class="kwd">extends</span><span class="pln"> CI_Controller </span><span class="pun">{</span>
<span class="kwd">public</span> <span class="kwd">function</span><span class="pln"> index</span><span class="pun">()</span> <span class="pun">{</span><span class="pln">
$this</span><span class="pun">-></span><span class="pln">load</span><span class="pun">-></span><span class="pln">view</span><span class="pun">(</span><span class="str">'welcome_message'</span><span class="pun">);</span>
<span class="pun">}</span>
<span class="pun">}</span>

创建示例视图:

<span class="pln">cd </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">html</span><span class="pun">/</span><span class="pln">codeigniter</span><span class="pun">/</span><span class="pln">application</span><span class="pun">/</span><span class="pln">views
sudo nano welcome_message</span><span class="pun">.</span><span class="pln">php</span>

将以下 HTML 添加到文件中:

<span class="dec"><!DOCTYPE html></span>
<span class="tag"><html></span>
<span class="tag"><head></span>
<span class="tag"><title></span><span class="pln">Welcome to CodeIgniter Idroot.Us</span><span class="tag"></title></span>
<span class="tag"></head></span>
<span class="tag"><body></span>
<span class="tag"><h1></span><span class="pln">Hello, CodeIgniter!</span><span class="tag"></h1></span>
<span class="tag"></body></span>
<span class="tag"></html></span>

保存文件,然后打开 Web 浏览器并在地址栏中输入服务器的 IP 地址或域名。您应该会看到欢迎消息,确认 CodeIgniter 已成功安装。

感谢您使用本教程在 Rocky Linux 9 系统上安装 CodeIgniter PHP 框架。有关其他帮助或有用信息,我们建议您查看 CodeIgniter 官方网站


Edge插件网 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:如何在 Rocky Linux 9 上安装 CodeIgniter
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址