edo1z blog

プログラミングなどに関するブログです

cloud9でcakephp3・MySQLを使う

cloud9プロジェクトの作成

cloud9でPHPを選択してプロジェクトを作ります。

MySQLの起動

$ mysql-ctl start
Installing MySQL
 * Stopping MySQL database server mysqld
   ...done.
 * Starting MySQL database server mysqld
   ...done.
 * Checking for tables which need an upgrade, are corrupt or were
not closed cleanly.

MySQL 5.5 database added.  Please make note of these credentials:

       Root User: hgoe
   Database Name: hoge

 * Starting MySQL database server mysqld
   ...done.

phpMyAdminのインストール

$ phpmyadmin-ctl install
Starting installation
Starting MySQL
 * Starting MySQL database server mysqld
   ...done.
Configuring database
Starting apache
 * Restarting web server apache2
   ...done.
PHPMyAdmin Installation complete. You can log in at: https://hoge-hoge.c9users.io/phpmyadmin with the following username (and blank password):

       Username: hoge

上記URLにアクセスしたらphpMyAdminが表示される。初期ではusernameと、パスワード空で入れる。root以外のユーザを作成したりする。

composerのインストール

$ curl -sS https://getcomposer.org/installer | php
Downloading 1.1.1...

Composer successfully installed to: /home/ubuntu/workspace/composer.phar
Use it: php composer.phar
Some settings on your machine may cause stability issues with Composer.
If you encounter issues, try to change the following:

The xdebug extension is loaded, this can slow down Composer a little.
Disabling it when using Composer is recommended.

composerを移動する

$ sudo mv composer.phar /usr/local/bin/composer

cakeプロジェクトの作成

$ composer create-project cakephp/app caketest
You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug

Installing cakephp/app (3.2.6)
  - Installing cakephp/app (3.2.6)
    Downloading: 100%

Created project in caketest
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing aura/installer-default (1.0.0)
    Downloading: 100%

  - Installing cakephp/plugin-installer (0.0.15)
    Downloading: 100%

  - Installing psr/log (1.0.0)
    Downloading: 100%

  - Installing mobiledetect/mobiledetectlib (2.8.22)
    Downloading: 100%

  - Installing aura/intl (1.1.1)
    Downloading: 100%

  - Installing cakephp/chronos (0.4.9)
    Downloading: 100%

  - Installing cakephp/cakephp (3.2.9)
    Downloading: 100%

  - Installing symfony/yaml (v3.0.6)
    Downloading: 100%

  - Installing symfony/filesystem (v3.0.6)
    Downloading: 100%

  - Installing symfony/config (v3.0.6)
    Downloading: 100%

  - Installing symfony/polyfill-mbstring (v1.2.0)
    Downloading: 100%

  - Installing symfony/console (v3.0.6)
    Downloading: 100%

  - Installing robmorgan/phinx (v0.5.3)
    Downloading: 100%

  - Installing cakephp/migrations (1.6.1)
    Downloading: 100%

  - Installing jakub-onderka/php-console-color (0.1)
    Downloading: 100%

  - Installing jakub-onderka/php-console-highlighter (v0.3.2)
    Downloading: 100%

  - Installing dnoegel/php-xdg-base-dir (0.1)
    Downloading: 100%

  - Installing nikic/php-parser (v2.1.0)
    Downloading: 100%

  - Installing symfony/var-dumper (v3.0.6)
    Downloading: 100%

  - Installing psy/psysh (v0.7.2)
    Downloading: 100%

  - Installing jdorn/sql-formatter (v1.2.17)
    Downloading: 100%

  - Installing cakephp/debug_kit (3.2.8)
    Downloading: 100%

  - Installing cakephp/bake (1.2.4)
    Downloading: 100%

cakephp/app suggests installing phpunit/phpunit (Allows automated tests to be run without system-wide install.)
cakephp/app suggests installing cakephp/cakephp-codesniffer (Allows to check the code against the coding standards used in CakePHP.)
symfony/console suggests installing symfony/event-dispatcher ()
symfony/console suggests installing symfony/process ()
symfony/var-dumper suggests installing ext-symfony_debug ()
psy/psysh suggests installing ext-pdo-sqlite (The doc command requires SQLite to work.)
cakephp/debug_kit suggests installing ext-sqlite (DebugKit needs to store panel data in a database. SQLite is simple and easy to use.)
Writing lock file
Generating autoload files
> Cake\Composer\Installer\PluginInstaller::postAutoloadDump
> App\Console\Installer::postInstall
Created `config/app.php` file
Set Folder Permissions ? (Default to Y) [Y,n]? Permissions set on /home/ubuntu/workspace/caketest/tmp/cache
Permissions set on /home/ubuntu/workspace/caketest/tmp/cache/models
Permissions set on /home/ubuntu/workspace/caketest/tmp/cache/persistent
Permissions set on /home/ubuntu/workspace/caketest/tmp/cache/views
Permissions set on /home/ubuntu/workspace/caketest/tmp/sessions
Permissions set on /home/ubuntu/workspace/caketest/tmp/tests
Permissions set on /home/ubuntu/workspace/caketest/tmp
Permissions set on /home/ubuntu/workspace/caketest/logs
Updated Security.salt value in config/app.php

プレビューを見る

cloud9のメニューのPreviewからプレビューを開く。database.phpの設定がまだだが、とりあえず初期画面が表示される。

cake3

database.phpの設定

config/app.phpの229行目に下記があるので、修正する。

'username' => 'hoge',
'password' => 'hoge',
'database' => 'hoge',
'encoding' => 'utf8',
'timezone' => 'UTC',
'flags' => [],
'cacheMetadata' => true,
'log' => false,