GenerateWebserverConfig generates the default nginx and apache config files
()
| 2337 | |
| 2338 | // GenerateWebserverConfig generates the default nginx and apache config files |
| 2339 | func (app *DdevApp) GenerateWebserverConfig() error { |
| 2340 | // Prevent running as root for most cases |
| 2341 | // We really don't want ~/.ddev to have root ownership, breaks things. |
| 2342 | if os.Geteuid() == 0 { |
| 2343 | util.Warning("not generating webserver config files because running with root privileges") |
| 2344 | return nil |
| 2345 | } |
| 2346 | |
| 2347 | var items = map[string]string{ |
| 2348 | "nginx": app.GetConfigPath(filepath.Join("nginx_full", "nginx-site.conf")), |
| 2349 | "apache": app.GetConfigPath(filepath.Join("apache", "apache-site.conf")), |
| 2350 | "nginx_second_docroot_example": app.GetConfigPath(filepath.Join("nginx_full", "seconddocroot.conf.example")), |
| 2351 | "README.nginx_full.txt": app.GetConfigPath(filepath.Join("nginx_full", "README.nginx_full.txt")), |
| 2352 | "README.apache.txt": app.GetConfigPath(filepath.Join("apache", "README.apache.txt")), |
| 2353 | "apache_second_docroot_example": app.GetConfigPath(filepath.Join("apache", "seconddocroot.conf.example")), |
| 2354 | } |
| 2355 | for t, configPath := range items { |
| 2356 | err := os.MkdirAll(filepath.Dir(configPath), 0755) |
| 2357 | if err != nil { |
| 2358 | return err |
| 2359 | } |
| 2360 | |
| 2361 | if fileutil.FileExists(configPath) { |
| 2362 | sigExists, err := fileutil.FgrepStringInFile(configPath, nodeps.DdevFileSignature) |
| 2363 | if err != nil { |
| 2364 | return err |
| 2365 | } |
| 2366 | // If the signature doesn't exist, they have taken over the file, so return |
| 2367 | if !sigExists { |
| 2368 | return nil |
| 2369 | } |
| 2370 | } |
| 2371 | |
| 2372 | cfgFile := fmt.Sprintf("%s-site-%s.conf", t, app.Type) |
| 2373 | c, err := webserverConfigAssets.ReadFile(path.Join("webserver_config_assets", cfgFile)) |
| 2374 | if err != nil { |
| 2375 | c, err = webserverConfigAssets.ReadFile(path.Join("webserver_config_assets", fmt.Sprintf("%s-site-php.conf", t))) |
| 2376 | if err != nil { |
| 2377 | return err |
| 2378 | } |
| 2379 | } |
| 2380 | content := string(c) |
| 2381 | docroot := app.GetAbsDocroot(true) |
| 2382 | err = fileutil.TemplateStringToFile(content, map[string]any{"Docroot": docroot}, configPath) |
| 2383 | if err != nil { |
| 2384 | return err |
| 2385 | } |
| 2386 | } |
| 2387 | return nil |
| 2388 | } |
| 2389 | |
| 2390 | func (app *DdevApp) GeneratePostgresConfig() error { |
| 2391 | if app.Database.Type != nodeps.Postgres { |
no test coverage detected