getPhpBinary() public static method

Retrieve path to php binary
public static getPhpBinary ( ) : string
return string
Ejemplo n.º 1
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return array
  * @throws InvalidArgumentException parameter mismatch (e.g. base-url components like hostname)
  * @throws RuntimeException
  */
 protected function installMagento(InputInterface $input, OutputInterface $output)
 {
     $this->getApplication()->setAutoExit(false);
     $dialog = $this->getHelperSet()->get('dialog');
     $defaults = $this->commandConfig['installation']['defaults'];
     $useDefaultConfigParams = $this->_parseBoolOption($input->getOption('useDefaultConfigParams'));
     $sessionSave = $useDefaultConfigParams ? $defaults['session_save'] : $dialog->ask($output, '<question>Please enter the session save:</question> <comment>[' . $defaults['session_save'] . ']</comment>: ', $defaults['session_save']);
     $adminFrontname = $useDefaultConfigParams ? $defaults['admin_frontname'] : $dialog->askAndValidate($output, '<question>Please enter the admin frontname:</question> <comment>[' . $defaults['admin_frontname'] . ']</comment> ', $this->notEmptyCallback, false, $defaults['admin_frontname']);
     $currency = $useDefaultConfigParams ? $defaults['currency'] : $dialog->askAndValidate($output, '<question>Please enter the default currency code:</question> <comment>[' . $defaults['currency'] . ']</comment>: ', $this->notEmptyCallback, false, $defaults['currency']);
     $locale = $useDefaultConfigParams ? $defaults['locale'] : $dialog->askAndValidate($output, '<question>Please enter the locale code:</question> <comment>[' . $defaults['locale'] . ']</comment>: ', $this->notEmptyCallback, false, $defaults['locale']);
     $timezone = $useDefaultConfigParams ? $defaults['timezone'] : $dialog->askAndValidate($output, '<question>Please enter the timezone:</question> <comment>[' . $defaults['timezone'] . ']</comment>: ', $this->notEmptyCallback, false, $defaults['timezone']);
     $adminUsername = $useDefaultConfigParams ? $defaults['admin_username'] : $dialog->askAndValidate($output, '<question>Please enter the admin username:</question> <comment>[' . $defaults['admin_username'] . ']</comment>: ', $this->notEmptyCallback, false, $defaults['admin_username']);
     $adminPassword = $useDefaultConfigParams ? $defaults['admin_password'] : $dialog->askAndValidate($output, '<question>Please enter the admin password:</question> <comment>[' . $defaults['admin_password'] . ']</comment>: ', $this->notEmptyCallback, false, $defaults['admin_password']);
     $adminFirstname = $useDefaultConfigParams ? $defaults['admin_firstname'] : $dialog->askAndValidate($output, '<question>Please enter the admin\'s firstname:</question> <comment>[' . $defaults['admin_firstname'] . ']</comment>: ', $this->notEmptyCallback, false, $defaults['admin_firstname']);
     $adminLastname = $useDefaultConfigParams ? $defaults['admin_lastname'] : $dialog->askAndValidate($output, '<question>Please enter the admin\'s lastname:</question> <comment>[' . $defaults['admin_lastname'] . ']</comment>: ', $this->notEmptyCallback, false, $defaults['admin_lastname']);
     $adminEmail = $useDefaultConfigParams ? $defaults['admin_email'] : $dialog->askAndValidate($output, '<question>Please enter the admin\'s email:</question> <comment>[' . $defaults['admin_email'] . ']</comment>: ', $this->notEmptyCallback, false, $defaults['admin_email']);
     $validateBaseUrl = function ($input) {
         if (!preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $input)) {
             throw new InvalidArgumentException('Please enter a valid URL');
         }
         if (parse_url($input, \PHP_URL_HOST) == 'localhost') {
             throw new InvalidArgumentException('localhost cause problems! Please use 127.0.0.1 or another hostname');
         }
         return $input;
     };
     $baseUrl = $input->getOption('baseUrl') !== null ? $input->getOption('baseUrl') : $dialog->askAndValidate($output, '<question>Please enter the base url:</question> ', $validateBaseUrl, false);
     $baseUrl = rtrim($baseUrl, '/') . '/';
     // normalize baseUrl
     /**
      * Correct session save (common mistake)
      */
     if ($sessionSave == 'file') {
         $sessionSave = 'files';
     }
     /**
      * Try to create session folder
      */
     $defaultSessionFolder = $this->config['installationFolder'] . DIRECTORY_SEPARATOR . 'var/session';
     if ($sessionSave == 'files' && !is_dir($defaultSessionFolder)) {
         @mkdir($defaultSessionFolder);
     }
     $dbHost = $this->config['db_host'];
     if ($this->config['db_port'] != 3306) {
         $dbHost .= ':' . $this->config['db_port'];
     }
     $argv = array('license_agreement_accepted' => 'yes', 'locale' => $locale, 'timezone' => $timezone, 'db_host' => $dbHost, 'db_name' => $this->config['db_name'], 'db_user' => $this->config['db_user'], 'db_pass' => $this->config['db_pass'], 'db_prefix' => $this->config['db_prefix'], 'url' => $baseUrl, 'use_rewrites' => 'yes', 'use_secure' => 'no', 'secure_base_url' => '', 'use_secure_admin' => 'no', 'admin_username' => $adminUsername, 'admin_lastname' => $adminLastname, 'admin_firstname' => $adminFirstname, 'admin_email' => $adminEmail, 'admin_password' => $adminPassword, 'session_save' => $sessionSave, 'admin_frontname' => $adminFrontname, 'backend_frontname' => $adminFrontname, 'default_currency' => $currency, 'skip_url_validation' => 'yes');
     if ($useDefaultConfigParams) {
         if (strlen($defaults['encryption_key']) > 0) {
             $argv['encryption_key'] = $defaults['encryption_key'];
         }
         if (strlen($defaults['use_secure']) > 0) {
             $argv['use_secure'] = $defaults['use_secure'];
             $argv['secure_base_url'] = str_replace('http://', 'https://', $baseUrl);
         }
         if (strlen($defaults['use_rewrites']) > 0) {
             $argv['use_rewrites'] = $defaults['use_rewrites'];
         }
     }
     $installArgs = '';
     foreach ($argv as $argName => $argValue) {
         $installArgs .= '--' . $argName . ' ' . escapeshellarg($argValue) . ' ';
     }
     $output->writeln('<info>Start installation process.</info>');
     $phpExec = OperatingSystem::getPhpBinary();
     $installCommand = $phpExec . ' -f ' . escapeshellarg($this->getInstallScriptPath()) . ' -- ' . $installArgs;
     $output->writeln('<comment>' . $installCommand . '</comment>');
     Exec::run($installCommand, $installationOutput, $returnStatus);
     if ($returnStatus !== self::EXEC_STATUS_OK) {
         $this->getApplication()->setAutoExit(true);
         throw new RuntimeException('Installation failed.' . $installationOutput, 1);
     } else {
         $output->writeln('<info>Successfully installed Magento</info>');
         $encryptionKey = trim(substr($installationOutput, strpos($installationOutput, ':') + 1));
         $output->writeln('<comment>Encryption Key:</comment> <info>' . $encryptionKey . '</info>');
     }
     $dialog = $this->getHelperSet()->get('dialog');
     /**
      * Htaccess file
      */
     if ($input->getOption('useDefaultConfigParams') == null || $input->getOption('replaceHtaccessFile') != null) {
         $replaceHtaccessFile = false;
         if ($this->_parseBoolOption($input->getOption('replaceHtaccessFile'))) {
             $replaceHtaccessFile = true;
         } elseif ($dialog->askConfirmation($output, '<question>Write BaseURL to .htaccess file?</question> <comment>[n]</comment>: ', false)) {
             $replaceHtaccessFile = true;
         }
         if ($replaceHtaccessFile) {
             $this->replaceHtaccessFile($baseUrl);
         }
     }
     \chdir($this->config['installationFolder']);
     $this->getApplication()->reinit();
     $output->writeln('<info>Reindex all after installation</info>');
     $this->getApplication()->run(new StringInput('index:reindex:all'), $output);
     $this->getApplication()->run(new StringInput('sys:check'), $output);
     $output->writeln('<info>Successfully installed magento</info>');
 }
Ejemplo n.º 2
0
 /**
  * Invoke Magento PHP install script shell/install.php
  *
  * @param OutputInterface $output
  * @param string $installationFolder folder where magento is installed in, must exists setup script in
  * @param array $argv
  * @return void
  */
 private function runInstallScriptCommand(OutputInterface $output, $installationFolder, array $argv)
 {
     $installArgs = '';
     foreach ($argv as $argName => $argValue) {
         $installArgs .= '--' . $argName . ' ' . escapeshellarg($argValue) . ' ';
     }
     $output->writeln('<info>Start installation process.</info>');
     $installCommand = sprintf('%s -ddisplay_startup_errors=1 -ddisplay_errors=1 -derror_reporting=-1 -f %s -- %s', OperatingSystem::getPhpBinary(), escapeshellarg($installationFolder . '/' . self::MAGENTO_INSTALL_SCRIPT_PATH), $installArgs);
     $output->writeln('<comment>' . $installCommand . '</comment>');
     $installException = null;
     $installationOutput = null;
     $returnStatus = null;
     try {
         Exec::run($installCommand, $installationOutput, $returnStatus);
     } catch (Exception $installException) {
     }
     if (isset($installException) || $returnStatus !== Exec::CODE_CLEAN_EXIT) {
         $this->getApplication()->setAutoExit(true);
         throw new RuntimeException(sprintf('Installation failed (Exit code %s). %s', $returnStatus, $installationOutput), 1, $installException);
     }
     $output->writeln('<info>Successfully installed Magento</info>');
     $encryptionKey = trim(substr(strstr($installationOutput, ':'), 1));
     $output->writeln('<comment>Encryption Key:</comment> <info>' . $encryptionKey . '</info>');
 }