diff options
author | Phil Burton <phil@pgburton.com> | 2017-08-20 01:42:41 +0100 |
---|---|---|
committer | Phil Burton <phil@pgburton.com> | 2017-08-20 01:42:41 +0100 |
commit | 3219d077917b1a6cb01a8cbdd288b71e515717a6 (patch) | |
tree | a1e26ab25d565d73eadfce8d01acfecc21cbaa82 |
inital commit
-rw-r--r-- | new-site.php | 68 | ||||
-rw-r--r-- | nginx.php | 21 |
2 files changed, 89 insertions, 0 deletions
diff --git a/new-site.php b/new-site.php new file mode 100644 index 0000000..0568f8a --- /dev/null +++ b/new-site.php @@ -0,0 +1,68 @@ +<?php + +// A script to make a new site +// TODO: +// Nginx conf +// Git repo +// Directory structure + +// Handle options +$options = getopt('d:n:'); + +if (!array_key_exists('d', $options)) { + echo "please provide a domain (-d)\n"; + exit(1); +} + +if (!array_key_exists('n', $options)) { + echo "please provide a name (-n)\n"; + exit(1); +} + +$domain = $options['d']; +$name = $options['n']; + +$conf = include_once('nginx.php'); + +$conf = sprintf($conf[0], $domain, $name, $name, $name, $name, $name); + +echo "Making directory structure\n"; + +if (!mkdir('/web/sites/' . $name)) { + echo "Failed to create '/web/sites/'" . $name . "\n"; + exit(1); +} + +chown('/web/sites/' . $name, "nginx"); + +if (!mkdir('/web/sites/' . $name . '/logs')) { + echo "Failed to create '/web/sites/'" . $name . "/logs\n"; + exit(1); +} + +chown('/web/sites/' . $name . '/logs', "nginx"); + + +if (!mkdir('/web/sites/' . $name . '/web')) { + echo "Failed to create '/web/sites/'" . $name . "/web\n"; + exit(1); +} + +chown('/web/sites/' . $name . '/logs', "nginx"); + +echo "Complete\n"; + +if (!file_put_contents("/web/etc/nginx/" . $name . ".conf", $conf)) { + echo "Failed to write nginx conf\n"; +} + +chown('/web/etc/nginx/' . $name . ".conf", "nginx"); + +touch('/web/sites/' . $name . '/logs/' . $name . '.access_log'); +chown('/web/sites/' . $name . '/logs/' . $name . '.access_log', "nginx"); + +touch('/web/sites/' . $name . '/logs/' . $name . '.error_log'); +chown('/web/sites/' . $name . '/logs/' . $name . '.error_log', "nginx"); + +touch('/web/sites/' . $name . '/web/index.php'); +chown('/web/sites/' . $name . '/web/index.php', "nginx"); diff --git a/nginx.php b/nginx.php new file mode 100644 index 0000000..e362fb3 --- /dev/null +++ b/nginx.php @@ -0,0 +1,21 @@ +<?php + +return [ + "server { + listen *; + server_name %s; + + access_log /web/sites/%s/logs/%s.access_log main; + error_log /web/sites/%s/logs/%s.error_log info; + + root /web/sites/%s/web; + + location ~ \.php$ { + # Test for non-existent scripts or throw a 404 error + # Without this line, nginx will blindly send any request ending in .php to php-fpm + try_files \$uri =404; + include /etc/nginx/fastcgi.conf; + fastcgi_pass unix:/run/php7-fpm.sock; + } +}" +]; |