ROS与web入门教程-安装cakephp
ROS与web入门教程-安装cakephp
说明:
- 介绍如何安装cakephp
- 测试版本为cakephp4
步骤:
- 安装composer
curl -s https://getcomposer.org/installer | php
- 在web根目录生产cakephp项目
cd /home/ubuntu/web
composer create-project --prefer-dist cakephp/app:4.* cms
- 增加虚拟机
- 通过增加
vim /usr/local/nginx/conf/vhost/80.conf
- 内容如下:
server {
listen 80;
listen [::]:80;
server_name _;
root /home/ubuntu/web/cms/webroot;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
添加数据库
- 添加表
- 打开http://192.168.0.139:81/phpmyadmin/
- 输入账号root,密码ncnynl.com
- 点击左边的新建,效果如下:
写入数据库名cake_cms,点执行
添加表及测试数据
点击上部的sql,效果如下:
- 复制如下代码,运行执行
USE cake_cms;
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
created DATETIME,
modified DATETIME
);
CREATE TABLE articles (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
title VARCHAR(255) NOT NULL,
slug VARCHAR(191) NOT NULL,
body TEXT,
published BOOLEAN DEFAULT FALSE,
created DATETIME,
modified DATETIME,
UNIQUE KEY (slug),
FOREIGN KEY user_key (user_id) REFERENCES users(id)
) CHARSET=utf8mb4;
CREATE TABLE tags (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(191),
created DATETIME,
modified DATETIME,
UNIQUE KEY (title)
) CHARSET=utf8mb4;
CREATE TABLE articles_tags (
article_id INT NOT NULL,
tag_id INT NOT NULL,
PRIMARY KEY (article_id, tag_id),
FOREIGN KEY tag_key(tag_id) REFERENCES tags(id),
FOREIGN KEY article_key(article_id) REFERENCES articles(id)
);
INSERT INTO users (email, password, created, modified)
VALUES
('cakephp@example.com', 'secret', NOW(), NOW());
INSERT INTO articles (user_id, title, slug, body, published, created, modified)
VALUES
(1, 'First Post', 'first-post', 'This is the first post.', 1, now(), now());
- 设置config/app_local.php
'username' => 'root',
'password' => 'ncnynl.com',
'database' => 'cake_cms',
- 访问cms
http://192.168.0.139
- 效果如下:
安装相关工具:
- 安装vscode开发php
sudo apt install snapd
sudo snap install --classic vscode
- 安装terminator终端工具
sudo apt install terminator
参考:
- https://book.cakephp.org/4/zh/quickstart.html
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号