protected void DeployPhpAutoloader() { var iniManager = new IniFileManager(this.GetIniFilePath(), this.Logger); var phpIniAutoprependFile = this.Deployment.ExpandPaths(iniManager.GetValue("auto_prepend_file")); // Set a new autoprepend.... var autoPrependDir = Path.Combine(this.Deployment.runtimePath, "php_autoprepend_file"); Directory.CreateDirectory(autoPrependDir); // Autoprepend the default value.... if (!string.IsNullOrWhiteSpace(phpIniAutoprependFile)) { File.WriteAllText(Path.Combine(autoPrependDir, "default_auto_prepend.php"), @"<?php include_once '" + phpIniAutoprependFile.Replace("'", "\\'") + "';"); } // Autoprepend the environment variables.... these are NOT used to override any existing // settings, but to populate when missing. var environmentVariables = this.GetEnvironmentVariables(); // Create a prepend file to populate missing environemnt variables StringBuilder sb = new StringBuilder(); sb.AppendLine("<?php"); foreach (var env in environmentVariables) { sb.AppendLine(string.Format( "if (($val = getenv('{0}')) && empty($val)) {{ putenv ('{0}={1}'); }}", this.EscapePhpLiteral(env.Key), this.EscapePhpLiteral(env.Value))); } File.WriteAllText(Path.Combine(autoPrependDir, "chef_environment_autoprepend.php"), sb.ToString()); string autoprependfile = Path.Combine(this.Deployment.runtimePath, "auto_prepend_file.php"); File.WriteAllText(autoprependfile, string.Format(@"<?php $folder = '{0}'; foreach (glob(""{{$folder}}\*.php"") as $filename) {{ include $filename; }} ", autoPrependDir)); iniManager.UpdateOrCreateDirective("auto_prepend_file", autoprependfile); iniManager.Save(); }
/// <summary> /// Shared runtimes are application agnostic... /// </summary> /// <returns></returns> public void DeployRuntime() { var runtimePath = this.Deployment.runtimePath; IniFileManager inimanager = null; // Process the deployment operations foreach (KeyValuePair <string, JToken> operation in this.PhpSettings.runtime) { string type = operation.Value["type"].ToString(); switch (type) { case "dl": var config = operation.Value.castTo <Operations.ItemDownloaderConfig>(); var o = new Operations.ItemDownloader(this.Logger, config, this.Deployment.appPath); o.Execute(runtimePath); break; case "ini": // Inimanager needs to be initialized after the runtime has been downloaded (dl operation) inimanager = inimanager ?? new IniFileManager(this.GetIniFilePath(), this.Logger); var o2 = operation.Value.castTo <Operations.IniFileSettings>(); // Runtime writable was introduced at a later time, add this workaround // for the most common used values. if (o2.key.Contains("wincache.filemapdir") || o2.key.Contains("opcache.file_cache")) { o2.value = o2.value.Replace("%RUNTIME%", "%RUNTIME_WRITABLE%"); } o2.execute(inimanager, this.Deployment); break; case "file": var o3 = operation.Value.castTo <Operations.FileOperation>(); o3.execute(runtimePath); break; default: throw new Exception($"Operation type {type} not found."); } } // Add recommended PHP defaults inimanager.UpdateOrCreateDirective("expose_php", "Off"); inimanager.UpdateOrCreateDirective("mail.add_x_header", "Off"); if (string.IsNullOrWhiteSpace(inimanager.GetValue("disable_functions"))) { inimanager.UpdateOrCreateDirective("disable_functions", "exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source"); } // doc_root inimanager.Save(); // Preparar variables de entorno this.SetupEnvironmentVariables(); // Configure handlers in IIS's web.config this.deployIISHandlers(); // Deploy a command line shortcut for the PHP environment this.DeployPhpRuntimeShortcut(); }