Zero-config Rails and PHP with puma-dev

With puma-dev you can make any number of Rack/Rails applications available simply by creating symlinks. However, this blocks port 80, making it unavailable for Apache. Fortunately, puma-dev not only supports symlinks to Rack apps but also allows creating files within ~/.puma-dev/ that contain an alternative port number. This way, all applications that should be handled by Apache instead of puma-dev – such as PHP apps and static sites – can be set up as files containing just 81. Additionally, you need to configure Apache to listen on port 81. Here are the required steps:

Apache configuration /etc/apache2/httpd.conf

Apache should listen on port 81:

Listen 81

The modules for virtual hosts, rewrite, and PHP should be enabled:

LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule php7_module libexec/apache2/libphp7.so
Include /private/etc/apache2/extra/httpd-vhosts.conf

Virtual Hosts configuration /etc/apache2/extra/httpd-vhosts.conf

<VirtualHost 127.0.0.1:81>
  ServerName any.dev
  ServerAlias *.dev
  UseCanonicalName Off
  VirtualDocumentRoot "/Users/{username}/Sites/%1"
  <Directory "/Users/{username}/Sites/*">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
    Require all granted
  </Directory>
</VirtualHost>

Assuming your desired PHP application is located in the directory /Users/{username}/Sites/my-app/. If you create a file ~/.puma-dev/my-app with the content 81, the app will be available at http://my-app.test served through Apache. Happy hacking!