This repository is Chef Cookbooks for AWS OpsWorks Custom layer.
Support for PHP 5.6 and Apache 2.4 and PHP Application deployment.
- Note: This recipes tested on Amazon Linux version:
Amazon Linux 2015.03
This cookbooks use apache2
php
composer
recipes retrieved from Chef Supermarket via Berkshelf.
- Add a new stack
- Under Advanced Settings:
- Pick chef version
11.10
as the chef version - Use custom cookbook pointing to
https://github.com/yoshida/httpd24_php56_opsworks.git
- Enable "Manage Berkshelf" with
3.2.0
as the version - Edit "Custom JSON" (refer to Stack Custom JSON section)
- Pick chef version
- Add a new
Custom -> Custom
layer.
- Name:
PHP5.6 App Server
(as you like) - Short name:
php56app
(as you like)
- Edit the newly created layer, and add the custom recipes:
- Setup:
apache2
php
apache2::mod_php5
composer
- Note: If you want to use https, add the
apache2::mod_ssl
recipe, and add 443 toapache.listen_ports
in Stack Custom JSON. - Note:
composer
is optional recipe if you want to use composer - Note:
prompt
is optional recipe for display stack name to Prompt String (PS1)
- Note: If you want to use https, add the
- Configure:
php::configure
- Deploy:
deploy::php-deploy
- Note:
deploy::laravel5-deploy
is optional recipe for Laravel 5.1 initial configuration (composer
required)- You can customize
.env
configuration withlaravel5_deploy.dotenv
object in Stack Custom JSON (The.env
file copied from.env.example
file, and replacekey=value
pair in.env
file bylaravel5_deploy.dotenv
object's key-value pair).
- You can customize
- Note:
deploy::laravel5-migrate
,deploy::laravel5-migrate-refresh
are optional recipes for database migration.- To execute these recipes, you can manually run recipes on
Stack -> Run Command -> Execute Recipes
. - Learn more: http://docs.aws.amazon.com/opsworks/latest/userguide/workingcookbook-manual.html
- To execute these recipes, you can manually run recipes on
- Note:
- Undeploy:
deploy::php-undeploy
{
"apache": {
"package": "httpd24",
"service_name": "httpd",
"version": "2.4",
"lock_dir": "/var/run/httpd",
"default_site_enabled": false,
"listen_addresses": ["*"],
"listen_ports": ["80"]
},
"php": {
"packages": [
"php56",
"php56-devel",
"php56-mcrypt",
"php56-mbstring",
"php56-gd",
"php56-bcmath",
"php56-tidy",
"php56-pdo",
"php56-mysqlnd",
"php56-pecl-memcached",
"php56-pecl-apcu",
"php56-opcache"
],
"directives": {
"error_log": "/var/log/httpd/php_errors.log"
}
},
"laravel5_deploy": {
"dotenv": {
"APP_ENV": "production",
"APP_DEBUG": false
}
}
}
If you want to try deployment, we provide a sample application that displays phpinfo.
- Add a new application from the "Apps" section
- Under Settings:
- Name:
phpinfo
- Type:
PHP
- Document root:
public
- Data source type:
None
- Repository URL:
https://github.com/yoshida/phpinfo.git
- Name:
- Deploy
phpinfo
application - Open http://[your-server]/phpinfo.php
If you want to try deployment another application, let's try to deploy the https://github.com/Stolz/Wiki application. This application developed with Laravel 5.1 and database. You must set up the MySQL instance before create Apps.
- Add a new
DB -> MySQL
layer. - Edit the created MySQL layer, and add Custom JSON (workaround to avoid fail when deploy):
{ "mysql": { "mysql_bin": "/usr/bin/mysql" } }
- Add instance to MySQL Layer, and start instance.
Next, Set up the PHP5.6 App Server
layer.
- Add a new
Custom -> Custom
layer if you don't createPHP5.6 App Server
layer yet.
- Name:
PHP5.6 App Server
(as you like) - Short name:
php56app
(as you like)
- Edit the
PHP5.6 App Server
layer, and set the custom recipes:
- Setup:
apache2
php
apache2::mod_php5
apache2::mod_ssl
composer
prompt
- Configure:
php::configure
- Deploy:
deploy::php-deploy
deploy::laravel5-deploy
- Undeploy:
deploy::php-undeploy
- Add instance to PHP5.6 App Server Layer, and start instance.
Next, Set up the Apps.
- Add a new application from the "Apps" section
- Under Settings:
- Name:
wiki
- Type:
PHP
- Document root:
public
- Data source type:
OpsWorks
- Database instance:
db-master1
- Database name:
wiki
(as you like)
- Database instance:
- Repository URL:
https://github.com/Stolz/Wiki.git
- Enable SSL:
Yes
- SSL certificate: paste the your ssl certificate
- SSL certificate key: paste your ssl certificate key
- Name:
- Edit Stack Custom JSON:
{
"apache": {
"package": "httpd24",
"service_name": "httpd",
"version": "2.4",
"lock_dir": "/var/run/httpd",
"default_site_enabled": false,
"listen_addresses": ["*"],
"listen_ports": [80,443]
},
"php": {
"packages": [
"php56",
"php56-devel",
"php56-mcrypt",
"php56-mbstring",
"php56-gd",
"php56-bcmath",
"php56-tidy",
"php56-pdo",
"php56-mysqlnd",
"php56-pecl-memcached",
"php56-pecl-apcu",
"php56-opcache"
],
"directives": {
"error_log": "/var/log/httpd/php_errors.log"
}
},
"laravel5_deploy": {
"dotenv": {
"APP_ENV": "development",
"APP_DEBUG": true,
"APP_KEY": "your-application-key",
"FACEBOOK_OAUTH_CLIENT_ID": "your-id",
"FACEBOOK_OAUTH_CLIENT_SECRET": "your-secret",
"GITHUB_OAUTH_CLIENT_ID": "your-id",
"GITHUB_OAUTH_CLIENT_SECRET": "your-secret",
"GOOGLE_OAUTH_CLIENT_ID": "your-id",
"GOOGLE_OAUTH_CLIENT_SECRET": "your-secret",
"TWITTER_OAUTH_CLIENT_ID": "your-id",
"TWITTER_OAUTH_CLIENT_SECRET": "your-secret"
}
}
}
- Note: Generating a application key -> http://laravel-recipes.com/recipes/283/generating-a-new-application-key
- Deploy
wiki
application - Execute the
deploy::laravel5-migrate-refresh
recipe fromStack -> Run Command -> Execute Recipes
on PHP 5.6 instance - Open http://[your-server]/
If you cannot access the application, check these log files:
- /srv/www/wiki/current/storage/logs/*.log
- /var/log/httpd/wiki-error.log
- /var/log/httpd/error.log
- /var/log/httpd/php_errors.log