-------------------------------------------------------------------------------- CakePHP4開発環境構築 -------------------------------------------------------------------------------- ・前処理 ・用意するもの CentOS-8.2.2004-x86_64-dvd1.iso -------------------------------------------------------------------------------- ・Oracle VM VirtualBox マネージャ で 新規作成 ・名前 cake01 ・タイプ Linux ・バージョン Other Linux (64bit) ・メモリサイズ 1024MB ・仮想ハードディスクを作成する ・ハードディスクのファイルタイプ: VDI(VirtualBox Disk Image) ・物理ハードディスクにあるストレージ: 可変サイズ ・ファイルの場所とサイズ: cake01, 80GB ・[作成] -------------------------------------------------------------------------------- ・ストレージ ・CentOS-8.2.2004-x86_64-dvd1.iso ・ネットワーク ・固定IPの場合 ・[設定(S)] - ネットワーク(固定IP) ・ブリッジ・アダプタ ・[OK] ・DHCPの場合 ・[設定(S)] - ネットワーク(Local Only) ・NAT ・Host Only ・[OK] -------------------------------------------------------------------------------- ・インストール ・起動(T) ・Install CentOS 8 ・Language: English (United States) ・DATE & TIME: Asia Tokyo ・KEYBOARD: Japanese ・SOFTWARE SELECTION: Minimal Install; ・KDUMP: disabled ・NETWORK & HOST ; Ethernet = ON; cake01.mydomain ・[Begin Installation] ・ROOT PASSWORD ・USER CREATION // <-- devusr ・(処理終了を待つ) ・Reboot ・ネットワーク設定 ・DHCPの場合(Local Only の場合) /etc/sysconfig/network-scripts/ifcfg-enp0s8 ONBOOT=yes ・固定IPの場合 $ su - # cd /etc/sysconfig/network-scripts # cp ifcfg-enp0s3 _ifcfg-enp0s3_org # vi ifcfg-enp0s3 # diff _ifcfg-enp0s3_org ifcfg-enp0s3 < BOOTPROTO="dhcp" --- > BOOTPROTO="static" > IPADDR="192.168.3.223" > NETMASK="255.255.255.0" > GATEWAY="192.168.3.1" # # vi /etc/resolv.conf # cat /etc/resolv.conf nameserver 192.168.3.1 # ・SELinuxを無効にする。 # vi /etc/selinux/config SELINUX=disabled ・Reboot # shutdown -r now -------------------------------------------------------------------------------- ・以降、client端末からsshでログインし、処理します。 -------------------------------------------------------------------------------- # yum -y update ### ### reboot ### # shutdown -r now # yum -y install epel-release https://rpms.remirepo.net/enterprise/remi-release-8.rpm; \ yum config-manager --set-enabled PowerTools # yum -y install tar wget net-tools gcc make zip unzip emacs nkf git # yum -y install mariadb mariadb-server mariadb-devel # systemctl enable mariadb.service; \ systemctl start mariadb.service # mysql -u root -p パスワード入力はCR(Enter)だけ。 MariaDB [(none)]> set password for 'root'@'localhost' = password('...password...'); MariaDB [(none)]> create database devdb character set utf8; MariaDB [(none)]> create user 'devusr'@'localhost' identified by '...password...'; MariaDB [(none)]> grant all privileges on devdb.* to 'devusr'@'localhost'; MariaDB [(none)]> exit # yum -y module install php:remi-7.4 # yum -y install zlib-devel curl-devel openssl-devel \ httpd-devel apr-devel apr-util-devel libffi-devel # yum -y install php-bcmath php-dba php-dbg \ php-embedded php-enchant php-gd php-gmp php-intl php-ldap \ php-mysqlnd php-odbc php-opcache php-pdo php-pgsql \ php-process php-recode php-snmp php-soap php-xmlrpc php-zip # systemctl enable httpd; \ systemctl start httpd # firewall-cmd --permanent --add-service=http; \ firewall-cmd --permanent --add-service=https; \ firewall-cmd --reload # cd /etc # cp php.ini ~/php.ini # vi php.ini # diff ~/php.ini php.ini 588a589 > error_log = /var/log/php_error.log 923a925 > date.timezone = Asia/Tokyo 1017c1019 < pdo_mysql.default_socket= --- > pdo_mysql.default_socket=/var/lib/mysql/mysql.sock # touch /var/log/php_error.log; \ chown apache:apache /var/log/php_error.log; \ chmod 666 /var/log/php_error.log # cd /etc/httpd/conf # cp httpd.conf ~/httpd.conf # vi httpd.conf # diff ~/httpd.conf httpd.conf 106c106 < AllowOverride none --- > AllowOverride All 128c128 < AllowOverride None --- > AllowOverride All 154c154 < AllowOverride None --- > AllowOverride FileInfo 167c167 < DirectoryIndex index.html --- > DirectoryIndex index.php index.html # # systemctl restart httpd ### ### npm ### # yum -y install npm ### ### Image Magick ### # yum -y install ImageMagick ImageMagick-devel ### ### composer ### # cd /usr/local/bin # curl -sS https://getcomposer.org/installer | php ### ### sh.local ### # vi /etc/profile.d/sh.local # cat /etc/profile.d/sh.local <<< #Add any required envvar overrides to this file, it is sourced from /etc/profile alias composer='php /usr/local/bin/composer.phar' alias ls='ls' alias ll='ls -la' alias e='emacs' alias delb='rm -f *~ .??*~' >>> ### ### .emacs ### # cd # vi .emacs # cat .emacs <<< (setq-default tab-width 4 indent-tabs-mode nil) (add-hook 'php-mode-hook (lambda () (setq tab-width 4) (setq c-basic-offset 4))) >>> ### ### https://book.cakephp.org/4/en/index.html ### https://book.cakephp.org/4/en/quickstart.html ### # cd # cp .emacs /home/devusr # chown devusr:devusr /home/devusr/.emacs # su - devusr $ composer create-project --prefer-dist cakephp/app:4.* html $ exit # rm -Rf /var/www/html # mv /home/devusr/html /var/www/html; \ chown -R devusr:devusr /var/www/html; \ chown -R apache:apache /var/www/html/tmp; \ chown -R apache:apache /var/www/html/logs # su - devusr $ cd /var/www/html/config $ cp app_local.php ~/app_local.php $ vi app_local.php $ diff ~/app_local.php app_local.php 47,48c47,48 < 'username' => 'my_app', < 'password' => 'secret', --- > 'username' => 'devusr', > 'password' => '...password...', 50c50 < 'database' => 'my_app', --- > 'database' => 'devdb', $ exit # exit ### ### Check by WEB browser. http://...対象HOST... ### だいたい、以下のような感じであったらOK。 <<< ... ... ... Environment Your version of PHP is 7.2.0 or higher (detected 7.4.9). Your version of PHP has the mbstring extension loaded. Your version of PHP has the openssl extension loaded. Your version of PHP has the intl extension loaded. Filesystem Your tmp directory is writable. Your logs directory is writable. The Cake\Cache\Engine\FileEngineEngine is being used for core caching. To change the config edit config/app.php Database CakePHP is able to connect to the database. DebugKit DebugKit is loaded. ... ... ... >>> ### ### Sample DB ### devusrでログイン。 ssh devusr@...host-IP-address... $ vi sample.sql $ cat sample.sql USE devdb; CREATE TABLE users ( id INT AUTO_INCREMENT PRIMARY KEY, email VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, created DATETIME, modified DATETIME ); INSERT INTO users (email, password, created, modified) VALUES ('cakephp@example.com', 'secret', NOW(), NOW()); $ $ mysql -u devusr -p devdb MariaDB [devdb]> \. sample.sql MariaDB [devdb]> select * from users; +----+---------------------+----------+---------------------+---------------------+ | id | email | password | created | modified | +----+---------------------+----------+---------------------+---------------------+ | 1 | cakephp@example.com | secret | 2020-10-06 16:09:48 | 2020-10-06 16:09:48 | +----+---------------------+----------+---------------------+---------------------+ 1 row in set (0.000 sec) MariaDB [devdb]> \q Bye $ ### ### CakePHP bake ### $ cd /var/www/html $ bin/cake bake all users $ find /var/www/html -type f -newer ~/sample.sql -print /var/www/html/src/Controller/UsersController.php /var/www/html/src/Model/Entity/User.php /var/www/html/src/Model/Table/UsersTable.php /var/www/html/templates/Users/index.php /var/www/html/templates/Users/view.php /var/www/html/templates/Users/add.php /var/www/html/templates/Users/edit.php /var/www/html/tests/TestCase/Controller/UsersControllerTest.php /var/www/html/tests/TestCase/Model/Table/UsersTableTest.php /var/www/html/tests/Fixture/UsersFixture.php /var/www/html/tmp/cache/models/myapp_cake_model_default_users /var/www/html/tmp/cache/models/myapp_cake_model_default_articles /var/www/html/tmp/cache/models/myapp_cake_model_default_articles_tags /var/www/html/tmp/cache/models/myapp_cake_model_default_tags $ ### ### Check by WEB browser. http://IPアドレス/users ### -------------------------------------------------------------------------------- .end of line