This is an example application which can be run on CloudFoundry using the PHP Build Pack.
This is an out-of-the-box implementation of PHPMyAdmin 4.2.2. It's an example how common PHP applications can easily be run on CloudFoundry.
- Clone the app (i.e. this repo).
git clone https://github.com/dmikusa-pivotal/cf-ex-phpmyadmin
cd cf-ex-phpmyadmin
- 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.
cf create-service cleardb spark my-test-mysql-db
-
Edit the manifest.yml file. Change the 'host' attribute to something unique. Then under "services:" change "mysql-db" to the name of your MySQL service. This is the name of the service that will be bound to your application and thus available to PHPMyAdmin.
-
Push it to CloudFoundry.
cf push
Access your application URL in the browser. Login with the credentials for your service. If you need to find these, just run this command and look for the VCAP_SERVICES environment variable under the System Provided
section.
cf env <app-name>
When you push the application here's what happens.
- The local bits are pushed to your target. This is small, six files around 30k. It includes the changes we made and a build pack extension for PHPMyAdmin.
- The server downloads the PHP Build Pack and runs it. This installs HTTPD and PHP.
- The build pack sees the extension that we pushed and runs it. The extension downloads the stock PHPMyAdmin 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 PHPMyAdmin files with them. In this case, it's just theconfig.inc.php
file. - At this point, the build pack is done and CF runs our droplet.
These changes were made to prepare it to run on CloudFoundry:
- Configure the database in
config.inc.php
. This was done by reading the environment variable VCAP_SERVICES, which is populated by CloudFoundry and contains the connection information for our services, and configuring the host, port from it. See this link for the details. - Remove the setup directory, which is not needed.
- Override the configuration file httpd-directories.conf and prevent access to the libraries directory. See this link for the details.
- Set the 'PmaAbsoluteUri' configuration option. This is needed because the application is using the detected host and port, which are internal to CF, to generate in the URLs. The links generated with the internal ip / port do not work and so we configure around that by grabbing the application's URL and port. Note that this would not work if multiple URL's were bound to the application. Link
- Increased the timeout of the session by setting 'LoginCookieValidity' and 'session.gc_maxlifetime' to 1800. Link to change #1 and change #2.