Play Framework FAQ: Can you share an example of a Play Framework 2.6 startup script, i.e., a shell script that shows the commands and parameters you use to run a Play Framework application?
Sure. Assuming that you created a production mode version of your application with the sbt dist
command, deployed that zip file to a production server, and have a Play Framework 2.6 application named “myapp,” you can put a command like this in a Unix/Linux shell script to start your Play application:
nohup \
myapp-1.0-SNAPSHOT/bin/myapp \
-Dplay.http.secret.key='YOUR_APPLICATION_SECRET_HERE' \
-Dhttp.port=5150 \
-J-Xms128M \
-J-Xmx256m \
-J-server \
-Dconfig.file=/var/www/myapp/myapp.conf \
&
Of course you can change some of those parameters as need be, but that gives you a basic idea of how to:
- Run the Play Framework 2.6 “run” command (i.e., myapp-1.0-SNAPSHOT/bin/myapp)
- How to set the Play Framework secret key
- How to set the port your Play Framework application runs on
- How to set several JVM parameters
- How to specify the location of your production-mode configuration file
A Play Framework 2.6 production mode configuration file
To go along with that shell script, here’s an example of a Play Framework production-mode configuration file:
include "application.conf"
# can set the secret key here, if you prefer
#play.http.secret.key="foobar"
# needed to make play happy
# see: stackoverflow.com/questions/45070168/host-not-allowed-error-when-deploying-a-play-framework-application-to-amazon-a
# see: www.playframework.com/documentation/2.6.x/AllowedHostsFilter
# “As of Play 2.6.x, the Allowed Hosts filter is included in Play’s list of default filters”
play.filters.hosts {
allowed = [".myapp.com"]
}
# can also try "127.0.0.1:9000"
# i had to restart nginx after making changes here
# mysql
# db.default.url="mysql://user:password@localhost/database"
# note: only works when i manually override all three of these; the first is not enough
db.default.url="mysql://my_username: my_password@localhost/my_database"
db.default.username="my_username"
db.default.password="my_password"
# set other production mode variables ...
webapp.title = "My Web App"
webapp.description = "A description of my web app ..."
Summary
In summary, if you wanted to see an example of a Play Framework 2.6 startup script that calls the Play “run” command, I hope this is helpful.