如何在 Fedora 38 上安装 CodeIgniter

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

CodeIgniter是一个健壮的PHP框架,因其简单性,效率和灵活性而在Web开发人员中获得了极大的欢迎。虽然存在自动安装方法,但本综合指南将引导您使用命令行界面 (CLI) 在 Fedora 38 上手动安装 CodeIgniter 的过程。

如何在 Fedora 38 上安装 CodeIgniter

在 Fedora 38 上安装 CodeIgniter

第 1 步。在我们可以在 Fedora 38安装 CodeIgniter 之前,确保我们的系统是最新的软件包是很重要的。这将确保我们可以访问最新功能和错误修复,并且我们可以毫无问题地安装 CodeIgniter

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

第 2 步。PHP 安装和配置。

CodeIgniter 通常需要 PHP 7 或更高版本。确保 PHP 已安装并正确配置在 Fedora 38 系统上。您可以通过运行以下命令来检查您的 PHP 版本:

<span class="pln">php </span><span class="pun">-</span><span class="pln">v</span>

如果未安装 PHP,则可以使用以下命令进行安装:

<span class="pln">sudo dnf install php php</span><span class="pun">-</span><span class="pln">cli php</span><span class="pun">-</span><span class="pln">zip</span>

第 3 步。作曲家安装。

Composer,PHP 包管理器,对于有效地管理 CodeIgniter 的依赖项至关重要。使用以下命令在系统上安装 Composer:

<span class="pln">php </span><span class="pun">-</span><span class="pln">r </span><span class="str">"copy('https://getcomposer.org/installer', 'composer-setup.php');"</span><span class="pln">
php composer</span><span class="pun">-</span><span class="pln">setup</span><span class="pun">.</span><span class="pln">php
php </span><span class="pun">-</span><span class="pln">r </span><span class="str">"unlink('composer-setup.php');"</span><span class="pln">
sudo mv composer</span><span class="pun">.</span><span class="pln">phar </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">composer</span>

第 4 步。在 Fedora 38安装 CodeIgniter

导航到所需的项目目录,并使用从官方 GitHub 存储库下载最新版本的 CodeIgniter。替换为最新版本号:wget[version]

<span class="pln">wget https</span><span class="pun">:</span><span class="com">//github.com/codeigniter4/CodeIgniter4/archive/refs/tags/v4.4.1.zip</span>

下载完成后,解压缩下载的 ZIP 文件:

<span class="pln">unzip v4</span><span class="pun">.</span><span class="lit">4.1</span><span class="pun">.</span><span class="pln">zip</span>

解压缩后,您将有一个名为 的目录,其中包含 CodeIgniter 文件。将这些文件移动到 Web 服务器的文档根目录或 Web 服务器可访问的目录:framework-4.x

<span class="pln">sudo mv framework</span><span class="pun">-</span><span class="lit">4.x</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">your_project_folder</span>

第5步。配置阿帕奇。

应安装并正确配置Web服务器,例如Apache或Nginx,以便为您的CodeIgniter应用程序提供服务。如果尚未安装,现在使用以下命令安装 Apache Web 服务器:

<span class="pln">sudo dnf install apache</span>

接下来,在目录中创建虚拟主机配置文件。替换为项目目录的实际路径:/etc/httpd/conf.d/[your_project_folder]

<span class="pln">sudo nano </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">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@yourdomain.com
DocumentRoot /var/www/html/codeigniter/public
ServerName yourdomain.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="pun">/</span><span class="atn">public</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>

通过将 Web 服务器配置为指向 CodeIgniter 的文件夹,您可以确保只有此目录中的文件才能通过 Web 浏览器访问,从而增强安全性。重新启动 Apache 以应用更改:public

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

第 6 步。数据库设置。

如果尚未安装,请安装数据库服务器,如MySQL,MariaDB或PostgreSQL。在本指南中,我们将使用 MySQL:

<span class="pln">sudo dnf install mysql</span><span class="pun">-</span><span class="pln">server</span>

启动 MySQL 服务并使用它来在启动时启动:

<span class="pln">sudo systemctl start mysqld
sudo systemctl enable mysqld</span>

以根用户身份访问 MySQL 命令行,并为您的 CodeIgniter 应用程序创建一个新数据库。替换为所需的数据库名称:[database_name]

<span class="pln">mysql </span><span class="pun">-</span><span class="pln">u root </span><span class="pun">-</span><span class="pln">p</span>
<span class="pln">CREATE DATABASE </span><span class="pun">[</span><span class="pln">database_name</span><span class="pun">];</span>

导航到 CodeIgniter 项目的根目录并编辑该文件以配置数据库连接。将 、 和替换为数据库凭据:.env[database_name][database_user][database_password]

<span class="pln">nano </span><span class="pun">.</span><span class="pln">env</span>

在文件中,根据您的 MySQL 凭据设置数据库配置:.env

<span class="pln">database</span><span class="pun">.</span><span class="kwd">default</span><span class="pun">.</span><span class="pln">hostname </span><span class="pun">=</span><span class="pln"> localhost
database</span><span class="pun">.</span><span class="kwd">default</span><span class="pun">.</span><span class="pln">database </span><span class="pun">=</span> <span class="pun">[</span><span class="pln">database_name</span><span class="pun">]</span><span class="pln">
database</span><span class="pun">.</span><span class="kwd">default</span><span class="pun">.</span><span class="pln">username </span><span class="pun">=</span> <span class="pun">[</span><span class="pln">database_user</span><span class="pun">]</span><span class="pln">
database</span><span class="pun">.</span><span class="kwd">default</span><span class="pun">.</span><span class="pln">password </span><span class="pun">=</span> <span class="pun">[</span><span class="pln">database_password</span><span class="pun">]</span>

步骤 7.作曲家依赖项。

使用终端导航到 CodeIgniter 项目目录,然后运行以下命令以安装 CodeIgniter 所需的依赖项:

<span class="pln">composer install</span>

Composer 将获取并安装您的 CodeIgniter 应用程序所需的所有软件包。

安装依赖项后,更新 Composer 自动加载文件以确保正确加载 CodeIgniter 的类:

<span class="pln">composer </span><span class="kwd">dump</span><span class="pun">-</span><span class="pln">autoload</span>

第8步。环境配置。

CodeIgniter 允许您在文件中配置特定于环境的变量。这对于管理开发、生产和测试环境的不同配置特别有用。.env

编辑文件以根据您的开发环境自定义配置设置:.env

<span class="pln">nano </span><span class="pun">.</span><span class="pln">env</span>

自定义环境变量以满足您的特定需求,例如数据库设置和应用程序环境:

<span class="com"># Development</span><span class="pln">
CI_ENVIRONMENT </span><span class="pun">=</span><span class="pln"> development
app</span><span class="pun">.</span><span class="pln">baseURL </span><span class="pun">=</span> <span class="str">'http://localhost/your_project_folder/public/'</span>

<span class="com"># Production</span>
<span class="com"># Uncomment and configure these lines for your production environment</span>
<span class="com"># CI_ENVIRONMENT = production</span>
<span class="com"># app.baseURL = 'https://your-domain.com/'</span>

第9步。安全增强功能。

出于安全原因,必须禁用目录列表。打开虚拟主机配置文件(例如,对于 Apache 的配置文件)并在块中添加以下行:codeigniter.conf<Directory>

<span class="typ">Options</span> <span class="pun">-</span><span class="typ">Indexes</span>

保存文件并重新启动 Apache:

<span class="pln">sudo systemctl restart httpd</span>

确保正确设置文件权限以限制对敏感文件的未授权访问。导航到项目的根目录并运行:

<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>

第9步。测试您的应用程序。

要验证 CodeIgniter 安装是否成功,请创建基本控制器和视图。使用终端生成一个名为“Welcome”的新控制器:

<span class="pln">php spark make</span><span class="pun">:</span><span class="pln">controller </span><span class="typ">Welcome</span>

此命令将创建一个在目录中命名的新控制器文件。向此控制器添加一个简单的方法:Welcome.phpapp/Controllers

<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">
echo </span><span class="str">"Welcome to CodeIgniter!"</span><span class="pun">;</span>
<span class="pun">}</span>

打开您的 Web 浏览器并通过输入 URL 访问您的 CodeIgniter 应用程序:

<span class="pln">http</span><span class="pun">:</span><span class="com">//localhost/your_project_folder/public/welcome</span>

您应该会在浏览器中看到消息“欢迎使用 CodeIgniter!”,确认安装成功。

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


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

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

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