在 Ubuntu 22.04|20.04|18.04 上安装 CakePHP 框架在 Ubuntu 22.04|20.04|18.04 上安装 CakePHP 框架在 Ubuntu 22.04|20.04|18.04 上安装 CakePHP 框架在 Ubuntu 22.04|20.04|18.04 上安装 CakePHP 框架
  • 业务
  • 目标
  • 支持
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容

在 Ubuntu 22.04|20.04|18.04 上安装 CakePHP 框架

发表 admin at 2025年2月28日
类别
  • 未分类
标签

如何在 Ubuntu 22.04|20.04|18.04 上安装最新的 CakePHP 框架? CakePHP 是一个 PHP 快速开发框架,它使用流行的设计模式,如前端控制器、关联数据映射和 MVC。 CakePHP 旨在提供一个结构化框架,使各个级别的 PHP 用户能够快速开发强大的 Web 应用程序,而不损失任何灵活性。

以下是在 Ubuntu 22.04|20.04|18.04 Linux 操作系统上安装 CakePHP 的步骤。

第1步:安装系统依赖项

要运行 CakePHP,您需要在主机上安装 PHP、Web 服务器和数据库服务器。

安装 PHP 和扩展

通过运行以下命令安装 PHP:

sudo apt update
sudo apt install php php-common php-json php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath php-intl

安装 MariaDB 数据库服务器:

通过运行以下命令安装 MariaDB 数据库服务器

sudo apt update
sudo apt install mariadb-server mariadb-client

一旦数据库服务器正在运行,请以 root 用户身份登录 MySQL shell:

sudo mysql -u root

为 CakePHP 创建数据库。

CREATE DATABASE myproject;
GRANT ALL ON myproject.* to 'myproject_user'@'localhost' IDENTIFIED BY 'StrongPassword';
FLUSH PRIVILEGES;
QUIT;

安装 Apache 网络服务器

还可以通过在终端中运行以下命令来安装 Apache2 Web 服务器依赖项。

sudo apt -y install apache2 libapache2-mod-php

该服务应该启动并启用以在引导时启动。

步骤 2:在 Ubuntu 上安装 PHP Composer

确保安装了 wget

sudo apt -y install wget

下载 Composer 安装程序:

wget https://getcomposer.org/installer -O composer-installer.php

运行安装程序脚本以全局部署 Composer:

sudo php ./composer-installer.php --install-dir=/usr/local/bin --filename=composer

您应该看到如下所示的输出:

All settings correct for using Composer
Downloading...

Composer (version 2.1.12) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer

您应该能够使用composer命令

 ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 2.1.12 2021-11-09 16:02:04
Usage:
  command [options] [arguments]

Options:
  -h, --help                     Display this help message
  -q, --quiet                    Do not output any message
  -V, --version                  Display this application version
      --ansi                     Force ANSI output
      --no-ansi                  Disable ANSI output
  -n, --no-interaction           Do not ask any interactive question
      --profile                  Display timing and memory usage information
      --no-plugins               Whether to disable plugins.
  -d, --working-dir=WORKING-DIR  If specified, use the given directory as working directory.
      --no-cache                 Prevent use of the cache
  -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

要检查已安装的 Composer 版本,请键入命令:

$ composer -V
Composer version 2.1.12 2021-11-09 16:02:04

每当您想要更新作曲家时,只需键入:

$ sudo composer self-update
You are already using composer version 1.8.0 (stable channel).

您现在已经在 Ubuntu/Debian 服务器上安装了 Composer PHP 依赖管理器。

第 3 步:创建 CakePHP 项目

对于新项目,您可以使用 CakePHP 应用程序骨架。

sudo mkdir /srv/projects
cd /srv/projects
sudo composer create-project --prefer-dist cakephp/app

如果您想使用自定义应用程序目录名称(例如 /myapp/):

sudo composer create-project --prefer-dist cakephp/app myapp

您的应用程序目录设置应如下所示:

$ cd app
$ ls -1
README.md
bin
composer.json
composer.lock
config
index.php
logs
phpcs.xml
phpstan.neon
phpunit.xml.dist
plugins
resources
src
templates
tests
tmp
vendor
webroot

在 config/app.php 上设置数据库连接设置

$ vim config/app.php 
*/
    'Datasources' => [
        'default' => [
            'className' => 'Cake\Database\Connection',
            'driver' => 'Cake\Database\Driver\Mysql',
            'persistent' => false,
            'host' => 'localhost',
            /*
             * CakePHP will use the default DB port based on the driver selected
             * MySQL on MAMP uses port 8889, MAMP users will want to uncomment
             * the following line and set the port accordingly
             */
            //'port' => 'non_standard_port_number',
            'username' => 'myproject_user',
            'password' => 'StrongPassword',
            'database' => 'myproject',
            /*
             * You do not need to set this flag to use full utf-8 encoding (internal default since CakePHP 3.6).
             */
            //'encoding' => 'utf8mb4',
            'timezone' => 'UTC',
            'flags' => [],
            'cacheMetadata' => true,
            'log' => false,

启动开发服务器以检查您的安装是否按预期工作。

cd /srv/projects/app
bin/cake server

这将在端口 8765 上启动 PHP 的内置网络服务器。在网络浏览器中打开 http://localhost:8765 以查看欢迎页面。

参考:

  • CakePHP 书
©2015-2025 Norria support@alaica.com