CakePHP 開発環境整備
vagrant, virtualboxに関してはインストール済み前提です。
概要
CentOS 6.7
CakePHP 3.2
Apache 2.2.15 → 2.4 以上の方が良いよ
Mysql 5.7.12
PHP 7.0.5
vagrant
vagrant init bento/centos-6.7
vagrant up
vagrant ssh
yum
yum update
※yum updateすると、その後vagrant reload,up を行うとマウントに失敗します。下記を参考に解決してください。
http://tech.withsin.net/2015/07/10/virtualbox-vagrant-mount-fail/
Apache
yum -y install httpd
設定はこちらを参考に
http://centos.server-manual.com/centos5_apache2.html
httpd -v
PHP
rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
yum install php70w php70w-opcache php70w-cli php70w-common php70w-devel php70w-mcrypt php70w-mysql php70w-intl php70w-mbstring
php -v
mysql
wget http://dev.mysql.com/get/mysql57-community-release-el6-7.noarch.rpm
yum localinstall mysql57-community-release-el6-7.noarch.rpm
yum install mysql-community-server
chkconfig mysqld on
chkconfig --list mysqld
mysqladmin --version
補足
cat /var/log/mysqld.log
# [Note] A temporary password is generated for root@localhost: **lNMg;#B/f6Y;** ←これがパスワードになります
パスワードは 8文字以上英大文字小文字数字記号の4種類を含む 必要がある。
※以下、**でくくられている部分が入力する部分になります。
http://weblabo.oscasierra.net/mysql-57-init-setup/
# mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root: **初期パスワードを入力する**
The existing password for the user account root has expired. Please set a new password.
New password: **新しいパスワードを入力する**
Re-enter new password: **再度同じ新しいパスワードを入力する**
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: **y**
There are three levels of password validation policy:
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Using existing password for root.
Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) :** y**
New password: **ポリシーに沿った新しいパスワードを入力**
Re-enter new password: **再度新しいパスワードを入力する**
Estimated strength of the password: 50
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : **y**
By default, a MySQL installation has an anonymous user, 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? (Press y|Y for Yes, any other key for No) : **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? (Press y|Y for Yes, any other key for No) : **y**
Success.
By default, MySQL 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? (Press y|Y for Yes, any other key for No) : **y**
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? (Press y|Y for Yes, any other key for No) : **y**
Success.
All done!
設定
sudo vi /etc/my.cnf
下記を追記
[client]
default-character-set=utf8
[mysqld]
skip-character-set-client-handshake
character-set-server = utf8
collation-server = utf8_general_ci
init-connect = SET NAMES utf8
[mysqldump]
default-character-set=utf8
[mysql]
default-character-set=utf8
sudo service mysqld restart
CakePHP
$ curl -sS https://getcomposer.org/installer | php
$ mv composer.phar /usr/local/bin/composer.phar
$ alias composer='/usr/local/bin/composer.phar'
$ composer --version
※今後composerの更新とかやる場合はaliasを設定しなおして、composer.jsonがあるディレクトリに移動して,composerコマンドをたたくといいっぽい。
my_app_nameに今回作成するアプリの名前を入れてください。
composer self-update && composer create-project --prefer-dist cakephp/app my_app_name
sudo vi /etc/httpd/conf/httpd.conf
DocumentRoot "/var/www/html"
↓
DocumentRoot "/var/www/app_name"
app_nameの部分はcake のアプリ名(上記で設定したものにします)
さらに、Vagratfileを書き換えます。
config.vm.synced_folder "./", "/vagrant", owner: 'vagrant', group: 'apache', mount_options: ['dmode=777', 'fmode=666']
上記は、共有フォルダ以下にCakephpプロジェクトを配置するために必要な処理です。