protected function execute(InputInterface $input, OutputInterface $output) { $dialog = $this->getHelperSet()->get('dialog'); $output->writeln("<info>" . "Welcome! amp will help setup your PHP applications by creating\n" . "databases and virtual-hosts. amp is intended for use during\n" . "development and testing.\n" . "\n" . "Please fill in a few configuration options so that we can properly\n" . "install the PHP application." . "</info>"); $output->writeln(""); $output->writeln("<info>=============================[ Configure Database ]=============================</info>"); $output->writeln(""); $output->writeln("<info>" . "Amp creates a unique database user for each generated instance.\n" . "To accomplish this amp needs GRANT-level privileges. It is\n" . "recommended that you supply the root/administrator credentials\n" . "for this task. If you wish to create a new user for amp to use\n" . "please assign it appropriate privileges eg:\n\n" . "MySQL: <fg=cyan;bg=black;option=bold>GRANT ALL ON *.* to '#user'@'localhost' IDENTIFIED BY '#pass' WITH GRANT OPTION</fg=cyan;bg=black;option=bold>\n" . "PgSQL: <fg=cyan;bg=black;option=bold>\$ createuser --superuser --createdb --createrole -P #user</fg=cyan;bg=black;option=bold>\n" . " <fg=cyan;bg=black;option=bold>Add 'local all #user md5' to pg_hba.conf</fg=cyan;bg=black;option=bold>\n" . " <fg=cyan;bg=black;option=bold>Test \$ psql -U #user -W template1</fg=cyan;bg=black;option=bold>" . "</info>"); $this->askDbType()->execute($input, $output, $dialog); $db_type = $this->getContainer()->getParameter('db_type'); if (in_array($db_type, array('mysql_dsn', 'pg_dsn'))) { $this->askDbDsn()->execute($input, $output, $dialog); } $output->writeln(""); $output->writeln("<info>=======================[ Configure File Permissions ]========================</info>"); $output->writeln(""); $currentUser = \Amp\Util\User::getCurrentUser(); $output->writeln("<info>" . "It appears that you are currently working as user \"{$currentUser}\".\n" . "\n" . "If the web server executes PHP requests as the same user, then no special\n" . "permissions are required.\n" . "\n" . "If the web server executes PHP requests as a different user (such as\n" . "\"www-data\" or \"apache\"), then special permissions will be required\n" . "for any web-writable data directories." . "</info>"); $this->askPermType()->execute($input, $output, $dialog); switch ($this->config->getParameter("perm_type")) { case 'linuxAcl': case 'osxAcl': $this->askPermUser()->execute($input, $output, $dialog); break; case 'custom': $this->askPermCommand()->execute($input, $output, $dialog); break; default: break; } $output->writeln(""); $output->writeln("<info>=============================[ Configure Hostnames ]=============================</info>"); $output->writeln("<info>" . "When defining a new vhost (e.g. \"http://example-1.localhost\"), the hostname must\n" . "be mapped to an IP address.\n" . "\n" . "amp can attempt to register hostnames automatically in the /etc/hosts file.\n" . "However, if you use wildcard DNS, dnsmasq, or manually manage hostnames, then\n" . "this feature can be disabled.\n" . "</info>"); $this->askHostsType($this->getContainer()->getParameter('hosts_file'), $this->getContainer()->getParameter('hosts_ip'))->execute($input, $output, $dialog); $output->writeln(""); $output->writeln("<info>=============================[ Configure HTTPD ]=============================</info>"); $this->askHttpdType()->execute($input, $output, $dialog); switch ($this->config->getParameter('httpd_type')) { case 'apache': case 'apache24': case 'nginx': $output->writeln("<info>\n" . "Whenever you create a new vhost, you may need to restart the web server.\n" . "Amp can do this automatically if you specify a command.\n" . "\n" . "NOTE: Commands based on `sudo` may require you to enter a password periodically.\n" . "</info>"); $this->askHttpdRestartCommand()->execute($input, $output, $dialog); break; default: } switch ($this->config->getParameter('httpd_type')) { case 'apache': case 'apache24': $configPath = $this->getContainer()->getParameter('apache_dir'); $output->writeln(""); $output->writeln("<comment>Note</comment>: Please add this line to the httpd.conf or apache2.conf:"); $output->writeln(""); $output->writeln(" <comment>Include {$configPath}/*.conf</comment>"); $configFiles = $this->findApacheConfigFiles(); if ($configFiles) { $output->writeln(""); $output->writeln("The location of httpd.conf varies, but it may be:"); $output->writeln(""); foreach ($configFiles as $configFile) { $output->writeln(" <comment>{$configFile}</comment>"); } } $output->writeln(""); $output->writeln("You will need to restart Apache after adding the directive -- and again"); $output->writeln("after creating any new sites."); break; case 'nginx': $configPath = $this->getContainer()->getParameter('nginx_dir'); $output->writeln(""); $output->writeln("<comment>Note</comment>: Please ensure that nginx.conf includes this directive:"); $output->writeln(""); $output->writeln(" <comment>include {$configPath}/*.conf;</comment>"); $configFiles = $this->findNginxConfigFiles(); if ($configFiles) { $output->writeln(""); $output->writeln("The location of nginx.conf varies, but it may be:"); $output->writeln(""); foreach ($configFiles as $configFile) { $output->writeln(" <comment>{$configFile}</comment>"); } } $output->writeln(""); $output->writeln("You will need to restart nginx after adding the directive -- and again"); $output->writeln("after creating any new sites."); break; default: } $output->writeln(""); $output->writeln("<info>===================================[ Test ]==================================</info>"); $output->writeln(""); $output->writeln("To ensure that amp is correctly configured, you may create a test site by running:"); $output->writeln(""); $output->writeln(" <comment>amp test</comment>"); // FIXME: auto-detect "amp" vs "./bin/amp" vs "./amp" $this->config->save(); }
protected function execute(InputInterface $input, OutputInterface $output) { $dialog = $this->getHelperSet()->get('dialog'); $output->writeln("<info>" . "Welcome! amp will help setup your PHP applications by creating\n" . "databases and virtual-hosts. amp is intended for use during\n" . "development and testing.\n" . "\n" . "Please fill in a few configuration options so that we can properly\n" . "install the PHP application." . "</info>"); $output->writeln(""); $output->writeln("<info>=============================[ Configure MySQL ]=============================</info>"); $output->writeln(""); $output->writeln("<info>" . "Amp creates a unique MySQL user for each generated instance.\n" . "To accomplish this amp needs GRANT-level privileges. It is\n" . "recommended that you supply the root/administrator credentials\n" . "for this task. If you wish to create a new user for amp to use\n" . "please assign it appropriate privileges eg:\n\n" . "<fg=cyan;bg=black;option=bold>GRANT ALL ON *.* to '#user'@'localhost' IDENTIFIED BY '#pass' WITH GRANT OPTION</fg=cyan;bg=black;option=bold>" . "</info>"); $this->config->setParameter('mysql_type', 'dsn'); // temporary limitation $this->askMysqlDsn()->execute($input, $output, $dialog); $output->writeln(""); $output->writeln("<info>=======================[ Configure File Permissions ]========================</info>"); $output->writeln(""); $currentUser = \Amp\Util\User::getCurrentUser(); $output->writeln("<info>" . "It appears that you are currently working as user \"{$currentUser}\".\n" . "\n" . "If the web server executes PHP requests as the same user, then no special\n" . "permissions are required.\n" . "\n" . "If the web server executes PHP requests as a different user (such as\n" . "\"www-data\" or \"apache\"), then special permissions will be required\n" . "for any web-writable data directories." . "</info>"); $this->askPermType()->execute($input, $output, $dialog); switch ($this->config->getParameter("perm_type")) { case 'linuxAcl': case 'osxAcl': $this->askPermUser()->execute($input, $output, $dialog); break; case 'custom': $this->askPermCommand()->execute($input, $output, $dialog); break; default: break; } $output->writeln(""); $output->writeln("<info>=============================[ Configure HTTPD ]=============================</info>"); $this->askHttpdType()->execute($input, $output, $dialog); switch ($this->config->getParameter('httpd_type')) { case 'apache': case 'apache24': $configPath = $this->getContainer()->getParameter('apache_dir'); $output->writeln(""); $output->writeln("<comment>Note</comment>: Please add this line to the httpd.conf or apache2.conf:"); $output->writeln(""); $output->writeln(" <comment>Include {$configPath}/*.conf</comment>"); $configFiles = $this->findApacheConfigFiles(); if ($configFiles) { $output->writeln(""); $output->writeln("The location of httpd.conf varies, but it may be:"); $output->writeln(""); foreach ($configFiles as $configFile) { $output->writeln(" <comment>{$configFile}</comment>"); } } $output->writeln(""); $output->writeln("You will need to restart Apache after adding the directive -- and again"); $output->writeln("after creating any new sites."); break; case 'nginx': $configPath = $this->getContainer()->getParameter('nginx_dir'); $output->writeln(""); $output->writeln("<comment>Note</comment>: Please ensure that nginx.conf includes this directive:"); $output->writeln(""); $output->writeln(" <comment>Include {$configPath}/*.conf</comment>"); $configFiles = $this->findNginxConfigFiles(); if ($configFiles) { $output->writeln(""); $output->writeln("The location of nginx.conf varies, but it may be:"); $output->writeln(""); foreach ($configFiles as $configFile) { $output->writeln(" <comment>{$configFile}</comment>"); } } $output->writeln(""); $output->writeln("You will need to restart nginx after adding the directive -- and again"); $output->writeln("after creating any new sites."); break; default: } $output->writeln(""); $output->writeln("<info>===================================[ Test ]==================================</info>"); $output->writeln(""); $output->writeln("To ensure that amp is correctly configured, you may create a test site by running:"); $output->writeln(""); $output->writeln(" <comment>amp test</comment>"); // FIXME: auto-detect "amp" vs "./bin/amp" vs "./amp" $this->config->save(); }