amazon linuxにcakephpをインストールしたので記録
cakephp インストール
使用したバージョン
パッケージ | バージョン |
---|---|
httpd | Apache/2.4.23 (Amazon) |
php | 5.6.24 |
mysql | 5.6.32 |
composer | 1.2.0 |
cakephpを使用するための必要なものインストールする
root ユーザーで実行
yum install -y httpd24 php56 mysql56-server
yum install -y php56-mcrypt php56-intl php56-mbstring php56-mysqlnd php56-opcache php56-devel
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
cakephpユーザーの作成
ユーザーを作成して作成したユーザーのホームディレクトリにプロジェクトを置きます。
sudo su
useradd cakephp
su cakephp
cd ~
プロジェクト作成
cakephpユーザーで実行
/usr/local/bin/composer create-project --prefer-dist cakephp/app /home/cakephp/sample
apacheが読み込めるように権限を付ける
rootユーザーで実行
chmod 770 /home/cakephp
chgrp apache -R /home/cakephp
find /home/cakephp -type d -exec chmod 0770 {} \;
find /home/cakephp -type f -exec chmod 0660 {} \;
httpd設定
rootでユーザー実行
cd /etc/httpd/conf.d/
vi 01-sample.conf
01-sample.conf
ServerName [ドメイン、またはIP]
<VirtualHost *:80>
Servername [ドメイン、またはIP]
DocumentRoot /home/cakephp/sample/webroot/
<Directory "/home/cakephp/sample">
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/httpd/cakephp-error_log
CustomLog /var/log/httpd/cakephp-access_log common
</VirtualHost>
httpd起動する
/etc/init.d/httpd start
以上で終了になります。webでアクセスしてcakephpの画面が出てくると思います。
servername がローカルIPの場合sshポートフォワードを使用してwebアクセスする。
sshポートフォワードやり方
以降は、データベースとcakephpを結びつけるやりかたを載せています。
mysqlの設定
rootユーザーで実行
例として
データベースcakephp
ユーザーcakephp
パスワードcakehphp
を作成します。
/etc/init.d/mysql start
mysql
create database cakephp CHARACTER SET utf8;
GRANT ALL PRIVILEGES ON cakephp.* TO cakephp@localhost IDENTIFIED BY 'cakephp';
quit
mysqlで作成したデータベースをcakephpに結び付ける
su cakephp
vi /home/cakephp/sample/config/app.php
接続するデータベースの指定のところを以下のように編集する。
app.php
'Datasources' => [
'default' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'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' => 'cakephp',
'password' => 'cakephp',
'database' => 'cakephp',
'encoding' => 'utf8',
'timezone' => 'UTC',
'flags' => [],
'cacheMetadata' => true,
'log' => false,
webページ開いてチェックマークがすべてについていたら終了です。
あとはデータベースにテーブルを作成したりコード書いたり…
おまけ。RDSに接続する場合のapp.phpの記述
app.php
'Datasources' => [
'default' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'RDSのエンドポイント',
/**
* 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' => '3306',
'username' => 'ユーザー名',
'password' => 'パスワード',
'database' => 'データベース名',
'encoding' => 'utf8',
'timezone' => 'UTC',
'flags' => [],
'cacheMetadata' => true,
'log' => false,