AnsibleでCakePHPを設置してみる
プレイブック
プレイブックを作成する。
※面倒なのでname:を省略してますが、ちゃんとname:を付けましょう。
$ vi cakephp.yml
--- - hosts: all sudo: yes vars: cake_ver: 2.5.5 cake_url: https://codeload.github.com/cakephp/cakephp/zip/{{cake_ver}} doc_root: /var/www/html cake_root: /var/www/html/cakephp-{{cake_ver}} tasks: # CakePHPをダウンロードする - get_url: url={{cake_url}} dest=/usr/local/src/cakephp.zip # CakePHPを解凍する(unzipが必要なので、unzipもインストールしている) - yum: name=unzip state=latest - unarchive: src=/usr/local/src/cakephp.zip dest={{doc_root}} creates={{cake_root}} # テンポラリのディレクトリのパーミッションを変更する - file: path={{cake_root}}/app/tmp mode=0777 recurse=yes # データベースの設定ファイルを設置する - template: src=database.php dest={{cake_root}}/app/Config/database.php # Apacheの設定ファイルを設置する - template: src=cakephp.conf dest=/etc/httpd/conf.d/cakephp.conf notify: - restart httpd # SecurityのsaltとcipherSeedを書き換える - lineinfile: > dest={{cake_root}}/app/Config/core.php regexp="^\s*Configure::write\('Security\.salt', '\w+'\);$" line=" Configure::write('Security.salt', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'); //changed" backrefs=yes - lineinfile: > dest={{cake_root}}/app/Config/core.php regexp="^\s*Configure::write\('Security\.cipherSeed', '\w+'\);$" line=" Configure::write('Security.cipherSeed', '0123456789'); //changed" backrefs=yes handlers: - name: restart httpd service: name=httpd state=restarted
$ vi cakephp.conf ServerName localhost NameVirtualHost *:80 <VirtualHost *:80> ServerName localhost DocumentRoot {{cake_root}}/app/webroot <Directory {{cake_root}}/app/webroot> AllowOverride all </Directory> </VirtualHost>
CakePHPのデータベースの設定ファイルを作成する。
$ vi database.php <?php class DATABASE_CONFIG { public $default = array( 'datasource' => 'Database/Mysql', 'persistent' => false, 'host' => 'localhost', 'login' => 'dbuser', 'password' => 'dbpassword', 'database' => 'sampledb', 'prefix' => '', //'encoding' => 'utf8', ); }