CloudFoundry PHP Example Application: PHPMyAdmin
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.8.3. 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/cloudfoundry-samples/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 mysql
If you have an existing DB service with some arbitary name, please re-name the service such that it contains the string
config.inc.phpfile will automatically configure MySQL services if the plan is ClearDb or Pivotal MySQL, if they are tagged with
mysqlor if the service name contains the word
mysql. If you do not follow this pattern, your MySQL service will require manual configuration.
manifest.ymlfile. Insert your service name, if it's not
mysql. Also, set the route that you would like to use.
Push it to CloudFoundry.
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>
How It Works
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
htdocsdirectory. 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 the
- 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.