在Ubuntu 18.04/Ubuntu 16.04/Debian 9上安装CakePhp框架
如何在Ubuntu 18.04/Ubuntu 16.04/Debian 9上安装最新的CakePhp框架?
CakePHP是PHP的快速发展框架,它使用前载体,关联数据映射和MVC等流行的设计模式。
CakePHP旨在提供一个结构化框架,使PHP用户在所有级别都能快速开发强大的Web应用程序,而不会损失灵活性。
以下是在Ubuntu 18.04/Ubuntu 16.04/Debian 9上安装CakePhp的步骤。
第1步:安装系统依赖项
要运行CakePhp,我们需要在主机上安装PHP,Web服务器和数据库服务器。
安装PHP和扩展
通过运行命令来安装php:
sudo apt install php php-cli php-json php-pdo php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath php-intl
安装MariaDB数据库服务器:
如何在Debian 9/Debian 8上安装MariaDB 10
如何在Ubuntu 16.04(Xenial Xerus)LTS上安装MariaDB 10.x
在Ubuntu 18.04和Centos 7上安装MariaDB 10.3
有一个运行的数据库服务器,以root用户身份登录mysql shell:
$mysql -u root -p
为CakePHP创建数据库。
CREATE DATABASE myproject; GRANT ALL ON myproject.* to 'myproject_user'@'localhost' IDENTIFIED BY 'StrongPassword'; FLUSH PRIVILEGES; QUIT;
安装Apache Web服务器
还通过在终端中运行下面的命令来安装Apache2 Web服务器依赖项。
sudo apt -y install apache2 libapache2-mod-php
应启动并启用该服务以启动启动。
第2步:安装Composer
确保安装WGet
sudo apt -y install wget
下载Composer Installer:
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 1.8.0) successfully installed to: /usr/local/bin/composer Use it: php /usr/local/bin/composer
你应该能够使用 composer命令
______
/____/___ ____ ___ ____ ____ ________ _____
// /__ \/__ `__ \/__ \/__ \/___/_ \/___/
//___//_////////_///_/(__ ) __//
____/____/_//_//_/.___/____/____/___/_/
/_/
Composer version 1.8.0 2016-12-03 10:31:16
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.
-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 1.8.0 2016-12-03 10:31:16
每当要更新composer时,只需执行:
$sudo composer self-update You are already using composer version 1.8.0 (stable channel).
我们现在拥有Ubuntu/Debian Server上安装了一个Composer PHP依赖关系管理器。
第3步:创建一个cakephp项目
对于一个新项目,我们可以使用CakePhp应用程序骨架。
mkdir /srv/projects cd /srv/projects composer create-project --prefer-dist cakephp/app
如果要使用自定义应用程序指示者名称(例如/myapp /):
composer create-project --prefer-dist cakephp/app myapp
应用程序目录设置应该如下所示:
$ls -1 bin composer.json composer.lock config index.php logs phpunit.xml.dist plugins README.md src tests tmp vendor webroot
设置数据库连接设置 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/myapp bin/cake server
这将在端口上启动PHP的内置WebServer 8765。
打开 http://localhost:8765在Web浏览器中查看欢迎页面。

