Skip to content

Commit

Permalink
Merge pull request #20 from tizzo/feature/tizzo/support-fpm
Browse files Browse the repository at this point in the history
Add support for php-fpm on Apache.
  • Loading branch information
lliss committed Apr 24, 2017
2 parents 2e8aa97 + af01051 commit 7526cfc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 27 deletions.
2 changes: 2 additions & 0 deletions KEYS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ TODO: Find a good way to expose database options as command line arguments where
- 'server.disable_site_command' - The command to run to disable a site on the server (e.g. `a2dissite sitename` on ubutnu.
- 'server.enable_site_command' - The command to run to enable a site on the server (e.g. `a2ensite sitename` on ubutnu.
- 'server.port' - The port to listen on for this virtualhost.
- 'server.sapi' - The supported sapi (apache supports fpm and mod_php).
- 'server.fpm_url' - The host and port to proxy requests to if the `server.sapi` key is set to `fpm`.
- 'server.restart_command' - The command to run to reload configuration (e.g. `service apache2 restart`).
- 'server.user' - The user that the webserver runs as (e.g. `apache2` runs as `www-data` on Ubuntu).
- 'settings_file.path' - The path to the site's settings.php file.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Directory /var/www/html/<?php print $site_name; ?>/webroot/>
<Directory <?php print $docroot; ?> >
Options -Indexes
Options +FollowSymLinks
AllowOverride All
Require all granted

# Not a part of Drupal's stock .htaccess but added as a measure of security.
<FilesMatch "(^LICENSE|CHANGELOG|MAINTAINERS|INSTALL|UPGRADE|API|README).*\.txt$">
Expand All @@ -16,9 +17,12 @@
Allow from 127.0.0.1
</Files>
</Directory>
<VirtualHost *:80>
<VirtualHost *:<?php print $port; ?>>
ServerName <?php print $hostname . PHP_EOL; ?>
DocumentRoot /var/www/html/<?php print $site_name; ?>/webroot
DocumentRoot <?php print $docroot . PHP_EOL; ?>
<FilesMatch \.php$>
SetHandler proxy:fcgi://<?php print $fpm_url . PHP_EOL; ?>
</FilesMatch>
LogLevel warn
ServerSignature Off
</VirtualHost>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Options -Indexes
Options +FollowSymLinks
AllowOverride All
Require all granted

# Not a part of Drupal's stock .htaccess but added as a measure of security.
<FilesMatch "(^LICENSE|CHANGELOG|MAINTAINERS|INSTALL|UPGRADE|API|README).*\.txt$">
Expand Down
37 changes: 13 additions & 24 deletions lib/Fetcher/Server/Apache2.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ class Apache2 implements ServerInterface {
protected $site;

public function __construct(\Pimple $site) {
$site->setDefaultConfigration('server.user', 'www-data');
$site->setDefaultConfigration('server.port', 80);
$site->setDefaultConfigration('server.webroot', '/var/www');
$site->setDefaultConfigration('server.vhost_enabled_folder', '/etc/apache2/sites-enabled');
$site->setDefaultConfigration('server.vhost_available_folder', '/etc/apache2/sites-available');
$site->setDefaultConfigration('server.restart_command', 'sudo service apache2 reload');
$site->setDefaultConfigration('server.enable_site_command', function($c) {
return 'sudo a2ensite ' . $c['name'] . '.conf';
});
$site->setDefaultConfigration('server.disable_site_command', function($c) {
return 'sudo a2dissite ' . $c['name'] . '.conf';
});
$site->setDefaultConfigration('server.enable_site_command', function($c) {
return 'sudo a2ensite ' . $c['name'] . '.conf';
});
$site->setDefaultConfigration('server.host_conf_path', function($c) {
return $c['server.vhost_available_folder'] . '/' . $c['name'] . '.conf';
});
$site->setDefaultConfigration('server.fpm_url', '127.0.0.1:9000');
$site->setDefaultConfigration('server.port', 80);
$site->setDefaultConfigration('server.restart_command', 'sudo service apache2 reload');
$site->setDefaultConfigration('server.sapi', 'mod_php');
$site->setDefaultConfigration('server.user', 'www-data');
$site->setDefaultConfigration('server.vhost_enabled_folder', '/etc/apache2/sites-enabled');
$site->setDefaultConfigration('server.vhost_available_folder', '/etc/apache2/sites-available');
$site->setDefaultConfigration('server.webroot', '/var/www');
$this->site = $site;
}

/**
* Implements \Fetcher\Server\ServerInterface::registerSettings().
*
* TODO: I think this is a good idea...
*/
static public function registerSettings(\Fetcher\Site $site) {
$site->setDefaultConfigration('server.user', 'www-data');
Expand All @@ -37,35 +37,27 @@ static public function registerSettings(\Fetcher\Site $site) {

/**
* Get the user under which this server runs.
*
* TODO: This can vary based on the system.
*/
public function getWebUser() {
return 'www-data';
}

/**
* Get the parent folder where web files should be located.
*
* TODO: This can vary based on the system.
*/
public function getWebRoot() {
return '/var/www';
}

/**
* Check whether this site appears to be enabled.
*
* TODO: This can vary based on the system.
*/
public function siteIsEnabled() {
return is_link($this->site['server.vhost_enabled_folder'] . '/' . $this->site['name']);
}

/**
* Check whether this site appears to be configured and configure it if not.
*
* TODO: This can vary based on the system.
*/
public function ensureSiteConfigured() {
$site = $this->site;
Expand All @@ -75,16 +67,15 @@ public function ensureSiteConfigured() {
'hostname' => $site['hostname'],
'docroot' => $site['site.webroot'],
'port' => $site['server.port'],
'fpm_url' => $site['server.fpm_url'],
);
$content = \drush_fetcher_get_asset('drupal.vhost', $vars);
$content = \drush_fetcher_get_asset('apache.drupal.vhost.' . $site['server.sapi'], $vars);
$site['system']->writeFile($site['server.host_conf_path'], $content);
}
}

/**
* Ensure that the site is removed.
*
* TODO: Vhost deletion can vary based on the system.
*/
public function ensureSiteRemoved() {
if ($this->siteIsEnabled()) {
Expand All @@ -96,8 +87,6 @@ public function ensureSiteRemoved() {

/**
* Ensure that the configured site has been enabled.
*
* TODO: This does not exist by default on some systems.
*/
public function ensureSiteEnabled() {
$site = $this->site;
Expand Down

0 comments on commit 7526cfc

Please sign in to comment.