phpsword / sword-bundle

Modern WordPress development with Symfony
https://getsword.com
MIT License
124 stars 4 forks source link

Trying to find env value on $_SERVER if getenv fails #32

Open Slityak opened 1 year ago

Slityak commented 1 year ago

I reopened the topic as we discussed earlier.

I'm running my project without docker, so I have installed symfony manually and then required phpsword/sword-bundle. My current setup:

All of my environment parameters are in the project's default .env file, but Symfony by default not using "putenv" while loading the .env file, so getenv('WP_ANYTHING') returns false in getenv_docker helper function.

If I add these extra lines to my composer.json, then Symfony loads ,env parameters to environment and the getenv() method works as expected. "extra": { "runtime": { "use_putenv": true }......... But this is not recommended according to the Symfony documentation: https://symfony.com/doc/current/components/runtime.html#using-options

williarin commented 1 year ago

Thank you for the explanation.

When I made the installer and this file, it was aimed at being use with Docker. I've used the official WordPress wp-config.php and changed some parameters. They also use getenv, that's why I've used it.

I've not made in-depth research on the differences between $_SERVER and getenv yet, except that getenv and putenv are not thread safe and that's the reason why Symfony discourages using them on Apache with mod_php. But for a dev environment or if you use fpm, it shouldn't be a problem.

I see some other options for your issue:

  1. the docs can be updated for the manual installation section, to recommend using "extra": { "runtime": { "use_putenv": true } with Apache
  2. an alternate wp-config-apache.php can be created in the install folder, to be used on a manual installation
  3. we remove getenv from wp-config.php, but also rename getenv_docker as it's not Docker related anymore

I'm not really sure which is better.

Slityak commented 1 year ago

I don't support point 1.), because Symfony doesn't either. They have obviously done the necessary research and made the right decision on this. The other two options are sympathetic to me, maybe 3.) better but only because manual installation is already complicated - but I haven't tested it in docker yet. I think it would be nice if the config could remain consistent and transparent as long as it doesn't come at the expense of performance or security.

The basic Wordpress doesn't restrict too much what it can run on, basically if you FTP the user to a cheap web storage site, that's fine too. Anyone who consciously chooses Symfony for development is obviously well versed in development. It's perfectly ok that the docker version is the recommended one but I myself would like to go the route of making it easy to install manually anywhere with command line + composer like Symfony. What do you think?