├── LICENSE ├── README.md ├── composer ├── metadata.rb └── recipes │ └── install.rb ├── laravel ├── metadata.rb ├── recipes │ ├── environment_variables.rb │ ├── storage_permissions.rb │ └── symlink_storage.rb └── templates │ └── default │ └── .env.erb ├── php ├── metadata.rb └── recipes │ └── mcrypt_enable.rb └── services ├── attributes └── ntp.rb ├── metadata.rb └── recipes ├── imagemagick.rb └── ntp.rb /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Dwight Watson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Laravel on OpsWorks 2 | =================== 3 | 4 | This repository contains recipes to provision and deploy OpsWorks stacks with Laravel 5+. 5 | 6 | You'll need to create an OpsWorks stack that uses Ubuntu 14.04 LTS, as the recipes in this repository are designed to work with that OS. 7 | 8 | ## Stack configuration 9 | 10 | When creating a stack, indicate that you want to use custom Chef cookbooks, with a repository type of Git and a repository URL of `https://github.com/dwightwatson/laravel-opsworks` (or your own repository URL if you decide to fork this one). You will not need an SSH key if the repository is public (like this one). The other settings for the stack you may set as you please. 11 | 12 | ## PHP App Server layer configuration 13 | 14 | You'll need to add the following recipes to the PHP App Server layer so that it can operate a Laravel installation. 15 | 16 | ### Setup 17 | 18 | In the setup stage, add the `php::mcrypt_enable` recipe. This will enable the PHP Mcrypt extension which is required by Laravel. 19 | 20 | ## Deploy 21 | 22 | In the deploy stage, add the following recipes. 23 | 24 | * `laravel::environment_variables` 25 | This recipe will populate your `.env` file with the database configuration of your OpsWorks data store (whether it be a database instance or RDS instance). It will also take the custom environment variables from your app configuration and place them into your `.env` file. 26 | 27 | * `laravel::symlink_storage` 28 | This will move the `storage` directory into a shared directory so that it can be used by each release of your app. For example, if you're storing cache/sessions or other application data in the storage folder it can be used by the next release after a deployment (so it won't force your users to re-authenticate or the app to re-build the cache). 29 | 30 | * `composer::install` 31 | This will install Composer and then the dependencies of your application for the given release, without the development dependencies. 32 | 33 | ## App configuration 34 | 35 | Select the correct data source type for your application (whether it be RDS or OpsWorks) as the credentials for that database will be passed into your application's environment. You can also add additional application environment variables, for example your `APP_KEY`. 36 | 37 | ```bash 38 | opsworks-agent-cli get_json 39 | ``` -------------------------------------------------------------------------------- /composer/metadata.rb: -------------------------------------------------------------------------------- 1 | name "composer" 2 | maintainer "Dwight Watson" 3 | maintainer_email "dwight@studiousapp.com" 4 | license "MIT" 5 | description "Installs Composer and project dependencies" 6 | version "1.0.0" -------------------------------------------------------------------------------- /composer/recipes/install.rb: -------------------------------------------------------------------------------- 1 | node[:deploy].each do |application, deploy| 2 | script "install_composer" do 3 | interpreter "bash" 4 | user "root" 5 | cwd "#{deploy[:deploy_to]}/current" 6 | code <<-EOH 7 | curl -s https://getcomposer.org/installer | php 8 | php composer.phar install --no-dev --no-interaction --prefer-dist 9 | EOH 10 | only_if { ::File.exist?("#{deploy[:deploy_to]}/current/composer.json")} 11 | end 12 | end -------------------------------------------------------------------------------- /laravel/metadata.rb: -------------------------------------------------------------------------------- 1 | name "php" 2 | maintainer "Dwight Watson" 3 | maintainer_email "dwight@studiousapp.com" 4 | license "MIT" 5 | description "Configure a Laravel application" 6 | version "1.0.0" -------------------------------------------------------------------------------- /laravel/recipes/environment_variables.rb: -------------------------------------------------------------------------------- 1 | node[:deploy].each do |application, deploy| 2 | template "#{deploy[:deploy_to]}/current/.env" do 3 | source ".env.erb" 4 | mode 0755 5 | owner deploy[:user] 6 | group deploy[:group] 7 | 8 | variables( 9 | database: deploy[:database], 10 | variables: (deploy[:environment_variables] rescue {}), 11 | ) 12 | 13 | only_if { ::File.directory?("#{deploy[:deploy_to]}/current") } 14 | end 15 | end -------------------------------------------------------------------------------- /laravel/recipes/storage_permissions.rb: -------------------------------------------------------------------------------- 1 | node[:deploy].each do |application, deploy| 2 | script "storage_permissions" do 3 | interpreter "bash" 4 | user "root" 5 | cwd "#{deploy[:deploy_to]}/current" 6 | code <<-EOH 7 | chmod -R 777 storage/app storage/framework storage/logs bootstrap/cache 8 | EOH 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /laravel/recipes/symlink_storage.rb: -------------------------------------------------------------------------------- 1 | node[:deploy].each do |application, deploy| 2 | script "symlink_storage" do 3 | interpreter "bash" 4 | user "root" 5 | cwd "#{deploy[:deploy_to]}" 6 | code <<-EOH 7 | chmod -R 777 current/storage/app current/storage/framework current/storage/logs current/bootstrap/cache 8 | mv current/storage/* shared 9 | rm -rf current/storage 10 | ln -s #{deploy[:deploy_to]}/shared #{deploy[:deploy_to]}/current/storage 11 | chown -h #{deploy[:user]}:#{deploy[:group]} #{deploy[:deploy_to]}/current/storage 12 | EOH 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /laravel/templates/default/.env.erb: -------------------------------------------------------------------------------- 1 | DB_CONNECTION=<%= @database[:type] %> 2 | DB_HOST=<%= @database[:host] %> 3 | DB_DATABASE=<%= @database[:database] %> 4 | DB_USERNAME=<%= @database[:username] %> 5 | DB_PASSWORD=<%= @database[:password] %> 6 | 7 | <% @variables.each do |key, value| %> 8 | <%= "#{key.upcase}=#{value}" %> 9 | <% end %> -------------------------------------------------------------------------------- /php/metadata.rb: -------------------------------------------------------------------------------- 1 | name "php" 2 | maintainer "Dwight Watson" 3 | maintainer_email "dwight@studiousapp.com" 4 | license "MIT" 5 | description "Configure PHP for Laravel" 6 | version "1.0.0" -------------------------------------------------------------------------------- /php/recipes/mcrypt_enable.rb: -------------------------------------------------------------------------------- 1 | case node[:platform] 2 | when "debian", "ubuntu" 3 | execute "enable_mcrypt" do 4 | user "root" 5 | command "php5enmod mcrypt && service apache2 restart" 6 | only_if { ::File.exist?("/etc/php5/mods-available/mcrypt.ini") } 7 | end 8 | end -------------------------------------------------------------------------------- /services/attributes/ntp.rb: -------------------------------------------------------------------------------- 1 | override[:ntp][:servers] = [ 2 | '0.amazon.pool.ntp.org', 3 | '1.amazon.pool.ntp.org', 4 | '2.amazon.pool.ntp.org', 5 | '3.amazon.pool.ntp.org', 6 | ] 7 | -------------------------------------------------------------------------------- /services/metadata.rb: -------------------------------------------------------------------------------- 1 | name "services" 2 | maintainer "Dwight Watson" 3 | maintainer_email "dwight@studiousapp.com" 4 | license "MIT" 5 | description "Configure PHP for Laravel" 6 | version "1.0.0" 7 | 8 | depends "ntp", "~> 1.8.2" -------------------------------------------------------------------------------- /services/recipes/imagemagick.rb: -------------------------------------------------------------------------------- 1 | case node[:platform] 2 | when "redhat", "centos", "fedora" 3 | package "ImageMagick" 4 | when "debian", "ubuntu" 5 | package "imagemagick" 6 | end -------------------------------------------------------------------------------- /services/recipes/ntp.rb: -------------------------------------------------------------------------------- 1 | include_recipe "ntp" --------------------------------------------------------------------------------