This post shows how to deploy a Play! application to a server that is running Apache2, mostly as a note to myself.
My server hosts multiple domains, and I want the Play! application to run on the example.org domain (which is, obviously, merely an example domain name). The other domains are being served by Apache, so just starting Play! on port 80 is not an option — it’s already in use. Instead, we will let run Play! on the default port (9000) and have Apache translate requests to example.org to the Play! instance. Apache, in this case, takes the role of a reverse proxy.
Prepare the Play! application
I’ll assume you’ve installed Play! on your server and uploaded the Play! application you want to run on it. Then change to the application’s directory and create an id for this specific deployment:
Just enter a name you associate with your server, e.g., server1.
Now open the conf/application.conf file and add some deployment-specific options using the newly created id.
Tell Play! to launch the application in production mode on this server:
Give database credentials, e.g., for a MySQL database server:
Tell JPA to only create the database schema once when it’s empty — so it doesn’t try updating it on its own:
Finally tell Play! that it will be behind a reverse proxy which we’ll configure in a second:
If you so wished, you could now also change the port the Play! application will run on. This would be necessary when having multiple Play! applications running on the same server.
Now start Play! so Apache will find it running when we restart it later:
This starts the Play! application in the background. You stop it using ´play stop´, restart it using ´play restart´, and ´play status´ will give you some information on the current state of the application.
Make Apache a reverse proxy
Apache2 organizes configuration files into sites, probably to be found in /etc/apache2/sites-available and activated by being linked to in /etc/apache2/sites-enabled. Open the configuration file for the site in question and, for the example.org virtual host, add the ProxyPass and ProxyPassReverse directives. Your site configuration might look like this, then:
1 2 3 4 5
Now we need to add some additional modules to Apache so it actually knows how to do what we tell it to. All it takes is adding three soft links in the /etc/apache2/mods-enabled directory:
1 2 3
Now restart Apache like so:
And that’s it — opening http://example.org in your web browser should now bring up your Play! application.