如何在 Ubuntu 22.04 LTS 上安装 CodeIgniter

Linux命令 Edge插件网 2年前 (2023-03-11) 575次浏览 已收录 0个评论

CodeIgniter 是一个快速、轻量级且易于使用的 PHP 框架,非常适合中小型项目。它的简单性、速度和来自大型社区的支持使其成为想要快速轻松地构建动态 Web 应用程序的开发人员的热门选择。如何在 Ubuntu 22.04 LTS 上安装 CodeIgniter

在 Ubuntu 22.04 LTS Jammy Jellyfish 上安装 CodeIgniter

第 1 步。首先,通过在终端中运行以下命令,确保所有系统软件包都是最新的。apt

<span class="pln">sudo apt update
sudo apt upgrade apt</span><span class="pun">-</span><span class="pln">transport</span><span class="pun">-</span><span class="pln">https</span>

第 2 步。在 Ubuntu 22.04 上安装 LAMP 堆栈。

在开始本教程之前,必须在服务器上安装 LAMP 服务器。如果您没有安装 LAMP 堆栈,您可以按照我们的指南进行操作。

第 3 步。配置数据库。

默认情况下,MariaDB 未强化。您可以使用脚本保护 MariaDB。您应该仔细阅读并在每个步骤下方,这将设置root密码,删除匿名用户,禁止远程root登录,并删除测试数据库和对安全MariaDB的访问权限。mysql_secure_installation

<span class="pln">mysql_secure_installation</span>

像这样配置它:

<span class="pun">-</span> <span class="typ">Set</span><span class="pln"> root password</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y
</span><span class="pun">-</span> <span class="typ">Remove</span><span class="pln"> anonymous users</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y
</span><span class="pun">-</span> <span class="typ">Disallow</span><span class="pln"> root login remotely</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y
</span><span class="pun">-</span> <span class="typ">Remove</span><span class="pln"> test database </span><span class="kwd">and</span><span class="pln"> access to it</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y
</span><span class="pun">-</span> <span class="typ">Reload</span><span class="pln"> privilege tables now</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y</span>

接下来,我们需要登录到 MariaDB 控制台并为 CodeIgniter 创建一个数据库。运行以下命令:

<span class="pln">mysql </span><span class="pun">-</span><span class="pln">u root </span><span class="pun">-</span><span class="pln">p</span>

这将提示您输入密码,因此请输入您的MariaDB root密码并按Enter键。登录到数据库服务器后,您需要为 CodeIgniter 安装创建一个数据库:

<span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> CREATE USER </span><span class="str">'codeigniter'</span><span class="pun">@</span><span class="str">'localhost'</span><span class="pln"> IDENTIFIED BY </span><span class="str">'Your-Strong-Passwd'</span><span class="pun">;</span>
<span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> CREATE DATABASE codeigniter</span><span class="pun">;</span>
<span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> GRANT ALL ON codeigniter</span><span class="pun">.*</span><span class="pln"> to </span><span class="str">'codeigniter'</span><span class="pun">@</span><span class="str">'localhost'</span><span class="pun">;</span>
<span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> FLUSH PRIVILEGES</span><span class="pun">;</span>
<span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> EXIT</span><span class="pun">;</span>

第 4 步。在 Ubuntu 22.04 上安装 CodeIgniter

默认情况下,CodeIgniter 在 Ubuntu 22.04 基本存储库上不可用。现在运行以下命令,将最新版本的 CodeIgniter 从 GitHub 页面下载到您的 Ubuntu 系统:

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

下载完成后,将存档的内容解压缩到服务器上的目录中:

<span class="pln">tar xvf </span><span class="typ">CodeIgniter4</span><span class="pun">-</span><span class="lit">4.3</span><span class="pun">.</span><span class="lit">1.tar</span><span class="pun">.</span><span class="pln">gz
mv </span><span class="typ">CodeIgniter4</span><span class="pun">-*/</span> <span class="typ">CodeIgniter</span>

接下来,您需要编辑数据库配置:

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

设置环境:

<span class="com">#--------------------------------------------------------------------</span>
<span class="com"># ENVIRONMENT</span>
<span class="com">#--------------------------------------------------------------------</span><span class="pln">
CI_ENVIRONMENT </span><span class="pun">=</span><span class="pln"> development</span>

设置数据库连接:

<span class="com">#--------------------------------------------------------------------</span>
<span class="com"># DATABASE</span>
<span class="com">#--------------------------------------------------------------------</span><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"> codeigniter
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"> codeigniter
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="typ">Your</span><span class="pun">-</span><span class="typ">Strong</span><span class="pun">-</span><span class="typ">Passwd</span><span class="pln">
database</span><span class="pun">.</span><span class="kwd">default</span><span class="pun">.</span><span class="typ">DBDriver</span> <span class="pun">=</span> <span class="typ">MySQLi</span>

配置 CodeIgniter 基本 URL 以通过您的 Web 浏览器访问:

<span class="pln">app</span><span class="pun">.</span><span class="pln">baseURL </span><span class="pun">=</span> <span class="str">'http://your-domain.com'</span>

保存并关闭文件,然后将 CodeIgniter 文件夹移动到 :/srv

<span class="pln">sudo mv </span><span class="typ">CodeIgniter</span> <span class="pun">/</span><span class="pln">srv</span>

第5步。配置阿帕奇。

现在,我们为您的 CodeIgniter 应用程序创建一个虚拟主机配置文件。要创建虚拟主机文件,请打开终端并运行以下命令:

<span class="pln">nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">apache2</span><span class="pun">/</span><span class="pln">sites</span><span class="pun">-</span><span class="pln">available</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 admin@your-domain.com
  DocumentRoot /srv/CodeIgniter/public
  ServerName your-domain.com
  ServerAlias www.your-domain.com

</span><span class="tag"><Directory</span> <span class="pun">/</span><span class="atn">srv</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">
  AllowOverride All
  Require all granted
</span><span class="tag"></Directory></span><span class="pln">

  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined
</span><span class="tag"></VirtualHost></span>

保存并关闭文件,然后重新启动 Apache Web 服务器,以便进行更改:

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

第 6 步。访问 CodeIgniter Web 界面。

成功安装后,现在打开您的 Web 浏览器并使用 URL 访问 CodeIgniter Web UI。您将被重定向到以下页面:http://your-domain.com

如何在 Ubuntu 22.04 LTS 上安装 CodeIgniter

感谢您使用本教程在 Ubuntu 22.04 LTS Jammy Jellyfish 系统上安装 CodeIgniter。如需其他帮助或有用信息,我们建议您查看 CodeIgniter 网站


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

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

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