How To Enable PHP 5.4 on OpenShift - Archived

I was introduced to OpenShift at #MongoDBMunich last month and had to try it out. It looked very good to me and I hope to see this project evolve.

When I first tried it, I immediatly spotted the “old” PHP version. It’s not really old and is still usable, but for State-of-the-Art development and certain frameworks (e.g. Symfony 2.1) you need a newer version. I talked to the OpenShift guys and they pointed me to the “Do-It-Yourself” cartridge which is designed to be used to install whatever you want as an application stack. You don’t get root access (of course), so you have to compile the stuff you need yourself without relying on a paket manager.

I will split this tutorial into a series with three articles that show you how to get PHP 5.4 working, launch a Symfony2 application, and add Jenkins to test a PHP project.

Enabling PHP 5.4

Installing Apache and PHP without a package manager is pretty easy. Just run the configure script and then make install and you are done! Almost. Of course there are dependencies which you have to resolve by yourself. Normaly your package manager will do this for you, so now you are on your own.

If you are not interested in details and just want to run PHP 5.4 (actually it’s 5.4.7 with Apache 2.4.3), you can use my openshift-php54 repository on github. It comes with a readme and some installation instructions and has an install script, which takes care of everything, getting you up and running without any effort. For everyone interested in the process, please read on.

Compiling Apache and PHP

To get apache compiling I had to first compile apr and apr-utils as well as PCRE 8 (Apache 2.4 needs at least 7.8). APR must be moved into the apache folder in a folder called srclib. The path where PCRE is located must be passed to the apache compile script with the –with-pcre= option.

Because I have in mind to run Symfony2 on OpenShift, I wanted to install PHP with the intl extension. This was rather hard as it has dependencies on ICU. After installing ICU, I couldn’t get the compiler to recognize it. Several tries and some searches later I found out I need to pass the –with-icu-dir= option when running configure.

Afterwards PHP compiled without problems. I don’t have any idea on how to go on if I want to use different php.ini files for apache and cli. Right now the default php.ini gets used in any case. If you can tell me how to do this or have some resources on this topic, please let me know!

I also added the apc extension by following an instruction from a comment on It worked without any issues except that the command to configure apc is not “config” but “configure”.

Everything there is left are moving files and changing configurations. You should edit the httpd.conf and php.ini. You should also cleanup your installation files as they take a lot of space and you don’t need them anymore (at least not till your next compile).

The last step would be to place proper openshift hooks so apache gets stopped and started again when deploying. Have a look at my hooks in the repository mentioned above. For starting apache, you can edit the start hook like this:

$OPENSHIFT_HOMEDIR/app-root/runtime/srv/httpd/bin/apachectl start > $OPENSHIFT_DIY_LOG_DIR/server.log 2>&1 &

As you can see, it executes apachectl, logging into the server.log file. Stopping apache can be added to the stop script:

$OPENSHIFT_RUNTIME_DIR/srv/httpd/bin/apachectl stop > /dev/null 2>&1

Ready for takeoff

Now place your php files inside the diy folder of your repo. In the sample repository, you can see two files I placed there for testing purpose. My phpinfo.php can be retrieved from my test application.

The next step will be to get a clean Symfony2 installation up and running on OpenShift. So be sure to read it, as there are some pitfalls (like symlinks to persisting data like logs or the vendor folder) that can make this a challenge. You may also want to consider creating a build script to copy and change the configuration files (for example, paramters.yml). All this will be covered in the next article.

Jenkins, PHP
Comments are closed.