りんちゃんの日記

日常を書き留めていきます。

cakePHP3環境構築centOS6

【前提条件】

 Apache
 mySQL
 centOS 6.x
 php ※確認
 Cake Php 3 ※確認


1. 初期設定

 1.1.  iptablesを止める

  # chkconfig iptables off               ※設定
  # chkconfig --list iptables            
※確認

 1.2.  SELINUXを無効

  # sed -i "s/enforcing/disabled/g" /etc/sysconfig/selinux

 


2. リポジトリの設定

 2.1.  リポジトリパッケージインストール

  # yum install -y epel-release

 2.2.  リポジトリインストール

  # rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

 2.3.  PHPリポジトリ指定インストール

  # yum install -y --enablerepo=remi-php70 php
  # yum install -y --enablerepo=remi-php70 php-devel
  # yum install -y --enablerepo=remi-php70 php-mysql
  # yum install -y --enablerepo=remi-php70 php-mbstring
  # yum install -y --enablerepo=remi-php70 php-gd
  # yum install -y --enablerepo=remi-php70 php-pear
  # yum install -y --enablerepo=remi-php70 httpd-devel
  # yum install -y --enablerepo=remi-php70 php-intl
  # yum install -y --enablerepo=remi-php70 mysql-server

 2.4.  確認

  # php -v
  # pear list

 


3. php.iniを編集

 3.1.  タイムゾーンの設定

  # vi /etc/php.ini

 【編集内容】タイムゾーンを日本にする

  date.timezone = "Asia/Tokyo"

 


4. httpd.conf編集

  # vi /etc/httpd/conf/httpd.conf

 4.1.  「<Directory />」の中身を変更する

 変更前
   <Directory />
    AllowOverride none
    Require all denied
   </Directory>

 

 変更後
  <Directory />
   Options FollowSymLinks
   AllowOverride All
   Order allow,deny
   allow from all
  </Directory>

 4.2.  アプリディレクトリ「sushi」のApache設定を追加する

  追加する
  <Directory "/var/www/html/sushi">
   Options FollowSymLinks
   AllowOverride All
   Order allow,deny
   Allow from all
  </Directory>

 4.3.  ドキュメントルートの設定

  追加する
       DocumentRoot "/var/www/html/sushi"

 


5. MySQL設定

 5.1.  my.cmfの設定

 赤文字の箇所追加

  # vi /etc/my.cnf

    [mysqld]
    datadir=/var/lib/mysql
      socket=/var/lib/mysql/mysql.sock
      user=mysql
      # Disabling symbolic-links is recommended to prevent assorted security risks
      symbolic-links=0

      character-set-server=utf8


      # 任意設定
      innodb_file_per_table
      query-cache-size=16M

     [mysqld_safe]
   log-error=/var/log/mysqld.log
   pid-file=/var/run/mysqld/mysqld.pid

     [mysql]
     default-character-set=utf8

     [client]  <--追加 クライアントからの接続の文字コードの設定
     default-character-set=utf8

 5.2.  MySQLのサービス起動開始

   # service mysqld start

 5.3. MySQLのrootパスワードの設定

   # mysql_secure_installation

 5.4. mySQLに接続

   # mysql --user=root--password={rootのパスワード}

 5.5. DB作成

   mysql>create database sushi;                                                 ※DB作成
   mysql>grant all on *.* to ebi@localhost identified by 'ika';   
※ユーザ作成
   mysql>flush privileges;                   
※更新
   mysql>quit;                                                                               
mySQL切断

 


6. cakephp3のインストール

※CakePHP3をインストールするためにComposerをインストール

 6.1.  ダウンロード

   # curl -sS https://getcomposer.org/installer | php

 6.2.  ダウンロードファイルを 「/usr/local/bin/composer」へ移動する

   # mv composer.phar /usr/local/bin/composer

 6.3.  ディレクトリ移動

   # cd /var/www/html

 6.4.  CakePHPでsushiアプリを作成

アプリ名には任意のアプリ名を付ける(ここではsushi)

   # composer create-project --prefer-dist cakephp/app sushi
 ⇒ /var/www/html/sushiにアプリが作成される

 


7. app.phpを編集

 7.1.  DBの設定

※赤い箇所のところ設定する


   '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' => 'root',
     'password' => '{rootパスワード}',
     'database' => '{DB名}',
     'encoding' => 'utf8',
     'timezone' => 'Asia/Tokyo',
     'flags' => [],
     'cacheMetadata' => true,
     'log' => false,

 


8. 自動起動の設定

 8.1.  Appacheの起動

   # service httpd start

 8.2.  自動起動

   # chkconfig httpd on
   # chkconfig mysqld on

 8.3.  自動起動確認

   # chkconfig --list httpd
   # chkconfig --list mysqld

 


9. Apacheを再起動して、URLの確認

 9.1.  Apache再起動

   # service httpd restart

 9.2.  URLをブラウザで確認する

   http://IPアドレス