IoTではないRaspberry Piの使い方(PHPのWEBフレームワークを動かす)

過去の記事にて記載したとおり、Raspberry Pi は「inux系OSが動く超小型のコンピュータ」として使用できます。このため、この記事ではWordPressのサーバーとして構築してみました。

今回は、Raspberry PiをWEBサーバーとし、PHPフレームワークを動作させてテスト環境を構築してみます。

Raspberry Pi OSをインストールし、Webサーバーを構築

OSのインストール

まずはOSをインストールします。

2023年12月に新しいバーションが公開されたので、そちらのインストール方法は、上記記事を参考にしてください。

今回は64-bit を選択し、インストールしました。

SSLの設定

ssh-keygen -t ed25519
mkdir ~/.ssh
mv raspberrypi.pub ~/.ssh/authorized_keys
chmod -R 700 ~/.ssh

ssh-keygenでキーを作り、.sshフォルダを作成して、authorized_keysに名前を変えて移動します。

一方、.pubの付いていない方は、WinSCPなどを使用してRaspberry Piから手持ちのパソコンなどに取得します。

これを使用してTera Termなどで接続を確認したら、vi /etc/ssh/sshd_configの以下の部分を修正して、再起動します。

PasswordAuthentication no
PermitRootLogin no

WEBサーバーのインストール

sudo apt install apache2

PHPをインストール

OSをインストールした後、まだPHPをインストールしていないため、php -v は見つからないと出ます。

またこの状態では、通常手順でインストールを行うと、PHP7.4がインストールされます。

php -v
-bash: php: コマンドが見つかりません

sudo apt depends php
php
  依存: php7.4

PHPは出来るだけ最新のものが必要なので、こちらのサイト様を参考にインストールします。

こちら記載の処理を実行すると、php8.3がインストールされるようになります。

sudo wget -qO /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
→deb https://packages.sury.org/php/ bullseye main が返ります。

sudo apt update
sudo apt depends php
→ php
  依存: php8.3

確認出来たので、phpをインストールします。

sudo apt install php -y
sudo apt install php-bcmath php-mbstring php-xml php-mysql php-curl php-zip php-intl -y
php -v
PHP 8.3.2-1+0~20240120.16+debian11~1.gbpb43448 (cli) (built: Jan 20 2024 14:17:59) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.2-1+0~20240120.16+debian11~1.gbpb43448, Copyright (c), by Zend Technologies

データーベースサーバーのインストール

sudo apt-get install mariadb-server

導入できたら、DBの初期設定を行います。

$ sudo mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none):←そのままリターン
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] Y ←Yを選択
Enabled successfully!
Reloading privilege tables..
 ... Success!


You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] Y ←Yを選択
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y ←Yを選択
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y ←Yを選択
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y ←Yを選択
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y ←Yを選択
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
$

phpMyAdminのインストール

データベースのメンテナンス用に、phpMyAdminをインストールします。

sudo apt install phpmyadmin

設定が進行すると、次の画面が現れます。

インストールしているのはApacheなので、apache2 の方でスペースキーを押下し、TABキーで了解します。

apache2の方に*(アスタリスク)が付いている事を確認してください。

最後にこのような確認が出ますが、既にmariaDBをインストールしてあるので、TABキーで<いいえ>に移し、Enterで確定します。

インストールが完了したら、ウェブブラウザから呼び出してみます。

http://[Raspberry PiのIPアドレス]/phpmyadmin

エラーが発生します。

恐らく、通常手順でインストールされるphpmyadminが、PHPの7.4を想定しているのに対し、8.3をインストールしているためでしょう。

普通にインストールしたphpMyAdminを、新しいバージョンに更新します。

wgeでZIPファイルを取得し、解凍します。

sudo wget https://files.phpmyadmin.net/phpMyAdmin/5.2.1/phpMyAdmin-5.2.1-all-languages.zip
sudo unzip phpMyAdmin-5.2.1-all-languages.zip
sudo mv phpMyAdmin-5.2.1-all-languages phpmyadmin
sudo rm -fr /usr/share/phpmyadmin
sudo cp -R ./phpmyadmin /usr/share

これで新版に切り替わったはずなので、起動してみます。

http://[ラズベリーパイのホスト名]/phpmyadmin/

で接続すると、このようにphpmyadminの画面が表示されます。

phpmyadminを表示してもエラーにならず、ログインすると、トップページのバージョンがダウンロードした5.2.1になっています。

Composer をインストールする

PHPのフレームワークをインストールするには、必要なライブラリの依存関係を管理するシステムのComposerが必要なので、インストールします。

こちらのサイト様の情報を元にインストールしました。

wget -O composer-setup.php https://getcomposer.org/installer
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
All settings correct for using Composer
Downloading...

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

composer --version
Composer version 2.6.6 2023-12-08 18:32:26

sudo composer self-update
You are already using the latest available Composer version 2.6.6 (stable channel).

CakePHPをインストールする

ComposerからCakePHPをインストールします。

今回は、WEBサーバーのルートディレクトリに ckproject というプロジェクトフォルダを作成するよう設定します。

cd /var/www/html
composer create-project cakephp/app ckproject

エラーが出る場合

このように、

mkdir() : Permission denied

というエラーが出る場合は、ユーザーの設定が必要です。

Raspberry Pi はOSインストール時に設定したユーザー名のみですが、インストールなどの管理権限が必要な場合、sudoを付けて一時的に管理権限を使用します。

このため、WEBサーバーのルートディレクトリである /var/www/htm の所有者も、管理者であるrootになっています。

一方、Apacheをインストールした際、www-dataというユーザー名/グループ名が自動設定され、このユーザーがWEBサーバーを動作させています。

このため、WEBサーバーのルートディレクトリの所有者をrootからwww-dataに変更します。

sudo chown -R www-data:www-data /var/www/

また、所有者がwww-dataに変更されたため、composer create-project もwww-dataユーザーで実施します。

ただ、www-dataは通常、ログイン権限を持たないユーザーなので、

sudo su - www-data --shell=/bin/bash

で強制的にwww-dataになって、実行します。

$ composer create-project cakephp/app ckproject
Creating a "cakephp/app" project at "./ckproject"
Installing cakephp/app (5.0.1)
  - Installing cakephp/app (5.0.1): Extracting archive
Created project in /var/www/html/ckproject
Loading composer repositories with package information
Updating dependencies
Lock file operations: 86 installs, 0 updates, 0 removals
  - Locking brick/varexporter (0.4.0)
  - Locking cakephp/bake (3.1.0)
  - Locking cakephp/cakephp (5.0.5)
  - Locking cakephp/cakephp-codesniffer (5.1.1)
  - Locking cakephp/chronos (3.0.4)
  - Locking cakephp/debug_kit (5.0.5)
  - Locking cakephp/migrations (4.1.1)
  - Locking cakephp/plugin-installer (2.0.1)
  - Locking cakephp/twig-view (2.0.1)
  - Locking composer/ca-bundle (1.4.0)
  - Locking composer/class-map-generator (1.1.0)
  - Locking composer/composer (2.6.5)
  - Locking composer/metadata-minifier (1.0.0)
  - Locking composer/pcre (3.1.1)
  - Locking composer/semver (3.4.0)
  - Locking composer/spdx-licenses (1.5.8)
  - Locking composer/xdebug-handler (3.0.3)
  - Locking dealerdirect/phpcodesniffer-composer-installer (v1.0.0)
  - Locking doctrine/sql-formatter (1.1.3)
  - Locking jasny/twig-extensions (v1.3.0)
  - Locking josegonzalez/dotenv (4.0.0)
  - Locking justinrainbow/json-schema (v5.2.13)
  - Locking laminas/laminas-diactoros (3.3.0)
  - Locking laminas/laminas-httphandlerrunner (2.10.0)
  - Locking league/container (4.2.0)
  - Locking m1/env (2.2.0)
  - Locking mobiledetect/mobiledetectlib (3.74.3)
  - Locking myclabs/deep-copy (1.11.1)
  - Locking nikic/php-parser (v4.18.0)
  - Locking phar-io/manifest (2.0.3)
  - Locking phar-io/version (3.2.1)
  - Locking phpstan/phpdoc-parser (1.25.0)
  - Locking phpunit/php-code-coverage (10.1.11)
  - Locking phpunit/php-file-iterator (4.1.0)
  - Locking phpunit/php-invoker (4.0.0)
  - Locking phpunit/php-text-template (3.0.1)
  - Locking phpunit/php-timer (6.0.0)
  - Locking phpunit/phpunit (10.5.9)
  - Locking psr/container (2.0.2)
  - Locking psr/http-client (1.0.3)
  - Locking psr/http-factory (1.0.2)
  - Locking psr/http-message (2.0)
  - Locking psr/http-server-handler (1.0.2)
  - Locking psr/http-server-middleware (1.0.2)
  - Locking psr/log (3.0.0)
  - Locking psr/simple-cache (3.0.0)
  - Locking react/promise (v3.1.0)
  - Locking robmorgan/phinx (0.15.5)
  - Locking sebastian/cli-parser (2.0.0)
  - Locking sebastian/code-unit (2.0.0)
  - Locking sebastian/code-unit-reverse-lookup (3.0.0)
  - Locking sebastian/comparator (5.0.1)
  - Locking sebastian/complexity (3.2.0)
  - Locking sebastian/diff (5.1.0)
  - Locking sebastian/environment (6.0.1)
  - Locking sebastian/exporter (5.1.1)
  - Locking sebastian/global-state (6.0.1)
  - Locking sebastian/lines-of-code (2.0.2)
  - Locking sebastian/object-enumerator (5.0.0)
  - Locking sebastian/object-reflector (3.0.0)
  - Locking sebastian/recursion-context (5.0.0)
  - Locking sebastian/type (4.0.0)
  - Locking sebastian/version (4.0.1)
  - Locking seld/jsonlint (1.10.1)
  - Locking seld/phar-utils (1.2.1)
  - Locking seld/signal-handler (2.0.2)
  - Locking slevomat/coding-standard (8.14.1)
  - Locking squizlabs/php_codesniffer (3.8.1)
  - Locking symfony/config (v7.0.3)
  - Locking symfony/console (v7.0.3)
  - Locking symfony/deprecation-contracts (v3.4.0)
  - Locking symfony/filesystem (v7.0.3)
  - Locking symfony/finder (v7.0.0)
  - Locking symfony/polyfill-ctype (v1.28.0)
  - Locking symfony/polyfill-intl-grapheme (v1.28.0)
  - Locking symfony/polyfill-intl-normalizer (v1.28.0)
  - Locking symfony/polyfill-mbstring (v1.28.0)
  - Locking symfony/polyfill-php73 (v1.28.0)
  - Locking symfony/polyfill-php80 (v1.28.0)
  - Locking symfony/polyfill-php81 (v1.28.0)
  - Locking symfony/process (v7.0.3)
  - Locking symfony/service-contracts (v3.4.1)
  - Locking symfony/string (v7.0.3)
  - Locking theseer/tokenizer (1.2.2)
  - Locking twig/markdown-extra (v3.8.0)
  - Locking twig/twig (v3.8.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 86 installs, 0 updates, 0 removals
  - Installing cakephp/plugin-installer (2.0.1): Extracting archive
  - Installing squizlabs/php_codesniffer (3.8.1): Extracting archive
  - Installing dealerdirect/phpcodesniffer-composer-installer (v1.0.0): Extracting archive
  - Installing nikic/php-parser (v4.18.0): Extracting archive
  - Installing symfony/polyfill-php80 (v1.28.0): Extracting archive
  - Installing symfony/polyfill-mbstring (v1.28.0): Extracting archive
  - Installing symfony/polyfill-ctype (v1.28.0): Extracting archive
  - Installing twig/twig (v3.8.0): Extracting archive
  - Installing twig/markdown-extra (v3.8.0): Extracting archive
  - Installing jasny/twig-extensions (v1.3.0): Extracting archive
  - Installing psr/simple-cache (3.0.0): Extracting archive
  - Installing psr/log (3.0.0): Extracting archive
  - Installing psr/http-message (2.0): Extracting archive
  - Installing psr/http-server-handler (1.0.2): Extracting archive
  - Installing psr/http-server-middleware (1.0.2): Extracting archive
  - Installing psr/http-factory (1.0.2): Extracting archive
  - Installing psr/http-client (1.0.3): Extracting archive
  - Installing psr/container (2.0.2): Extracting archive
  - Installing league/container (4.2.0): Extracting archive
  - Installing laminas/laminas-diactoros (3.3.0): Extracting archive
  - Installing laminas/laminas-httphandlerrunner (2.10.0): Extracting archive
  - Installing composer/ca-bundle (1.4.0): Extracting archive
  - Installing cakephp/chronos (3.0.4): Extracting archive
  - Installing cakephp/cakephp (5.0.5): Extracting archive
  - Installing cakephp/twig-view (2.0.1): Extracting archive
  - Installing brick/varexporter (0.4.0): Extracting archive
  - Installing cakephp/bake (3.1.0): Extracting archive
  - Installing phpstan/phpdoc-parser (1.25.0): Extracting archive
  - Installing slevomat/coding-standard (8.14.1): Extracting archive
  - Installing cakephp/cakephp-codesniffer (5.1.1): Extracting archive
  - Installing doctrine/sql-formatter (1.1.3): Extracting archive
  - Installing symfony/process (v7.0.3): Extracting archive
  - Installing symfony/polyfill-php81 (v1.28.0): Extracting archive
  - Installing symfony/polyfill-php73 (v1.28.0): Extracting archive
  - Installing symfony/finder (v7.0.0): Extracting archive
  - Installing symfony/filesystem (v7.0.3): Extracting archive
  - Installing symfony/polyfill-intl-normalizer (v1.28.0): Extracting archive
  - Installing symfony/polyfill-intl-grapheme (v1.28.0): Extracting archive
  - Installing symfony/string (v7.0.3): Extracting archive
  - Installing symfony/service-contracts (v3.4.1): Extracting archive
  - Installing symfony/console (v7.0.3): Extracting archive
  - Installing seld/signal-handler (2.0.2): Extracting archive
  - Installing seld/phar-utils (1.2.1): Extracting archive
  - Installing seld/jsonlint (1.10.1): Extracting archive
  - Installing react/promise (v3.1.0): Extracting archive
  - Installing justinrainbow/json-schema (v5.2.13): Extracting archive
  - Installing composer/pcre (3.1.1): Extracting archive
  - Installing composer/xdebug-handler (3.0.3): Extracting archive
  - Installing composer/spdx-licenses (1.5.8): Extracting archive
  - Installing composer/semver (3.4.0): Extracting archive
  - Installing composer/metadata-minifier (1.0.0): Extracting archive
  - Installing composer/class-map-generator (1.1.0): Extracting archive
  - Installing composer/composer (2.6.5): Extracting archive
  - Installing cakephp/debug_kit (5.0.5): Extracting archive
  - Installing symfony/deprecation-contracts (v3.4.0): Extracting archive
  - Installing symfony/config (v7.0.3): Extracting archive
  - Installing robmorgan/phinx (0.15.5): Extracting archive
  - Installing cakephp/migrations (4.1.1): Extracting archive
  - Installing m1/env (2.2.0): Extracting archive
  - Installing josegonzalez/dotenv (4.0.0): Extracting archive
  - Installing mobiledetect/mobiledetectlib (3.74.3): Extracting archive
  - Installing sebastian/version (4.0.1): Extracting archive
  - Installing sebastian/type (4.0.0): Extracting archive
  - Installing sebastian/recursion-context (5.0.0): Extracting archive
  - Installing sebastian/object-reflector (3.0.0): Extracting archive
  - Installing sebastian/object-enumerator (5.0.0): Extracting archive
  - Installing sebastian/global-state (6.0.1): Extracting archive
  - Installing sebastian/exporter (5.1.1): Extracting archive
  - Installing sebastian/environment (6.0.1): Extracting archive
  - Installing sebastian/diff (5.1.0): Extracting archive
  - Installing sebastian/comparator (5.0.1): Extracting archive
  - Installing sebastian/code-unit (2.0.0): Extracting archive
  - Installing sebastian/cli-parser (2.0.0): Extracting archive
  - Installing phpunit/php-timer (6.0.0): Extracting archive
  - Installing phpunit/php-text-template (3.0.1): Extracting archive
  - Installing phpunit/php-invoker (4.0.0): Extracting archive
  - Installing phpunit/php-file-iterator (4.1.0): Extracting archive
  - Installing theseer/tokenizer (1.2.2): Extracting archive
  - Installing sebastian/lines-of-code (2.0.2): Extracting archive
  - Installing sebastian/complexity (3.2.0): Extracting archive
  - Installing sebastian/code-unit-reverse-lookup (3.0.0): Extracting archive
  - Installing phpunit/php-code-coverage (10.1.11): Extracting archive
  - Installing phar-io/version (3.2.1): Extracting archive
  - Installing phar-io/manifest (2.0.3): Extracting archive
  - Installing myclabs/deep-copy (1.11.1): Extracting archive
  - Installing phpunit/phpunit (10.5.9): Extracting archive
17 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating autoload files
57 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
PHP CodeSniffer Config installed_paths set to ../../cakephp/cakephp-codesniffer,../../slevomat/coding-standard
No security vulnerability advisories found.
> App\Console\Installer::postInstall
Created `config/app_local.php` file
Created `/var/www/html/ckproject/logs` directory
Created `/var/www/html/ckproject/tmp/cache/views` directory
Set Folder Permissions ? (Default to Y) [Y,n]? y
Permissions set on /var/www/html/ckproject/tmp/cache
Permissions set on /var/www/html/ckproject/tmp/cache/models
Permissions set on /var/www/html/ckproject/tmp/cache/persistent
Permissions set on /var/www/html/ckproject/tmp/cache/views
Permissions set on /var/www/html/ckproject/tmp/sessions
Permissions set on /var/www/html/ckproject/tmp/tests
Permissions set on /var/www/html/ckproject/tmp
Permissions set on /var/www/html/ckproject/logs
Updated Security.salt value in config/app_local.php

CakePHPの確認

インストールが完了しましたので、http://[Raspberry PiのIP]/ckproject で確認してみます。

Database driver `Cake\Database\Driver\Sqlite` cannot be used due to a missing PHP extension or unmet dependency. Requested by connection `test`

エラーが発生して、起動できませんでした。

このエラーは、Sqliteが見つからないのでデータベースに接続出来ないといっていますが、環境的にはmariaDBをインストールしたため、そちらに繋げる必要があります。

/ckproject/config にある、app_local.php というファイルに’DATABASE_TEST_URL’という項目があり、この初期設定値が 

‘sqlite://127.0.0.1/tmp/tests.sqlite’ であるためSqliteを探しに行ってエラーを発生させているというのが真相でした。

このため、この部分をnullに書き換えます。

sudo vi /var/www/html/ckproject/config/app_local.php

            'url' => env('DATABASE_TEST_URL', 'sqlite://127.0.0.1/tmp/tests.sqlite'),
↓
            'url' => env('DATABASE_TEST_URL', null),

修正後、http://[Raspberry PiのIP]/ckproject で起動してみると

エラーがなくなり、無事にCakePHPがインストール出来たようです。

CakePHPの使用するデータベースを作成

設定ファイルである、/var/www/html/ckproject/config/app_local.php には以下のような記述があります。

この記述はCakePHPをインストールしたとき自動作成されたものです。

    'Datasources' => [
        'default' => [
            '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' => 'my_app',
            'password' => 'secret',

            'database' => 'my_app',
            /*
             * set it here.
             */
            //'schema' => 'myapp',

            /*
             * You can use a DSN string to set the entire configuration
             */
            'url' => env('DATABASE_URL', null),
        ],

        /*
         * The test connection is used during the test suite.
         */
        'test' => [
            'host' => 'localhost',
            //'port' => 'non_standard_port_number',
            'username' => 'my_app',
            'password' => 'secret',
            'database' => 'test_myapp',
            //'schema' => 'myapp',
            'url' => env('DATABASE_TEST_URL', null),
        ],
    ],

つまり、my_appというユーザーで、secretというパスワードを使用し、my_appというデータベースに接続すると宣言されているので、mariaDBにこの条件でデータベースを作成します。

また作成したデータベースの権限からユーザーアカウントを作成しておきます。

データベースが作成出来たら、id、text、作成日時、更新日時を持つテーブルを作成します。

・データベースの作成をSQL化すると
CREATE TABLE messages (
    id INT AUTO_INCREMENT PRIMARY KEY,
    text VARCHAR(255) NOT NULL,
    created DATETIME DEFAULT CURRENT_TIMESTAMP,
    modified DATETIME DEFAULT CURRENT_TIMESTAMP
);

コードを作成

テスト目的なので、コードは簡単にします。

テキストの入力枠一つ。ボタン一つ。ボタンを押すとテキストがDBに登録され、入力枠の下に表示されるようにします。

・/var/www/html/ckproject/src/Model/Table/MessagesTable.php

<?php
namespace App\Model\Table;

use Cake\ORM\Table;

class MessagesTable extends Table
{
    public function initialize(array $config): void
    {
        $this->addBehavior('Timestamp');
    }
}
?>

・/var/www/html/ckproject/src/Controller/MessagesController.php
<?php
namespace App\Controller;

use App\Controller\AppController;

class MessagesController extends AppController
{
    public function index()
    {
        $message = $this->Messages->newEmptyEntity();
        if ($this->request->is('post')) {
            $message = $this->Messages->patchEntity($message, $this->request->ge
tData());
            if ($this->Messages->save($message)) {
                $this->Flash->success(__('The message has been saved.'));
                return $this->redirect(['action' => 'index']);
            }
            $this->Flash->error(__('Unable to add your message.'));
        }
        $this->set('message', $message);
        $messages = $this->Messages->find('all');
        $this->set(compact('messages'));
    }
}
?>

・/var/www/html/ckproject/templates/Messages/index.php
<div>
    <?= $this->Form->create($message) ?>
    <?= $this->Form->control('text') ?>
    <?= $this->Form->button(__('Submit')) ?>
    <?= $this->Form->end() ?>
</div>

<div>
    <ul>
    <?php foreach ($messages as $message): ?>
        <li><?= h($message->text) ?></li>
    <?php endforeach; ?>
    </ul>
</div>

ファイルのユーザーには注意します。

どのファイルも、www-dataが所有者になるようにします。

CokePHPの起動

/var/www/html/ckproject/bin/cake server -H 0.0.0.0

ファイルを配置したらCakePHPサーバーを起動します。

server -H 0.0.0.0を忘れて、localhostからしか接続できなくて、暫く悩みましたので、オプションは忘れないように

警告が発生する場合

正常に起動はしていますが、警告が出ています。

Warning: You should set `zend.assertions` to `1` in your php.ini for your development environment. in /var/www/html/ckproject/vendor/cakephp/cakephp/src/Core/Configure.php on line 102

この警告は、開発環境ではzend.assertionsを1に設定し、アサーションを有効にすることを推奨しています。開発中にプログラムのエラーや不具合を早期に発見し、修正することが可能になります。

デフォルトでは-1に設定されていますので、指定のファイルを修正すれば警告は出なくなります。

起動に成功しました。

入力枠に入力したテキストは、データベースに登録され、それが表示されています。

まとめ

Raspberry Piでも最新のPHPを導入し、フレームワーク開発環境を導入できます。

小型なので、出先での開発環境として使用する事も可能でしょう。

また、何等かの方法で外部からRaspberry Piへの接続方法を確立すれば、接続したセンサー類の結果を出力したりする事も可能になります。

フレームワークを使用すれば、操作画面や、データ接続部分の開発を省力化する事が可能ですから、機器の開発に注力できるようになる事が期待できます。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です