/** * Manages php builds via phpbrew * * @param $meta * @throws \Exception */ protected function managePhp($meta) { $fs = Util::getFilesystem(); if (!$meta['installed']) { $this->output->writeInfo("Removing php {$meta['_build']}"); // php fpm has to be stopped before remving php build so that // the php-fpm.pid file is still exist $this->stopFpm($meta['_build']); $proc = $this->runScript('php.remove', $meta['_build']); if ($proc->isSuccessful()) { $this->output->writeInfo("Successfully removed php"); } else { throw new \Exception("Unable to remove php"); } SyncManager::removeRule($meta['_path'], true, true); $fs->remove($meta['_path']); return; } else { $this->output->writeInfo("Checking php {$meta['_build']}"); } if (!isset($meta['version'])) { $meta['version'] = $meta['_build']; } if (!empty($meta['_old']) && !isset($meta['_old']['version'])) { $meta['_old']['version'] = $meta['_build']; } if (!preg_match('/^[0-9][0-9\\.]*[0-9]$/', $meta['version'])) { throw new \Exception("Invalid php version {$meta['version']}"); } if (version_compare($meta['version'], '5.3.0') < 0) { throw new \Exception("Building php versions older than 5.3.0 is not supported"); } if (empty($meta['variants'])) { throw new \Exception("Build variants for php {$meta['_build']} are not defined in environment.yaml file"); } if (!is_array($meta['variants'])) { $meta['variants'] = [$meta['variants']]; } if (!empty($meta['_old']) && !is_array($meta['_old']['variants'])) { $meta['_old']['variants'] = [$meta['_old']['variants']]; } if ($meta['_is_installed'] && !empty($meta['_old']) && $meta['_old']['version'] == $meta['version'] && $meta['_old']['variants'] == $meta['variants']) { return; } $this->output->writeInfo("Building php from source"); $this->output->writeInfo("This may take a while depending on your cpu(s)..."); foreach ($meta['variants'] as $i => $variant) { if (false === strpos($variant, '--', 0)) { $meta['variants'][$i] = '+' . $variant; } } // stop php-fpm if we are rebuilding php if ($meta['_is_installed']) { $this->stopFpm($meta['_build']); } $proc = $this->runScript('php.install', $meta['_build'], $meta['version'], implode(" ", $meta['variants'])); if ($proc->isSuccessful() && file_exists($meta['_path'] . '/bin/php')) { // we need this directory to be available right after successfull build // since phpbrew doesn't make this directory by default $fs->mkdir($meta['_path'] . '/var/db', 0755, 'vagrant'); $this->output->writeInfo("Successfully built php"); // Get a copy of the log file $log_from = "/opt/phpbrew/build/{$meta['_build']}/build.log"; $log_to = "/vagrant/provision/main/logs/phpbuild-{$meta['_build']}.log"; $fs->copy($log_from, $log_to, true); $this->output->writeInfo("Saved build log file to {$log_to}"); } else { $fs->remove($meta['_path']); throw new \Exception("Unable to build php"); } // @todo fix code duplication issue since this code is already defined in initTask if (!$meta['_is_installed']) { SyncManager::addRule(SyncManager::SYNC_FILE, ['path' => "/opt/phpbrew/php/{$meta['_build']}/etc/php.ini", 'source' => "/vagrant/config/phpbrew/{$meta['_build']}/php.ini", 'default' => "/opt/phpbrew/php/{$meta['_build']}/etc/php.ini", 'owner' => 'vagrant', 'group' => 'vagrant']); SyncManager::addRule(SyncManager::SYNC_FILE, ['path' => "/opt/phpbrew/php/{$meta['_build']}/etc/php-fpm.conf", 'source' => "/vagrant/config/phpbrew/{$meta['_build']}/php-fpm.conf", 'default' => "/opt/phpbrew/php/{$meta['_build']}/etc/php-fpm.conf", 'owner' => 'vagrant', 'group' => 'vagrant']); SyncManager::addRule(SyncManager::SYNC_DIR, ['path' => "/opt/phpbrew/php/{$meta['_build']}/var/db", 'source' => "/vagrant/config/phpbrew/{$meta['_build']}/conf.d", 'default' => "/opt/phpbrew/php/{$meta['_build']}/var/db", 'owner' => 'vagrant', 'group' => 'vagrant']); } }