├── .gitignore ├── .cfignore ├── .bp-config ├── options.json └── httpd │ └── extra │ └── httpd-modules.conf ├── manifest.yml ├── .extensions └── drupal │ └── extension.py ├── README.md ├── LICENSE.md └── htdocs └── sites └── default └── settings.php /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | -------------------------------------------------------------------------------- /.cfignore: -------------------------------------------------------------------------------- 1 | .git 2 | README.md 3 | *.swp 4 | -------------------------------------------------------------------------------- /.bp-config/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "PHP_EXTENSIONS": [ "bz2", "zlib", "curl", "mcrypt", "gd", "pdo", "pdo_mysql", "apc", "mbstring"] 3 | } 4 | -------------------------------------------------------------------------------- /manifest.yml: -------------------------------------------------------------------------------- 1 | --- 2 | applications: 3 | - name: cf-ex-drupal 4 | memory: 128M 5 | instances: 1 6 | path: . 7 | services: 8 | - mysql 9 | -------------------------------------------------------------------------------- /.bp-config/httpd/extra/httpd-modules.conf: -------------------------------------------------------------------------------- 1 | LoadModule authz_core_module modules/mod_authz_core.so 2 | LoadModule authz_host_module modules/mod_authz_host.so 3 | LoadModule log_config_module modules/mod_log_config.so 4 | LoadModule env_module modules/mod_env.so 5 | LoadModule setenvif_module modules/mod_setenvif.so 6 | LoadModule dir_module modules/mod_dir.so 7 | LoadModule mime_module modules/mod_mime.so 8 | LoadModule reqtimeout_module modules/mod_reqtimeout.so 9 | LoadModule unixd_module modules/mod_unixd.so 10 | LoadModule mpm_event_module modules/mod_mpm_event.so 11 | LoadModule proxy_module modules/mod_proxy.so 12 | LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so 13 | LoadModule remoteip_module modules/mod_remoteip.so 14 | LoadModule rewrite_module modules/mod_rewrite.so 15 | LoadModule filter_module modules/mod_filter.so 16 | LoadModule deflate_module modules/mod_deflate.so 17 | LoadModule headers_module modules/mod_headers.so 18 | LoadModule access_compat_module modules/mod_access_compat.so 19 | -------------------------------------------------------------------------------- /.extensions/drupal/extension.py: -------------------------------------------------------------------------------- 1 | """Drupal Extension 2 | 3 | Downloads, installs and configures Drupal 4 | """ 5 | import os 6 | import os.path 7 | import logging 8 | from build_pack_utils import utils 9 | 10 | 11 | _log = logging.getLogger('drupal') 12 | 13 | 14 | DEFAULTS = utils.FormattedDict({ 15 | 'DRUPAL_VERSION': '7.53', 16 | 'DRUPAL_PACKAGE': 'drupal-{DRUPAL_VERSION}.tar.gz', 17 | 'DRUPAL_HASH': '4230279ecca4f0cde652a219e10327e7', 18 | 'DRUPAL_URL': 'http://ftp.drupal.org/files/projects/{DRUPAL_PACKAGE}' 19 | }) 20 | 21 | 22 | # Extension Methods 23 | def preprocess_commands(ctx): 24 | return () 25 | 26 | 27 | def service_commands(ctx): 28 | return {} 29 | 30 | 31 | def service_environment(ctx): 32 | return {} 33 | 34 | 35 | def compile(install): 36 | print 'Installing Drupal %s' % DEFAULTS['DRUPAL_VERSION'] 37 | ctx = install.builder._ctx 38 | inst = install._installer 39 | workDir = os.path.join(ctx['TMPDIR'], 'drupal') 40 | inst.install_binary_direct( 41 | DEFAULTS['DRUPAL_URL'], 42 | DEFAULTS['DRUPAL_HASH'], 43 | workDir, 44 | fileName=DEFAULTS['DRUPAL_PACKAGE'], 45 | strip=True) 46 | (install.builder 47 | .move() 48 | .everything() 49 | .under('{BUILD_DIR}/htdocs') 50 | .into(workDir) 51 | .done()) 52 | (install.builder 53 | .move() 54 | .everything() 55 | .under(workDir) 56 | .into('{BUILD_DIR}/htdocs') 57 | .done()) 58 | return 0 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## CloudFoundry PHP Example Application: Drupal 2 | 3 | This is an example application which can be run on CloudFoundry using the [PHP Build Pack]. 4 | 5 | This is an out-of-the-box implementation of Drupal. It's an example of how common PHP applications can easily be run on CloudFoundry. 6 | 7 | ### Usage 8 | 9 | 1. Clone the app (i.e. this repo). 10 | 11 | ```bash 12 | git clone https://github.com/cloudfoundry-samples/cf-ex-drupal.git cf-ex-drupal 13 | cd cf-ex-drupal 14 | ``` 15 | 16 | 1. If you don't have one already, create a MySQL service. With Pivotal Web Services, the following command will create a free MySQL database through [ClearDb]. Any MySQL provider should work. 17 | 18 | ```bash 19 | cf create-service cleardb spark mysql 20 | ``` 21 | 22 | 1. Edit `sites/default/settings.php` and change the `drupal_hash_salt`. This should be uniqe for every installation. Optionally edit any other settings, however you do *not* need to edit the database configuration. The file included with this example will automatically pull that information from `VCAP_SERVICES`. 23 | 24 | 1. Push it to CloudFoundry. 25 | 26 | ```bash 27 | cf push 28 | ``` 29 | 30 | 1. On your first push, you'll need to access the install script. It'll be `http://.cfapps.io/install.php`. Follow instructions there to complete the install. After it's done, you'll be all set. 31 | 32 | 33 | ### How It Works 34 | 35 | When you push the application here's what happens. 36 | 37 | 1. The local bits are pushed to your target. This is small, five files around 25k. It includes the changes we made and a build pack extension for Drupal. 38 | 1. The server downloads the [PHP Build Pack] and runs it. This installs HTTPD and PHP. 39 | 1. The build pack sees the extension that we pushed and runs it. The extension downloads the stock Drupal file from their server, unzips it and installs it into the `htdocs` directory. It then copies the rest of the files that we pushed and replaces the default Drupal files with them. In this case, it's just the `sites/default/settings.php` file. 40 | 1. At this point, the build pack is done and CF runs our droplet. 41 | 42 | 43 | ### Changes 44 | 45 | 1. I include a [custom list of HTTPD modules](https://github.com/cloudfoundry-samples/cf-ex-drupal/blob/master/.bp-config/httpd/extra/httpd-modules.conf#L15). These are the same as the default, but I've added `mod_access_compat`, which is necessary because Drupal's `.htaccess` file still uses HTTPD 2.2 config. 46 | 47 | 1. I [add the PHP extensions](https://github.com/cloudfoundry-samples/cf-ex-drupal/blob/master/.bp-config/options.json#L2) that are needed by Drupal. 48 | 49 | 1. I add a [custom build pack extension](https://github.com/cloudfoundry-samples/cf-ex-drupal/blob/master/.extensions/drupal/extension.py), which downloads Drupal on the remote server. This is not strictly necessary, but it saves me from having to upload a lot of files on each push. The version of Drupal that will be installed is [here](https://github.com/cloudfoundry-samples/cf-ex-drupal/blob/master/.extensions/drupal/extension.py#L15). 50 | 51 | 1. I include a [copy of the default settings from the standard Drupal install](https://github.com/cloudfoundry-samples/cf-ex-drupal/blob/master/htdocs/sites/default/settings.php). This is [modified](https://github.com/cloudfoundry-samples/cf-ex-drupal/blob/master/htdocs/sites/default/settings.php#L216-L251) to pull the database configuration from the `VCAP_SERVICES` environment variable, which is populated with information from services that are bound to the app. Since we bind a MySQL service to our app in the instructions above, we search for that and automatically configure it for use with Drupal. 52 | 53 | ### Caution 54 | 55 | Please read the following before using Drupal in production on CloudFoundry. 56 | 57 | 1. Drupal is designed to write to the local file system. This does not work well with CloudFoundry, as an application's [local storage on CloudFoundry] is ephemeral. In other words, Drupal will write things to the local disk and they will eventually disappear. 58 | 59 | You can work around this in some cases, like with media, by using a storage service like Amazon S3 or CloudFront. However there may be other cases where Drupal or Drupal plugins try to write to the disk, so test your installation carefully. 60 | 61 | 1. This is not an issue with Drupal specifically, but PHP stores session information to the local disk. As mentioned previously, the local disk for an application on CloudFoundry is ephemeral, so it is possible for you to lose session and session data. If you need reliable session storage, look at storing session data in an SQL database or with a NoSQL service. 62 | 63 | 64 | [PHP Buildpack]:https://github.com/cloudfoundry/php-buildpack 65 | [ClearDb]:https://www.cleardb.com/ 66 | [local storage on CloudFoundry]:http://docs.cloudfoundry.org/devguide/deploy-apps/prepare-to-deploy.html#filesystem 67 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /htdocs/sites/default/settings.php: -------------------------------------------------------------------------------- 1 | 'mysql', 68 | * 'database' => 'databasename', 69 | * 'username' => 'username', 70 | * 'password' => 'password', 71 | * 'host' => 'localhost', 72 | * 'port' => 3306, 73 | * 'prefix' => 'myprefix_', 74 | * 'collation' => 'utf8_general_ci', 75 | * ); 76 | * @endcode 77 | * 78 | * The "driver" property indicates what Drupal database driver the 79 | * connection should use. This is usually the same as the name of the 80 | * database type, such as mysql or sqlite, but not always. The other 81 | * properties will vary depending on the driver. For SQLite, you must 82 | * specify a database file name in a directory that is writable by the 83 | * webserver. For most other drivers, you must specify a 84 | * username, password, host, and database name. 85 | * 86 | * Transaction support is enabled by default for all drivers that support it, 87 | * including MySQL. To explicitly disable it, set the 'transactions' key to 88 | * FALSE. 89 | * Note that some configurations of MySQL, such as the MyISAM engine, don't 90 | * support it and will proceed silently even if enabled. If you experience 91 | * transaction related crashes with such configuration, set the 'transactions' 92 | * key to FALSE. 93 | * 94 | * For each database, you may optionally specify multiple "target" databases. 95 | * A target database allows Drupal to try to send certain queries to a 96 | * different database if it can but fall back to the default connection if not. 97 | * That is useful for master/slave replication, as Drupal may try to connect 98 | * to a slave server when appropriate and if one is not available will simply 99 | * fall back to the single master server. 100 | * 101 | * The general format for the $databases array is as follows: 102 | * @code 103 | * $databases['default']['default'] = $info_array; 104 | * $databases['default']['slave'][] = $info_array; 105 | * $databases['default']['slave'][] = $info_array; 106 | * $databases['extra']['default'] = $info_array; 107 | * @endcode 108 | * 109 | * In the above example, $info_array is an array of settings described above. 110 | * The first line sets a "default" database that has one master database 111 | * (the second level default). The second and third lines create an array 112 | * of potential slave databases. Drupal will select one at random for a given 113 | * request as needed. The fourth line creates a new database with a name of 114 | * "extra". 115 | * 116 | * For a single database configuration, the following is sufficient: 117 | * @code 118 | * $databases['default']['default'] = array( 119 | * 'driver' => 'mysql', 120 | * 'database' => 'databasename', 121 | * 'username' => 'username', 122 | * 'password' => 'password', 123 | * 'host' => 'localhost', 124 | * 'prefix' => 'main_', 125 | * 'collation' => 'utf8_general_ci', 126 | * ); 127 | * @endcode 128 | * 129 | * You can optionally set prefixes for some or all database table names 130 | * by using the 'prefix' setting. If a prefix is specified, the table 131 | * name will be prepended with its value. Be sure to use valid database 132 | * characters only, usually alphanumeric and underscore. If no prefixes 133 | * are desired, leave it as an empty string ''. 134 | * 135 | * To have all database names prefixed, set 'prefix' as a string: 136 | * @code 137 | * 'prefix' => 'main_', 138 | * @endcode 139 | * To provide prefixes for specific tables, set 'prefix' as an array. 140 | * The array's keys are the table names and the values are the prefixes. 141 | * The 'default' element is mandatory and holds the prefix for any tables 142 | * not specified elsewhere in the array. Example: 143 | * @code 144 | * 'prefix' => array( 145 | * 'default' => 'main_', 146 | * 'users' => 'shared_', 147 | * 'sessions' => 'shared_', 148 | * 'role' => 'shared_', 149 | * 'authmap' => 'shared_', 150 | * ), 151 | * @endcode 152 | * You can also use a reference to a schema/database as a prefix. This may be 153 | * useful if your Drupal installation exists in a schema that is not the default 154 | * or you want to access several databases from the same code base at the same 155 | * time. 156 | * Example: 157 | * @code 158 | * 'prefix' => array( 159 | * 'default' => 'main.', 160 | * 'users' => 'shared.', 161 | * 'sessions' => 'shared.', 162 | * 'role' => 'shared.', 163 | * 'authmap' => 'shared.', 164 | * ); 165 | * @endcode 166 | * NOTE: MySQL and SQLite's definition of a schema is a database. 167 | * 168 | * Advanced users can add or override initial commands to execute when 169 | * connecting to the database server, as well as PDO connection settings. For 170 | * example, to enable MySQL SELECT queries to exceed the max_join_size system 171 | * variable, and to reduce the database connection timeout to 5 seconds: 172 | * 173 | * @code 174 | * $databases['default']['default'] = array( 175 | * 'init_commands' => array( 176 | * 'big_selects' => 'SET SQL_BIG_SELECTS=1', 177 | * ), 178 | * 'pdo' => array( 179 | * PDO::ATTR_TIMEOUT => 5, 180 | * ), 181 | * ); 182 | * @endcode 183 | * 184 | * WARNING: These defaults are designed for database portability. Changing them 185 | * may cause unexpected behavior, including potential data loss. 186 | * 187 | * @see DatabaseConnection_mysql::__construct 188 | * @see DatabaseConnection_pgsql::__construct 189 | * @see DatabaseConnection_sqlite::__construct 190 | * 191 | * Database configuration format: 192 | * @code 193 | * $databases['default']['default'] = array( 194 | * 'driver' => 'mysql', 195 | * 'database' => 'databasename', 196 | * 'username' => 'username', 197 | * 'password' => 'password', 198 | * 'host' => 'localhost', 199 | * 'prefix' => '', 200 | * ); 201 | * $databases['default']['default'] = array( 202 | * 'driver' => 'pgsql', 203 | * 'database' => 'databasename', 204 | * 'username' => 'username', 205 | * 'password' => 'password', 206 | * 'host' => 'localhost', 207 | * 'prefix' => '', 208 | * ); 209 | * $databases['default']['default'] = array( 210 | * 'driver' => 'sqlite', 211 | * 'database' => '/path/to/databasefilename', 212 | * ); 213 | * @endcode 214 | */ 215 | 216 | /* 217 | * Read MySQL service properties from _ENV['VCAP_SERVICES'] 218 | */ 219 | $service_blob = json_decode($_ENV['VCAP_SERVICES'], true); 220 | $mysql_services = array(); 221 | foreach($service_blob as $service_provider => $service_list) { 222 | // looks for 'cleardb' or 'p-mysql' service 223 | if ($service_provider === 'cleardb' || $service_provider === 'p-mysql') { 224 | foreach($service_list as $mysql_service) { 225 | $mysql_services[] = $mysql_service; 226 | } 227 | continue; 228 | } 229 | foreach ($service_list as $some_service) { 230 | // looks for tags of 'mysql' 231 | if (in_array('mysql', $some_service['tags'], true)) { 232 | $mysql_services[] = $some_service; 233 | continue; 234 | } 235 | // look for a service where the name includes 'mysql' 236 | if (strpos($some_service['name'], 'mysql') !== false) { 237 | $mysql_services[] = $some_service; 238 | } 239 | } 240 | } 241 | 242 | // Configure Drupal, using the first database found 243 | $databases['default']['default'] = array( 244 | 'driver' => 'mysql', 245 | 'database' => $mysql_services[0]['credentials']['name'], 246 | 'username' => $mysql_services[0]['credentials']['username'], 247 | 'password' => $mysql_services[0]['credentials']['password'], 248 | 'host' => $mysql_services[0]['credentials']['hostname'], 249 | 'prefix' => 'drupal_', 250 | 'collation' => 'utf8_general_ci', 251 | ); 252 | 253 | /** 254 | * Access control for update.php script. 255 | * 256 | * If you are updating your Drupal installation using the update.php script but 257 | * are not logged in using either an account with the "Administer software 258 | * updates" permission or the site maintenance account (the account that was 259 | * created during installation), you will need to modify the access check 260 | * statement below. Change the FALSE to a TRUE to disable the access check. 261 | * After finishing the upgrade, be sure to open this file again and change the 262 | * TRUE back to a FALSE! 263 | */ 264 | $update_free_access = FALSE; 265 | 266 | /** 267 | * Salt for one-time login links and cancel links, form tokens, etc. 268 | * 269 | * This variable will be set to a random value by the installer. All one-time 270 | * login links will be invalidated if the value is changed. Note that if your 271 | * site is deployed on a cluster of web servers, you must ensure that this 272 | * variable has the same value on each server. If this variable is empty, a hash 273 | * of the serialized database credentials will be used as a fallback salt. 274 | * 275 | * For enhanced security, you may set this variable to a value using the 276 | * contents of a file outside your docroot that is never saved together 277 | * with any backups of your Drupal files and database. 278 | * 279 | * Example: 280 | * $drupal_hash_salt = file_get_contents('/home/example/salt.txt'); 281 | * 282 | */ 283 | $drupal_hash_salt = 'my unique salt - you should really change this'; 284 | 285 | /** 286 | * Base URL (optional). 287 | * 288 | * If Drupal is generating incorrect URLs on your site, which could 289 | * be in HTML headers (links to CSS and JS files) or visible links on pages 290 | * (such as in menus), uncomment the Base URL statement below (remove the 291 | * leading hash sign) and fill in the absolute URL to your Drupal installation. 292 | * 293 | * You might also want to force users to use a given domain. 294 | * See the .htaccess file for more information. 295 | * 296 | * Examples: 297 | * $base_url = 'http://www.example.com'; 298 | * $base_url = 'http://www.example.com:8888'; 299 | * $base_url = 'http://www.example.com/drupal'; 300 | * $base_url = 'https://www.example.com:8888/drupal'; 301 | * 302 | * It is not allowed to have a trailing slash; Drupal will add it 303 | * for you. 304 | */ 305 | # $base_url = 'http://www.example.com'; // NO trailing slash! 306 | 307 | /** 308 | * PHP settings: 309 | * 310 | * To see what PHP settings are possible, including whether they can be set at 311 | * runtime (by using ini_set()), read the PHP documentation: 312 | * http://www.php.net/manual/ini.list.php 313 | * See drupal_environment_initialize() in includes/bootstrap.inc for required 314 | * runtime settings and the .htaccess file for non-runtime settings. Settings 315 | * defined there should not be duplicated here so as to avoid conflict issues. 316 | */ 317 | 318 | /** 319 | * Some distributions of Linux (most notably Debian) ship their PHP 320 | * installations with garbage collection (gc) disabled. Since Drupal depends on 321 | * PHP's garbage collection for clearing sessions, ensure that garbage 322 | * collection occurs by using the most common settings. 323 | */ 324 | ini_set('session.gc_probability', 1); 325 | ini_set('session.gc_divisor', 100); 326 | 327 | /** 328 | * Set session lifetime (in seconds), i.e. the time from the user's last visit 329 | * to the active session may be deleted by the session garbage collector. When 330 | * a session is deleted, authenticated users are logged out, and the contents 331 | * of the user's $_SESSION variable is discarded. 332 | */ 333 | ini_set('session.gc_maxlifetime', 200000); 334 | 335 | /** 336 | * Set session cookie lifetime (in seconds), i.e. the time from the session is 337 | * created to the cookie expires, i.e. when the browser is expected to discard 338 | * the cookie. The value 0 means "until the browser is closed". 339 | */ 340 | ini_set('session.cookie_lifetime', 2000000); 341 | 342 | /** 343 | * If you encounter a situation where users post a large amount of text, and 344 | * the result is stripped out upon viewing but can still be edited, Drupal's 345 | * output filter may not have sufficient memory to process it. If you 346 | * experience this issue, you may wish to uncomment the following two lines 347 | * and increase the limits of these variables. For more information, see 348 | * http://php.net/manual/pcre.configuration.php. 349 | */ 350 | # ini_set('pcre.backtrack_limit', 200000); 351 | # ini_set('pcre.recursion_limit', 200000); 352 | 353 | /** 354 | * Drupal automatically generates a unique session cookie name for each site 355 | * based on its full domain name. If you have multiple domains pointing at the 356 | * same Drupal site, you can either redirect them all to a single domain (see 357 | * comment in .htaccess), or uncomment the line below and specify their shared 358 | * base domain. Doing so assures that users remain logged in as they cross 359 | * between your various domains. Make sure to always start the $cookie_domain 360 | * with a leading dot, as per RFC 2109. 361 | */ 362 | # $cookie_domain = '.example.com'; 363 | 364 | /** 365 | * Variable overrides: 366 | * 367 | * To override specific entries in the 'variable' table for this site, 368 | * set them here. You usually don't need to use this feature. This is 369 | * useful in a configuration file for a vhost or directory, rather than 370 | * the default settings.php. Any configuration setting from the 'variable' 371 | * table can be given a new value. Note that any values you provide in 372 | * these variable overrides will not be modifiable from the Drupal 373 | * administration interface. 374 | * 375 | * The following overrides are examples: 376 | * - site_name: Defines the site's name. 377 | * - theme_default: Defines the default theme for this site. 378 | * - anonymous: Defines the human-readable name of anonymous users. 379 | * Remove the leading hash signs to enable. 380 | */ 381 | # $conf['site_name'] = 'My Drupal site'; 382 | # $conf['theme_default'] = 'garland'; 383 | # $conf['anonymous'] = 'Visitor'; 384 | 385 | /** 386 | * A custom theme can be set for the offline page. This applies when the site 387 | * is explicitly set to maintenance mode through the administration page or when 388 | * the database is inactive due to an error. It can be set through the 389 | * 'maintenance_theme' key. The template file should also be copied into the 390 | * theme. It is located inside 'modules/system/maintenance-page.tpl.php'. 391 | * Note: This setting does not apply to installation and update pages. 392 | */ 393 | # $conf['maintenance_theme'] = 'bartik'; 394 | 395 | /** 396 | * Reverse Proxy Configuration: 397 | * 398 | * Reverse proxy servers are often used to enhance the performance 399 | * of heavily visited sites and may also provide other site caching, 400 | * security, or encryption benefits. In an environment where Drupal 401 | * is behind a reverse proxy, the real IP address of the client should 402 | * be determined such that the correct client IP address is available 403 | * to Drupal's logging, statistics, and access management systems. In 404 | * the most simple scenario, the proxy server will add an 405 | * X-Forwarded-For header to the request that contains the client IP 406 | * address. However, HTTP headers are vulnerable to spoofing, where a 407 | * malicious client could bypass restrictions by setting the 408 | * X-Forwarded-For header directly. Therefore, Drupal's proxy 409 | * configuration requires the IP addresses of all remote proxies to be 410 | * specified in $conf['reverse_proxy_addresses'] to work correctly. 411 | * 412 | * Enable this setting to get Drupal to determine the client IP from 413 | * the X-Forwarded-For header (or $conf['reverse_proxy_header'] if set). 414 | * If you are unsure about this setting, do not have a reverse proxy, 415 | * or Drupal operates in a shared hosting environment, this setting 416 | * should remain commented out. 417 | * 418 | * In order for this setting to be used you must specify every possible 419 | * reverse proxy IP address in $conf['reverse_proxy_addresses']. 420 | * If a complete list of reverse proxies is not available in your 421 | * environment (for example, if you use a CDN) you may set the 422 | * $_SERVER['REMOTE_ADDR'] variable directly in settings.php. 423 | * Be aware, however, that it is likely that this would allow IP 424 | * address spoofing unless more advanced precautions are taken. 425 | */ 426 | # $conf['reverse_proxy'] = TRUE; 427 | 428 | /** 429 | * Specify every reverse proxy IP address in your environment. 430 | * This setting is required if $conf['reverse_proxy'] is TRUE. 431 | */ 432 | # $conf['reverse_proxy_addresses'] = array('a.b.c.d', ...); 433 | 434 | /** 435 | * Set this value if your proxy server sends the client IP in a header 436 | * other than X-Forwarded-For. 437 | */ 438 | # $conf['reverse_proxy_header'] = 'HTTP_X_CLUSTER_CLIENT_IP'; 439 | 440 | /** 441 | * Page caching: 442 | * 443 | * By default, Drupal sends a "Vary: Cookie" HTTP header for anonymous page 444 | * views. This tells a HTTP proxy that it may return a page from its local 445 | * cache without contacting the web server, if the user sends the same Cookie 446 | * header as the user who originally requested the cached page. Without "Vary: 447 | * Cookie", authenticated users would also be served the anonymous page from 448 | * the cache. If the site has mostly anonymous users except a few known 449 | * editors/administrators, the Vary header can be omitted. This allows for 450 | * better caching in HTTP proxies (including reverse proxies), i.e. even if 451 | * clients send different cookies, they still get content served from the cache. 452 | * However, authenticated users should access the site directly (i.e. not use an 453 | * HTTP proxy, and bypass the reverse proxy if one is used) in order to avoid 454 | * getting cached pages from the proxy. 455 | */ 456 | # $conf['omit_vary_cookie'] = TRUE; 457 | 458 | /** 459 | * CSS/JS aggregated file gzip compression: 460 | * 461 | * By default, when CSS or JS aggregation and clean URLs are enabled Drupal will 462 | * store a gzip compressed (.gz) copy of the aggregated files. If this file is 463 | * available then rewrite rules in the default .htaccess file will serve these 464 | * files to browsers that accept gzip encoded content. This allows pages to load 465 | * faster for these users and has minimal impact on server load. If you are 466 | * using a webserver other than Apache httpd, or a caching reverse proxy that is 467 | * configured to cache and compress these files itself you may want to uncomment 468 | * one or both of the below lines, which will prevent gzip files being stored. 469 | */ 470 | # $conf['css_gzip_compression'] = FALSE; 471 | # $conf['js_gzip_compression'] = FALSE; 472 | 473 | /** 474 | * Block caching: 475 | * 476 | * Block caching may not be compatible with node access modules depending on 477 | * how the original block cache policy is defined by the module that provides 478 | * the block. By default, Drupal therefore disables block caching when one or 479 | * more modules implement hook_node_grants(). If you consider block caching to 480 | * be safe on your site and want to bypass this restriction, uncomment the line 481 | * below. 482 | */ 483 | # $conf['block_cache_bypass_node_grants'] = TRUE; 484 | 485 | /** 486 | * String overrides: 487 | * 488 | * To override specific strings on your site with or without enabling the Locale 489 | * module, add an entry to this list. This functionality allows you to change 490 | * a small number of your site's default English language interface strings. 491 | * 492 | * Remove the leading hash signs to enable. 493 | */ 494 | # $conf['locale_custom_strings_en'][''] = array( 495 | # 'forum' => 'Discussion board', 496 | # '@count min' => '@count minutes', 497 | # ); 498 | 499 | /** 500 | * 501 | * IP blocking: 502 | * 503 | * To bypass database queries for denied IP addresses, use this setting. 504 | * Drupal queries the {blocked_ips} table by default on every page request 505 | * for both authenticated and anonymous users. This allows the system to 506 | * block IP addresses from within the administrative interface and before any 507 | * modules are loaded. However on high traffic websites you may want to avoid 508 | * this query, allowing you to bypass database access altogether for anonymous 509 | * users under certain caching configurations. 510 | * 511 | * If using this setting, you will need to add back any IP addresses which 512 | * you may have blocked via the administrative interface. Each element of this 513 | * array represents a blocked IP address. Uncommenting the array and leaving it 514 | * empty will have the effect of disabling IP blocking on your site. 515 | * 516 | * Remove the leading hash signs to enable. 517 | */ 518 | # $conf['blocked_ips'] = array( 519 | # 'a.b.c.d', 520 | # ); 521 | 522 | /** 523 | * Fast 404 pages: 524 | * 525 | * Drupal can generate fully themed 404 pages. However, some of these responses 526 | * are for images or other resource files that are not displayed to the user. 527 | * This can waste bandwidth, and also generate server load. 528 | * 529 | * The options below return a simple, fast 404 page for URLs matching a 530 | * specific pattern: 531 | * - 404_fast_paths_exclude: A regular expression to match paths to exclude, 532 | * such as images generated by image styles, or dynamically-resized images. 533 | * If you need to add more paths, you can add '|path' to the expression. 534 | * - 404_fast_paths: A regular expression to match paths that should return a 535 | * simple 404 page, rather than the fully themed 404 page. If you don't have 536 | * any aliases ending in htm or html you can add '|s?html?' to the expression. 537 | * - 404_fast_html: The html to return for simple 404 pages. 538 | * 539 | * Add leading hash signs if you would like to disable this functionality. 540 | */ 541 | $conf['404_fast_paths_exclude'] = '/\/(?:styles)\//'; 542 | $conf['404_fast_paths'] = '/\.(?:txt|png|gif|jpe?g|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp)$/i'; 543 | $conf['404_fast_html'] = '404 Not Found

Not Found

The requested URL "@path" was not found on this server.

'; 544 | 545 | /** 546 | * By default the page request process will return a fast 404 page for missing 547 | * files if they match the regular expression set in '404_fast_paths' and not 548 | * '404_fast_paths_exclude' above. 404 errors will simultaneously be logged in 549 | * the Drupal system log. 550 | * 551 | * You can choose to return a fast 404 page earlier for missing pages (as soon 552 | * as settings.php is loaded) by uncommenting the line below. This speeds up 553 | * server response time when loading 404 error pages and prevents the 404 error 554 | * from being logged in the Drupal system log. In order to prevent valid pages 555 | * such as image styles and other generated content that may match the 556 | * '404_fast_paths' regular expression from returning 404 errors, it is 557 | * necessary to add them to the '404_fast_paths_exclude' regular expression 558 | * above. Make sure that you understand the effects of this feature before 559 | * uncommenting the line below. 560 | */ 561 | # drupal_fast_404(); 562 | 563 | /** 564 | * External access proxy settings: 565 | * 566 | * If your site must access the Internet via a web proxy then you can enter 567 | * the proxy settings here. Currently only basic authentication is supported 568 | * by using the username and password variables. The proxy_user_agent variable 569 | * can be set to NULL for proxies that require no User-Agent header or to a 570 | * non-empty string for proxies that limit requests to a specific agent. The 571 | * proxy_exceptions variable is an array of host names to be accessed directly, 572 | * not via proxy. 573 | */ 574 | # $conf['proxy_server'] = ''; 575 | # $conf['proxy_port'] = 8080; 576 | # $conf['proxy_username'] = ''; 577 | # $conf['proxy_password'] = ''; 578 | # $conf['proxy_user_agent'] = ''; 579 | # $conf['proxy_exceptions'] = array('127.0.0.1', 'localhost'); 580 | 581 | /** 582 | * Authorized file system operations: 583 | * 584 | * The Update manager module included with Drupal provides a mechanism for 585 | * site administrators to securely install missing updates for the site 586 | * directly through the web user interface. On securely-configured servers, 587 | * the Update manager will require the administrator to provide SSH or FTP 588 | * credentials before allowing the installation to proceed; this allows the 589 | * site to update the new files as the user who owns all the Drupal files, 590 | * instead of as the user the webserver is running as. On servers where the 591 | * webserver user is itself the owner of the Drupal files, the administrator 592 | * will not be prompted for SSH or FTP credentials (note that these server 593 | * setups are common on shared hosting, but are inherently insecure). 594 | * 595 | * Some sites might wish to disable the above functionality, and only update 596 | * the code directly via SSH or FTP themselves. This setting completely 597 | * disables all functionality related to these authorized file operations. 598 | * 599 | * @see http://drupal.org/node/244924 600 | * 601 | * Remove the leading hash signs to disable. 602 | */ 603 | # $conf['allow_authorize_operations'] = FALSE; 604 | --------------------------------------------------------------------------------