公開したCakePHPアプリケーションは、このサイトのことです。
静的なWebサイトを公開する場合にも必要な作業についてはほぼ省略して、CakePHPアプリケーションの場合に必要だったことをメインに書きます。
実際に作業したのは2月頃で、その時のメモをもとに記事を書いたので、今やろうとしたら変わっていることもあるかもしれません。
目次
- 背景
- 前提
- 1. レンタルサーバーにSSH接続できるように設定
- 2. レンタルサーバー上のPHPの拡張モジュールを確認
- 3. Composerのインストール
- 4. git clone
- 5. Composerを使ってアプリケーションで使うPHPライブラリをインストール
- 6. レンタルサーバー上のDBを作成
- 7. CakePHPのapp/config/app_local.phpを設定
- 8. CakePHPのMigrationコマンドを実行してDBテーブルを作成
- 9. レンタルサーバーのサイト設定のドキュメントルートがapp/webrootになるようにシンボリックリンクを調整
- この記事を書いて気付いたブログ機能の改善したいことメモ
背景
- Webアプリケーションを色々試せる環境が欲しい。特に仕事で使っているCakePHPを案件事情に影響されず使ってみたい。
- 試したことなどを記録する場所が欲しい。
- 仕事ではAWSを使用しているが、小規模の場合はレンタルサーバーでも可能では?と思っていたので試したい。
前提
- CakePHP4アプリケーションを作成済み。
- 上記アプリケーションのソースコード管理はGitHub。
- 作業PCはWindows。
- まずはサーバー費用は無料で始めたいので、レンタルサーバーのXREA Free(無料プラン)のアカウントを作成済み。
- 独自ドメインを使用したいので、事前に取得。ムームードメインを使用。
- 独自ドメインで仮のindex.htmlにアクセスできる状態まで構築済み。
1. レンタルサーバーにSSH接続できるように設定
レンタルサーバー側の設定
XREAの「新コントロールパネル」の「サイト設定」の「ツール/セキュリティー」の「SSH接続IP許可」を行う。
作業PC側
最初はTera Termを使ったのですが、後の方の作業でgitのSSH秘密鍵をエージェント転送で使いたくなり調べたところ、Tera Termの場合はputtygenとpageantも必要で手順が多かったので、別の方法を探しました。
GitBashを使うとWindowsPCでもMacのように少なめの手順でできることがわかり、そちらを使うようになりました。普段仕事でMacbookを使っているので、Mac同様だと自分にとってやりやすいです。
WindowsPCのGitBash上で、エージェント転送ありでSSH接続する手順:
$ # ssh-agentを開始する $ eval `ssh-agent` Agent pid 1693 $ # ssh-agentにSSH秘密鍵を追加する $ ssh-add ~/.ssh/id_ed25519 Enter passphrase for /c/Users/xxxxx/.ssh/id_ed25519: Identity added: /c/Users/xxxxx/.ssh/id_ed25519 (xxxxxx@xxxx.xxx) $ # エージェント転送あり(-Aオプション)でSSH接続する $ ssh xxxxxx@xxxx.xrea.com -A xxxxxx@xxxx.xrea.com's password: Last login: Sun Mar 3 22:10:06 2024 from xxx.xxx.xxx.xx [xxxxxx@xxxx ~]$
2. レンタルサーバー上のPHPの拡張モジュールを確認
レンタルサーバーにSSH接続し、使用しているシェルを確認する。bashになっていなかったらbashに切り替える。
最初にSSH接続した際はrbashだったが、この時はbashだった。
[xxxxxx@xxxx ~]$ echo $SHELL /bin/bash
PHPをCLIで実行したいため、まずPHPの実行パスを下記ページを見て確認する。
https://www.xrea.com/spec/#specCgi
次に、CakePHP4に必要なPHPの拡張モジュールが存在することをサーバー上で確認する。
必要な拡張モジュールは、CakePHP4のシステム要件を参照: https://book.cakephp.org/4/ja/installation.html#id2
[xxxxxx@xxxx ~]$ # まずPHPのCLIでの実行を試すために、バージョンを確認してみた。 [xxxxxx@xxxx ~]$ php82cli --version PHP 8.2.12 (cli) (built: Oct 24 2023 19:22:16) (NTS gcc x86_64) Copyright (c) The PHP Group Zend Engine v4.2.12, Copyright (c) Zend Technologies with Zend OPcache v8.2.12, Copyright (c), by Zend Technologies [xxxxxx@xxxx ~]$ [xxxxxx@xxxx ~]$ [xxxxxx@xxxx ~]$ # PHPの拡張モジュールを確認する。 [xxxxxx@xxxx ~]$ php82cli -m | grep -i mbstring mbstring [xxxxxx@xxxx ~]$ php82cli -m | grep -i intl intl [xxxxxx@xxxx ~]$ php82cli -m | grep -i simplexml SimpleXML [xxxxxx@xxxx ~]$ php82cli -m | grep -i pdo PDO pdo_mysql pdo_pgsql pdo_sqlite [xxxxxx@xxxx ~]$
3. Composerのインストール
参考: https://getcomposer.org/download/
[xxxxxx@xxxx ~]$ pwd /virtual/xxxxxx [xxxxxx@xxxx ~]$ [xxxxxx@xxxx ~]$ [xxxxxx@xxxx ~]$ ls -la total 67 drwx---r-x 6 xxxxxx hpusers 12 Feb 23 23:55 . drwx--x--x 1803 root root 1803 Feb 23 22:59 .. -rw------- 1 xxxxxx hpusers 80 Feb 18 00:00 .bash_history -rwx---r-x 1 xxxxxx hpusers 18 Aug 3 2022 .bash_logout -rwx---r-x 1 xxxxxx hpusers 141 Aug 3 2022 .bash_profile -rwx---r-x 1 xxxxxx hpusers 376 Aug 3 2022 .bashrc drwxr-xr-x 2 xxxxxx hpusers 3 Feb 23 21:24 _db_dump -rw------- 1 xxxxxx hpusers 45 Feb 23 23:55 .lesshst drwx---r-x 2 xxxxxx hpusers 2 Nov 9 2021 log drwxrwx--- 4 xxxxxx vchkpw 4 Feb 18 00:06 Maildir -rw-r--r-- 1 root root 0 Feb 17 18:24 .Maildir_time drwx---r-x 5 xxxxxx hpusers 6 Feb 18 12:41 public_html [xxxxxx@xxxx ~]$ [xxxxxx@xxxx ~]$ [xxxxxx@xxxx ~]$ php82cli -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" [xxxxxx@xxxx ~]$ [xxxxxx@xxxx ~]$ [xxxxxx@xxxx ~]$ ls -la total 94 drwx---r-x 6 xxxxxx hpusers 13 Feb 24 00:11 . drwx--x--x 1803 root root 1803 Feb 23 22:59 .. -rw------- 1 xxxxxx hpusers 80 Feb 18 00:00 .bash_history -rwx---r-x 1 xxxxxx hpusers 18 Aug 3 2022 .bash_logout -rwx---r-x 1 xxxxxx hpusers 141 Aug 3 2022 .bash_profile -rwx---r-x 1 xxxxxx hpusers 376 Aug 3 2022 .bashrc -rw-r--r-- 1 xxxxxx hpusers 58444 Feb 24 00:11 composer-setup.php drwxr-xr-x 2 xxxxxx hpusers 3 Feb 23 21:24 _db_dump -rw------- 1 xxxxxx hpusers 45 Feb 23 23:55 .lesshst drwx---r-x 2 xxxxxx hpusers 2 Nov 9 2021 log drwxrwx--- 4 xxxxxx vchkpw 4 Feb 18 00:06 Maildir -rw-r--r-- 1 root root 0 Feb 17 18:24 .Maildir_time drwx---r-x 5 xxxxxx hpusers 6 Feb 18 12:41 public_html [xxxxxx@xxxx ~]$ [xxxxxx@xxxx ~]$ [xxxxxx@xxxx ~]$ php82cli -r "if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" Installer verified [xxxxxx@xxxx ~]$ [xxxxxx@xxxx ~]$ [xxxxxx@xxxx ~]$ php82cli composer-setup.php All settings correct for using Composer Downloading... Composer (version 2.7.1) successfully installed to: /virtual/xxxxxx/composer.phar Use it: php composer.phar [xxxxxx@xxxx ~]$ [xxxxxx@xxxx ~]$ [xxxxxx@xxxx ~]$ php82cli -r "unlink('composer-setup.php');" [xxxxxx@xxxx ~]$ [xxxxxx@xxxx ~]$ [xxxxxx@xxxx ~]$ ls -la total 1227 drwx---r-x 7 xxxxxx hpusers 14 Feb 24 00:14 . drwx--x--x 1803 root root 1803 Feb 23 22:59 .. -rw------- 1 xxxxxx hpusers 80 Feb 18 00:00 .bash_history -rwx---r-x 1 xxxxxx hpusers 18 Aug 3 2022 .bash_logout -rwx---r-x 1 xxxxxx hpusers 141 Aug 3 2022 .bash_profile -rwx---r-x 1 xxxxxx hpusers 376 Aug 3 2022 .bashrc -rwxr-xr-x 1 xxxxxx hpusers 2975214 Feb 24 00:13 composer.phar drwxr-xr-x 3 xxxxxx hpusers 3 Feb 24 00:13 .config drwxr-xr-x 2 xxxxxx hpusers 3 Feb 23 21:24 _db_dump -rw------- 1 xxxxxx hpusers 45 Feb 23 23:55 .lesshst drwx---r-x 2 xxxxxx hpusers 2 Nov 9 2021 log drwxrwx--- 4 xxxxxx vchkpw 4 Feb 18 00:06 Maildir -rw-r--r-- 1 root root 0 Feb 17 18:24 .Maildir_time drwx---r-x 5 xxxxxx hpusers 6 Feb 18 12:41 public_html [xxxxxx@xxxx ~]$ [xxxxxx@xxxx ~]$ [xxxxxx@xxxx ~]$ php82cli ~/composer.phar --version Composer version 2.7.1 2024-02-09 15:26:28 [xxxxxx@xxxx ~]$
4. git clone
[xxxxxx@xxxx ~]$ # GitHubへの接続確認 [xxxxxx@xxxx ~]$ ssh -T git@github.com Hi xxxxxx! You've successfully authenticated, but GitHub does not provide shell access. [xxxxxx@xxxx ~]$ [xxxxxx@xxxx ~]$ [xxxxxx@xxxx ~]$ pwd /virtual/xxxxxx [xxxxxx@xxxx ~]$ [xxxxxx@xxxx ~]$ [xxxxxx@xxxx ~]$ ls -l total 1163 -rwxr-xr-x 1 xxxxxx hpusers 2975214 Feb 24 00:13 composer.phar drwxr-xr-x 2 xxxxxx hpusers 3 Feb 23 21:24 _db_dump drwx---r-x 2 xxxxxx hpusers 2 Nov 9 2021 log drwxrwx--- 4 xxxxxx vchkpw 4 Feb 18 00:06 Maildir drwx---r-x 5 xxxxxx hpusers 6 Feb 18 12:41 public_html [xxxxxx@xxxx ~]$ [xxxxxx@xxxx ~]$ [xxxxxx@xxxx ~]$ git clone git@github.com:xxxxxx/cms.git Cloning into 'cms'... Enter passphrase for key '/virtual/xxxxxx/.ssh/id_ed25519': remote: Enumerating objects: 409, done. remote: Counting objects: 100% (409/409), done. remote: Compressing objects: 100% (216/216), done. remote: Total 409 (delta 160), reused 409 (delta 160), pack-reused 0 Receiving objects: 100% (409/409), 322.41 KiB | 722.00 KiB/s, done. Resolving deltas: 100% (160/160), done. [xxxxxx@xxxx ~]$ [xxxxxx@xxxx ~]$ ls -l total 1164 drwxr-xr-x 5 xxxxxx hpusers 7 Feb 24 00:58 cms -rwxr-xr-x 1 xxxxxx hpusers 2975214 Feb 24 00:13 composer.phar drwxr-xr-x 2 xxxxxx hpusers 3 Feb 23 21:24 _db_dump drwx---r-x 2 xxxxxx hpusers 2 Nov 9 2021 log drwxrwx--- 4 xxxxxx vchkpw 4 Feb 18 00:06 Maildir drwx---r-x 5 xxxxxx hpusers 6 Feb 18 12:41 public_html [xxxxxx@xxxx ~]$
5. Composerを使ってアプリケーションで使うPHPライブラリをインストール
最初、--no-devオプションを付けずに実行してしまい、あとから気づいて--no-devオプション付きで実行しました…。
[xxxxxx@xxxx ~]$ cd cms [xxxxxx@xxxx cms]$ [xxxxxx@xxxx cms]$ [xxxxxx@xxxx cms]$ ls -l total 4 drwxr-xr-x 11 xxxxxx hpusers 22 Feb 24 00:58 app drwxr-xr-x 4 xxxxxx hpusers 4 Feb 24 00:58 docker -rw-r--r-- 1 xxxxxx hpusers 880 Feb 24 00:58 docker-compose.yml -rw-r--r-- 1 xxxxxx hpusers 6 Feb 24 00:58 README.md [xxxxxx@xxxx cms]$ [xxxxxx@xxxx cms]$ [xxxxxx@xxxx cms]$ cd app [xxxxxx@xxxx app]$ [xxxxxx@xxxx app]$ [xxxxxx@xxxx app]$ ls -l total 59 drwxr-xr-x 2 xxxxxx hpusers 6 Feb 24 00:58 bin -rw-r--r-- 1 xxxxxx hpusers 2182 Feb 24 00:58 composer.json -rw-r--r-- 1 xxxxxx hpusers 216051 Feb 24 00:58 composer.lock drwxr-xr-x 4 xxxxxx hpusers 12 Feb 24 00:58 config -rw-r--r-- 1 xxxxxx hpusers 649 Feb 24 00:58 index.php -rw-r--r-- 1 xxxxxx hpusers 160 Feb 24 00:58 phpcs.xml -rw-r--r-- 1 xxxxxx hpusers 183 Feb 24 00:58 phpstan.neon -rw-r--r-- 1 xxxxxx hpusers 1029 Feb 24 00:58 phpunit.xml.dist drwxr-xr-x 2 xxxxxx hpusers 3 Feb 24 00:58 plugins -rw-r--r-- 1 xxxxxx hpusers 1878 Feb 24 00:58 README.md drwxr-xr-x 2 xxxxxx hpusers 3 Feb 24 00:58 resources drwxr-xr-x 8 xxxxxx hpusers 9 Feb 24 00:58 src drwxr-xr-x 10 xxxxxx hpusers 10 Feb 24 00:58 templates drwxr-xr-x 4 xxxxxx hpusers 6 Feb 24 00:58 tests drwxr-xr-x 6 xxxxxx hpusers 9 Feb 24 00:58 webroot [xxxxxx@xxxx app]$ [xxxxxx@xxxx app]$ [xxxxxx@xxxx app]$ php82cli ~/composer.phar install Installing dependencies from lock file (including require-dev) Verifying lock file contents can be installed on current platform. Package operations: 89 installs, 0 updates, 0 removals - Downloading cakephp/plugin-installer (1.3.1) - Downloading squizlabs/php_codesniffer (3.7.2) - Downloading dealerdirect/phpcodesniffer-composer-installer (v1.0.0) - Downloading psr/http-message (1.1) - Downloading psr/http-server-handler (1.0.2) - Downloading psr/http-server-middleware (1.0.2) - Downloading psr/http-client (1.0.2) - Downloading psr/http-factory (1.0.2) - Downloading laminas/laminas-diactoros (2.25.1) - Downloading psr/simple-cache (2.0.0) - Downloading psr/log (2.0.0) - Downloading psr/container (2.0.2) - Downloading league/container (4.2.0) - Downloading laminas/laminas-httphandlerrunner (2.6.0) - Downloading symfony/polyfill-mbstring (v1.27.0) - Downloading composer/ca-bundle (1.3.5) - Downloading cakephp/chronos (2.3.2) - Downloading cakephp/cakephp (4.4.18) - Downloading cakephp/authentication (2.10.2) - Downloading nikic/php-parser (v4.15.4) - Downloading symfony/polyfill-ctype (v1.27.0) - Downloading twig/twig (v3.5.1) - Downloading twig/markdown-extra (v3.5.1) - Downloading jasny/twig-extensions (v1.3.0) - Downloading cakephp/twig-view (1.3.0) - Downloading brick/varexporter (0.3.8) - Downloading cakephp/bake (2.9.3) - Downloading phpstan/phpdoc-parser (1.18.1) - Downloading slevomat/coding-standard (8.10.0) - Downloading cakephp/cakephp-codesniffer (4.7.0) - Downloading jdorn/sql-formatter (v1.2.17) - Downloading symfony/process (v6.2.8) - Downloading symfony/polyfill-php81 (v1.27.0) - Downloading symfony/polyfill-php80 (v1.27.0) - Downloading symfony/polyfill-php73 (v1.27.0) - Downloading symfony/finder (v6.2.7) - Downloading symfony/filesystem (v6.2.7) - Downloading symfony/polyfill-intl-normalizer (v1.27.0) - Downloading symfony/polyfill-intl-grapheme (v1.27.0) - Downloading symfony/string (v6.2.8) - Downloading symfony/service-contracts (v3.2.1) - Downloading symfony/deprecation-contracts (v3.2.1) - Downloading symfony/console (v6.2.8) - Downloading seld/signal-handler (2.0.1) - Downloading seld/phar-utils (1.2.1) - Downloading seld/jsonlint (1.9.0) - Downloading react/promise (v2.9.0) - Downloading justinrainbow/json-schema (5.2.12) - Downloading composer/pcre (3.1.0) - Downloading composer/xdebug-handler (3.0.3) - Downloading composer/spdx-licenses (1.5.7) - Downloading composer/semver (3.3.2) - Downloading composer/metadata-minifier (1.0.0) - Downloading composer/class-map-generator (1.0.0) - Downloading composer/composer (2.5.5) - Downloading cakephp/debug_kit (4.9.3) - Downloading symfony/config (v6.2.7) - Downloading robmorgan/phinx (0.13.4) - Downloading cakephp/migrations (3.8.0) - Downloading m1/env (2.2.0) - Downloading josegonzalez/dotenv (3.2.0) - Downloading mobiledetect/mobiledetectlib (2.8.41) - Downloading sebastian/version (3.0.2) - Downloading sebastian/type (3.2.1) - Downloading sebastian/resource-operations (3.0.3) - Downloading sebastian/recursion-context (4.0.5) - Downloading sebastian/object-reflector (2.0.4) - Downloading sebastian/object-enumerator (4.0.4) - Downloading sebastian/global-state (5.0.5) - Downloading sebastian/exporter (4.0.5) - Downloading sebastian/environment (5.1.5) - Downloading sebastian/diff (4.0.4) - Downloading sebastian/comparator (4.0.8) - Downloading sebastian/code-unit (1.0.8) - Downloading sebastian/cli-parser (1.0.1) - Downloading phpunit/php-timer (5.0.3) - Downloading phpunit/php-text-template (2.0.4) - Downloading phpunit/php-invoker (3.1.1) - Downloading phpunit/php-file-iterator (3.0.6) - Downloading theseer/tokenizer (1.2.1) - Downloading sebastian/lines-of-code (1.0.3) - Downloading sebastian/complexity (2.0.2) - Downloading sebastian/code-unit-reverse-lookup (2.0.3) - Downloading phpunit/php-code-coverage (9.2.26) - Downloading phar-io/version (3.2.1) - Downloading phar-io/manifest (2.0.3) - Downloading myclabs/deep-copy (1.11.1) - Downloading doctrine/instantiator (2.0.0) - Downloading phpunit/phpunit (9.6.7) - Installing cakephp/plugin-installer (1.3.1): Extracting archive - Installing squizlabs/php_codesniffer (3.7.2): Extracting archive - Installing dealerdirect/phpcodesniffer-composer-installer (v1.0.0): Extracting archive - Installing psr/http-message (1.1): 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-client (1.0.2): Extracting archive - Installing psr/http-factory (1.0.2): Extracting archive - Installing laminas/laminas-diactoros (2.25.1): Extracting archive - Installing psr/simple-cache (2.0.0): Extracting archive - Installing psr/log (2.0.0): Extracting archive - Installing psr/container (2.0.2): Extracting archive - Installing league/container (4.2.0): Extracting archive - Installing laminas/laminas-httphandlerrunner (2.6.0): Extracting archive - Installing symfony/polyfill-mbstring (v1.27.0): Extracting archive - Installing composer/ca-bundle (1.3.5): Extracting archive - Installing cakephp/chronos (2.3.2): Extracting archive - Installing cakephp/cakephp (4.4.18): Extracting archive - Installing cakephp/authentication (2.10.2): Extracting archive - Installing nikic/php-parser (v4.15.4): Extracting archive - Installing symfony/polyfill-ctype (v1.27.0): Extracting archive - Installing twig/twig (v3.5.1): Extracting archive - Installing twig/markdown-extra (v3.5.1): Extracting archive - Installing jasny/twig-extensions (v1.3.0): Extracting archive - Installing cakephp/twig-view (1.3.0): Extracting archive - Installing brick/varexporter (0.3.8): Extracting archive - Installing cakephp/bake (2.9.3): Extracting archive - Installing phpstan/phpdoc-parser (1.18.1): Extracting archive - Installing slevomat/coding-standard (8.10.0): Extracting archive - Installing cakephp/cakephp-codesniffer (4.7.0): Extracting archive - Installing jdorn/sql-formatter (v1.2.17): Extracting archive - Installing symfony/process (v6.2.8): Extracting archive - Installing symfony/polyfill-php81 (v1.27.0): Extracting archive - Installing symfony/polyfill-php80 (v1.27.0): Extracting archive - Installing symfony/polyfill-php73 (v1.27.0): Extracting archive - Installing symfony/finder (v6.2.7): Extracting archive - Installing symfony/filesystem (v6.2.7): Extracting archive - Installing symfony/polyfill-intl-normalizer (v1.27.0): Extracting archive - Installing symfony/polyfill-intl-grapheme (v1.27.0): Extracting archive - Installing symfony/string (v6.2.8): Extracting archive - Installing symfony/service-contracts (v3.2.1): Extracting archive - Installing symfony/deprecation-contracts (v3.2.1): Extracting archive - Installing symfony/console (v6.2.8): Extracting archive - Installing seld/signal-handler (2.0.1): Extracting archive - Installing seld/phar-utils (1.2.1): Extracting archive - Installing seld/jsonlint (1.9.0): Extracting archive - Installing react/promise (v2.9.0): Extracting archive - Installing justinrainbow/json-schema (5.2.12): Extracting archive - Installing composer/pcre (3.1.0): Extracting archive - Installing composer/xdebug-handler (3.0.3): Extracting archive - Installing composer/spdx-licenses (1.5.7): Extracting archive - Installing composer/semver (3.3.2): Extracting archive - Installing composer/metadata-minifier (1.0.0): Extracting archive - Installing composer/class-map-generator (1.0.0): Extracting archive - Installing composer/composer (2.5.5): Extracting archive - Installing cakephp/debug_kit (4.9.3): Extracting archive - Installing symfony/config (v6.2.7): Extracting archive - Installing robmorgan/phinx (0.13.4): Extracting archive - Installing cakephp/migrations (3.8.0): Extracting archive - Installing m1/env (2.2.0): Extracting archive - Installing josegonzalez/dotenv (3.2.0): Extracting archive - Installing mobiledetect/mobiledetectlib (2.8.41): Extracting archive - Installing sebastian/version (3.0.2): Extracting archive - Installing sebastian/type (3.2.1): Extracting archive - Installing sebastian/resource-operations (3.0.3): Extracting archive - Installing sebastian/recursion-context (4.0.5): Extracting archive - Installing sebastian/object-reflector (2.0.4): Extracting archive - Installing sebastian/object-enumerator (4.0.4): Extracting archive - Installing sebastian/global-state (5.0.5): Extracting archive - Installing sebastian/exporter (4.0.5): Extracting archive - Installing sebastian/environment (5.1.5): Extracting archive - Installing sebastian/diff (4.0.4): Extracting archive - Installing sebastian/comparator (4.0.8): Extracting archive - Installing sebastian/code-unit (1.0.8): Extracting archive - Installing sebastian/cli-parser (1.0.1): Extracting archive - Installing phpunit/php-timer (5.0.3): Extracting archive - Installing phpunit/php-text-template (2.0.4): Extracting archive - Installing phpunit/php-invoker (3.1.1): Extracting archive - Installing phpunit/php-file-iterator (3.0.6): Extracting archive - Installing theseer/tokenizer (1.2.1): Extracting archive - Installing sebastian/lines-of-code (1.0.3): Extracting archive - Installing sebastian/complexity (2.0.2): Extracting archive - Installing sebastian/code-unit-reverse-lookup (2.0.3): Extracting archive - Installing phpunit/php-code-coverage (9.2.26): 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 doctrine/instantiator (2.0.0): Extracting archive - Installing phpunit/phpunit (9.6.7): Extracting archive 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 > App\Console\Installer::postInstall Created `config/app_local.php` file Created `/virtual/xxxxxx/cms/app/logs` directory Created `/virtual/xxxxxx/cms/app/tmp` directory Created `/virtual/xxxxxx/cms/app/tmp/cache` directory Created `/virtual/xxxxxx/cms/app/tmp/cache/models` directory Created `/virtual/xxxxxx/cms/app/tmp/cache/persistent` directory Created `/virtual/xxxxxx/cms/app/tmp/cache/views` directory Created `/virtual/xxxxxx/cms/app/tmp/sessions` directory Created `/virtual/xxxxxx/cms/app/tmp/tests` directory Set Folder Permissions ? (Default to Y) [Y,n]? Y Permissions set on /virtual/xxxxxx/cms/app/tmp/cache Permissions set on /virtual/xxxxxx/cms/app/tmp/cache/models Permissions set on /virtual/xxxxxx/cms/app/tmp/cache/persistent Permissions set on /virtual/xxxxxx/cms/app/tmp/cache/views Permissions set on /virtual/xxxxxx/cms/app/tmp/sessions Permissions set on /virtual/xxxxxx/cms/app/tmp/tests Permissions set on /virtual/xxxxxx/cms/app/tmp Permissions set on /virtual/xxxxxx/cms/app/logs Updated Security.salt value in config/app_local.php [xxxxxx@xxxx app]$ [xxxxxx@xxxx app]$ [xxxxxx@xxxx app]$ php82cli ~/composer.phar install --no-dev Installing dependencies from lock file Verifying lock file contents can be installed on current platform. Package operations: 0 installs, 0 updates, 60 removals - Removing twig/twig (v3.5.1) - Removing twig/markdown-extra (v3.5.1) - Removing theseer/tokenizer (1.2.1) - Removing symfony/process (v6.2.8) - Removing symfony/polyfill-php81 (v1.27.0) - Removing symfony/polyfill-php80 (v1.27.0) - Removing symfony/polyfill-php73 (v1.27.0) - Removing symfony/finder (v6.2.7) - Removing squizlabs/php_codesniffer (3.7.2) - Removing slevomat/coding-standard (8.10.0) - Removing seld/signal-handler (2.0.1) - Removing seld/phar-utils (1.2.1) - Removing seld/jsonlint (1.9.0) - Removing sebastian/version (3.0.2) - Removing sebastian/type (3.2.1) - Removing sebastian/resource-operations (3.0.3) - Removing sebastian/recursion-context (4.0.5) - Removing sebastian/object-reflector (2.0.4) - Removing sebastian/object-enumerator (4.0.4) - Removing sebastian/lines-of-code (1.0.3) - Removing sebastian/global-state (5.0.5) - Removing sebastian/exporter (4.0.5) - Removing sebastian/environment (5.1.5) - Removing sebastian/diff (4.0.4) - Removing sebastian/complexity (2.0.2) - Removing sebastian/comparator (4.0.8) - Removing sebastian/code-unit-reverse-lookup (2.0.3) - Removing sebastian/code-unit (1.0.8) - Removing sebastian/cli-parser (1.0.1) - Removing react/promise (v2.9.0) - Removing phpunit/phpunit (9.6.7) - Removing phpunit/php-timer (5.0.3) - Removing phpunit/php-text-template (2.0.4) - Removing phpunit/php-invoker (3.1.1) - Removing phpunit/php-file-iterator (3.0.6) - Removing phpunit/php-code-coverage (9.2.26) - Removing phpstan/phpdoc-parser (1.18.1) - Removing phar-io/version (3.2.1) - Removing phar-io/manifest (2.0.3) - Removing nikic/php-parser (v4.15.4) - Removing myclabs/deep-copy (1.11.1) - Removing m1/env (2.2.0) - Removing justinrainbow/json-schema (5.2.12) - Removing josegonzalez/dotenv (3.2.0) - Removing jdorn/sql-formatter (v1.2.17) - Removing jasny/twig-extensions (v1.3.0) - Removing doctrine/instantiator (2.0.0) - Removing dealerdirect/phpcodesniffer-composer-installer (v1.0.0) - Removing composer/xdebug-handler (3.0.3) - Removing composer/spdx-licenses (1.5.7) - Removing composer/semver (3.3.2) - Removing composer/pcre (3.1.0) - Removing composer/metadata-minifier (1.0.0) - Removing composer/composer (2.5.5) - Removing composer/class-map-generator (1.0.0) - Removing cakephp/twig-view (1.3.0) - Removing cakephp/debug_kit (4.9.3) - Removing cakephp/cakephp-codesniffer (4.7.0) - Removing cakephp/bake (2.9.3) - Removing brick/varexporter (0.3.8) Generating autoload files 14 packages you are using are looking for funding. Use the `composer fund` command to find out more! > App\Console\Installer::postInstall Set Folder Permissions ? (Default to Y) [Y,n]? Y No Security.salt placeholder to replace. [xxxxxx@xxxx app]$
6. レンタルサーバー上のDBを作成
XREAの「新コントロールパネル」でデータベースを作成する。
マニュアル: https://help.xrea.com/manual/database-create/
7. CakePHPのapp/config/app_local.phpを設定
サーバー上でviで書き換えました。
ちなみに、仕事では古いプロジェクトでは.envファイルを使っている場合があったので、いつから.envファイルが非推奨になったのかなと調べてみたところ、以下のようなPRがありました。
https://github.com/cakephp/app/pull/636
8. CakePHPのMigrationコマンドを実行してDBテーブルを作成
後から気づいたのですが、--no-lockオプションを付け忘れていました。次から付けます。
参考: https://book.cakephp.org/migrations/3/ja/index.html#schema-lock
[xxxxxx@xxxx app]$ php82cli bin/cake.php migrations status using migration paths - /virtual/xxxxxx/cms/app/config/Migrations using seed paths using environment default Status Migration ID Migration Name ----------------------------------------- down 20230503065104 CreateArticles [xxxxxx@xxxx app]$ [xxxxxx@xxxx app]$ [xxxxxx@xxxx app]$ php82cli bin/cake.php migrations migrate using migration paths - /virtual/xxxxxx/cms/app/config/Migrations using seed paths using environment default using adapter mysql using database xxxxxx ordering by creation time == 20230503065104 CreateArticles: migrating == 20230503065104 CreateArticles: migrated 0.0138s All Done. Took 0.0154s Dumps the current schema of the database to be used while baking a diff using migration paths - /virtual/xxxxxx/cms/app/config/Migrations using seed paths Writing dump file `/virtual/xxxxxx/cms/app/config/Migrations/schema-dump-default.lock`... Dump file `/virtual/xxxxxx/cms/app/config/Migrations/schema-dump-default.lock` was successfully written [xxxxxx@xxxx app]$ [xxxxxx@xxxx app]$ [xxxxxx@xxxx app]$ php82cli bin/cake.php migrations status using migration paths - /virtual/xxxxxx/cms/app/config/Migrations using seed paths using environment default Status Migration ID Migration Name ----------------------------------------- up 20230503065104 CreateArticles [xxxxxx@xxxx app]$
9. レンタルサーバーのサイト設定のドキュメントルートがapp/webrootになるようにシンボリックリンクを調整
XREAの「新コントロールパネル」の「サイト設定」を追加することでWebサイトを公開できるのですが、同期設定をしない場合はディレクトリが作成され、同期設定をする場合はシンボリックリンクが作成されます。
CakePHPアプリケーションのwebrootディレクトリだけを公開したかったのですが、自動作成されたシンボリックリンクをそのまま変更して大丈夫かどうかは不安だったので、シンボリックリンクの先をさらにシンボリックリンクにしてみました。
これでCakePHPアプリケーションを公開できました。
[xxxxxx@xxxx public_html]$ ls -la total 9 drwx---r-x 6 xxxxxx hpusers 8 Feb 24 03:38 . drwx---r-x 11 xxxxxx hpusers 19 Feb 24 00:58 .. drwx---r-x 2 xxxxxx hpusers 41 Feb 17 18:24 .fast-cgi-bin -rw-r--r-- 1 xxxxxx hpusers 128 Feb 17 20:09 index.html lrwxrwxrwx 1 xxxxxx hpusers 7 Feb 24 03:38 kgssys.net -> webroot drwx---r-x 2 xxxxxx hpusers 2 Feb 17 18:24 xxxxxx.shop drwx---r-x 5 xxxxxx hpusers 15 Feb 23 21:26 log drwx---r-x 2 xxxxxx hpusers 2 Feb 24 03:38 webroot [xxxxxx@xxxx public_html]$ [xxxxxx@xxxx public_html]$ [xxxxxx@xxxx public_html]$ [xxxxxx@xxxx public_html]$ ls -la webroot/ total 2 drwx---r-x 2 xxxxxx hpusers 2 Feb 24 03:38 . drwx---r-x 6 xxxxxx hpusers 8 Feb 24 03:38 .. [xxxxxx@xxxx public_html]$ [xxxxxx@xxxx public_html]$ [xxxxxx@xxxx public_html]$ rmdir webroot [xxxxxx@xxxx public_html]$ [xxxxxx@xxxx public_html]$ [xxxxxx@xxxx public_html]$ ls -la total 8 drwx---r-x 5 xxxxxx hpusers 7 Feb 24 03:39 . drwx---r-x 11 xxxxxx hpusers 19 Feb 24 00:58 .. drwx---r-x 2 xxxxxx hpusers 41 Feb 17 18:24 .fast-cgi-bin -rw-r--r-- 1 xxxxxx hpusers 128 Feb 17 20:09 index.html lrwxrwxrwx 1 xxxxxx hpusers 7 Feb 24 03:38 xxxxxx.net -> webroot drwx---r-x 2 xxxxxx hpusers 2 Feb 17 18:24 xxxxxx.shop drwx---r-x 5 xxxxxx hpusers 15 Feb 23 21:26 log [xxxxxx@xxxx public_html]$ [xxxxxx@xxxx public_html]$ [xxxxxx@xxxx public_html]$ ln -s ../cms/app/webroot webroot [xxxxxx@xxxx public_html]$ [xxxxxx@xxxx public_html]$ [xxxxxx@xxxx public_html]$ ls -la total 9 drwx---r-x 5 xxxxxx hpusers 8 Feb 24 03:39 . drwx---r-x 11 xxxxxx hpusers 19 Feb 24 00:58 .. drwx---r-x 2 xxxxxx hpusers 41 Feb 17 18:24 .fast-cgi-bin -rw-r--r-- 1 xxxxxx hpusers 128 Feb 17 20:09 index.html lrwxrwxrwx 1 xxxxxx hpusers 7 Feb 24 03:38 xxxxxx.net -> webroot drwx---r-x 2 xxxxxx hpusers 2 Feb 17 18:24 xxxxxx.shop drwx---r-x 5 xxxxxx hpusers 15 Feb 23 21:26 log lrwxrwxrwx 1 xxxxxx hpusers 18 Feb 24 03:39 webroot -> ../cms/app/webroot [xxxxxx@xxxx public_html]$
この記事を書いて気付いたブログ機能の改善したいことメモ
-
編集画面の認証セッションの有効期限を長くしたい。
- 一旦デフォルト設定(24分)にしていたが、長文を書く場合は有効期限を超える場合が多いことに気付いたため。
-
記事の編集画面の本文のテキストエリアの初期表示行数をもっと増やしておきたい。
- テキストエリアの右下をつかんで引っ張ることで大きくすることは可能だが、毎回それをやるのが面倒なので。
-
記事の編集画面で保存した後は、再度記事の編集画面を表示したい。
- 長文を書く場合、一旦保存したあとに編集を続けたい場合の方が多いな、と気付いたため。
- なお、今回はローカル開発環境で記事作成したものをコピーしてレンタルサーバー上の環境で保存したので、このやり方であれば不完全な編集画面でもどうにかなりそうです。