如何在Manjaro上安装CodeIgniter

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

CodeIgniter 是一个功能强大的 PHP 框架,允许开发人员轻松构建动态 Web 应用程序。如果您是 Manjaro Linux 用户,那么您很幸运,因为在本综合指南中,我们将引导您使用命令行界面 (CLI) 在 Manjaro 系统上安装 CodeIgniter 的过程。

如何在Manjaro上安装CodeIgniter

在 Manjaro 上安装 CodeIgniter

第 1 步。在运行以下教程之前,请确保我们的系统是最新的:

<span class="pln">sudo pacman </span><span class="pun">-</span><span class="typ">Syu</span><span class="pln">
sudo pacman </span><span class="pun">-</span><span class="pln">S </span><span class="kwd">base</span><span class="pun">-</span><span class="pln">devel</span>

第 2 步。安装基本依赖项。

  • .PHP

要运行 CodeIgniter,您需要 PHP。安装 PHP 及其所需的扩展:

<span class="pln">sudo pacman </span><span class="pun">-</span><span class="pln">S php php</span><span class="pun">-</span><span class="pln">apache</span>

我们已经安装了 PHP,但让我们确认它已正确设置:

<span class="pln">php </span><span class="pun">-</span><span class="pln">v</span>
  • 作曲家

Composer 是管理 CodeIgniter 依赖项的重要工具。让我们全局安装它:

<span class="pln">sudo pacman </span><span class="pun">-</span><span class="pln">S composer</span>

编写器简化了依赖项管理。让我们全局安装它:

<span class="pln">composer </span><span class="pun">--</span><span class="pln">version</span>
  • 阿帕奇

我们将使用 Apache 作为 CodeIgniter 应用程序的 Web 服务器。使用以下命令安装 Apache:

<span class="pln">sudo pacman </span><span class="pun">-</span><span class="pln">S apache</span>

Check if Apache is running:

<span class="pln">sudo systemctl status apache</span>

If it’s not running, start and enable it:

<span class="pln">sudo systemctl start apache
sudo systemctl enable apache</span>
  • MariaDB/MySQL

对于数据库支持,请安装 MariaDB(或 MySQL)和相关实用程序:

<span class="pln">sudo pacman </span><span class="pun">-</span><span class="pln">S mariadb</span>

Start and enable MariaDB/MySQL:

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

现在,初始化并保护数据库:

<span class="pln">sudo mysql_install_db </span><span class="pun">--</span><span class="pln">user</span><span class="pun">=</span><span class="pln">mysql </span><span class="pun">--</span><span class="pln">basedir</span><span class="pun">=</span><span class="str">/usr --datadir=/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">lib</span><span class="pun">/</span><span class="pln">mysql
sudo systemctl start mariadb
sudo mysql_secure_installation</span>

第 3 步。为 CodeIgniter 配置 Apache。

为 CodeIgniter 项目创建新的虚拟主机配置文件。将 替换为实际的项目目录路径和域名:your_project_directoryyour_domain

<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">extra</span><span class="pun">/</span><span class="pln">httpd</span><span class="pun">-</span><span class="pln">your_project_directory</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@your_domain
DocumentRoot "/path/to/your_project_directory/public"
ServerName your_domain

</span><span class="tag"><Directory</span> <span class="atv">"/path/to/your_project_directory/public"</span><span class="tag">></span><span class="pln">
AllowOverride All
Require all granted
</span><span class="tag"></Directory></span>
<span class="tag"></VirtualHost></span>

编辑系统的主机文件,将您的域映射到本地主机:

<span class="pln">sudo nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">hosts</span>

添加以下行:

<span class="lit">127.0</span><span class="pun">.</span><span class="lit">0.1</span><span class="pln"> your_domain</span>

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

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

要确保您的配置正确,请运行:

<span class="pln">sudo apachectl configtest</span>

Step 4. Downloading and Installing CodeIgniter.

第 4 步。下载并安装 CodeIgniter。

设置好环境后,让我们下载并安装 CodeIgniter。导航到您的项目目录并使用 Composer 创建一个新的 CodeIgniter 项目:

<span class="pln">composer create</span><span class="pun">-</span><span class="pln">project codeigniter4</span><span class="pun">/</span><span class="pln">appstarter </span><span class="pun">.</span>

CodeIgniter 现已安装,但您可能希望进一步自定义它。浏览 和 目录以根据您的项目要求进行更改。apppublic

通过您的网络浏览器输入您的域(例如,)。您应该会看到 CodeIgniter 欢迎页面,确认安装成功。http://your_domain

第5步。数据库配置。

让我们为您的 CodeIgniter 应用程序配置数据库。在 CodeIgniter 项目根目录中打开该文件:.env

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

使用您的MariaDB / MySQL凭据更新数据库设置:

<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="pln"> your_database_name
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="pln"> your_database_username
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="pln"> your_database_password</span>

第 6 步。测试您的 CodeIgniter 应用程序。

现在一切已设置完毕,让我们测试您的 CodeIgniter 应用程序,以确保它按预期工作。创建新的控制器和视图以测试应用程序:

<span class="pln">php spark make</span><span class="pun">:</span><span class="pln">controller </span><span class="typ">TestController</span><span class="pln">
php spark make</span><span class="pun">:</span><span class="pln">view test</span>

编辑文件以添加示例函数和视图。TestController.php

步骤 7.通过网络浏览器访问应用程序。

通过 Web 浏览器访问新控制器:

<span class="pln">http</span><span class="pun">:</span><span class="com">//your_domain/test</span>

您应该会看到 CodeIgniter 欢迎页面:

如何在Manjaro上安装CodeIgniter

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


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

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

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