mukadi-wordpress-bundle icon indicating copy to clipboard operation
mukadi-wordpress-bundle copied to clipboard

Unable to read the "...\match\public/wp/../.env" environment file.

Open truckee opened this issue 5 years ago • 5 comments

In a fresh installation of Symfony 4.3.4 and mbo2olivier/mukadi-wordpress-bundle per the documentation, launching the site results in the error shown in the title.

Symfony profiler's phpinfo() shows $_SERVER['APP_ENV'] =dev. There does not exist a .env file in ...\public\wp. Copying .env to ...\public\wp has no effect.

Stack trace:

Symfony\Component\Dotenv\Exception\PathException:
Unable to read the "G:\Documents\workspace\match\public/wp/../.env" environment file.

  at vendor/symfony/dotenv/Dotenv.php:484
  at Symfony\Component\Dotenv\Dotenv->doLoad(false, array('G:\\Documents\\workspace\\match\\public/wp/../.env'))
     (vendor/symfony/dotenv/Dotenv.php:65)
  at Symfony\Component\Dotenv\Dotenv->load('G:\\Documents\\workspace\\match\\public/wp/../.env')
     (vendor/mukadi/wordpress-bundle/Config.php:38)
  at Mukadi\WordpressBundle\Config->__construct('G:\\Documents\\workspace\\match\\public/wp')
     (public/wp-config.php:7)
  at require_once('G:\\Documents\\workspace\\match\\public\\wp-config.php')
     (public/wp/wp-load.php:42)
  at require_once('G:\\Documents\\workspace\\match\\public\\wp\\wp-load.php')
     (public/wp/wp-blog-header.php:13)
  at require_once('G:\\Documents\\workspace\\match\\public\\wp\\wp-blog-header.php')
     (vendor/mukadi/wordpress-bundle/Wordpress/Wordpress.php:102)
  at Mukadi\WordpressBundle\Wordpress\Wordpress->loadWordpress()
     (vendor/mukadi/wordpress-bundle/Wordpress/Wordpress.php:79)
  at Mukadi\WordpressBundle\Wordpress\Wordpress->getContent()
     (vendor/mukadi/wordpress-bundle/Wordpress/Wordpress.php:60)
  at Mukadi\WordpressBundle\Wordpress\Wordpress->initialize()
     (vendor/mukadi/wordpress-bundle/Controller/WordpressController.php:32)
  at Mukadi\WordpressBundle\Controller\WordpressController->wpAction(object(Wordpress))
     (vendor/symfony/http-kernel/HttpKernel.php:151)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:68)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/http-kernel/Kernel.php:198)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (public/index.php:45)
  at run()
     (public/index.php:49)

Edit: Changing mukadi/wordpress-bundle/Config.php:38 to: (new Dotenv())->load($path.'/../../.env'); allows getting a new error message:

Warning: Use of undefined constant WP_DEBUG - assumed 'WP_DEBUG' (this will throw an Error in a future version of PHP) in G:\Documents\workspace\match\vendor\mukadi\wordpress-bundle\Config.php on line 60

Warning: Use of undefined constant WP_DEBUG - assumed 'WP_DEBUG' (this will throw an Error in a future version of PHP) in G:\Documents\workspace\match\vendor\mukadi\wordpress-bundle\Config.php on line 61

Edit #2: Added WP_DEBUG=true to .env block ###> mukadi/wordpress-bundle ### Added define('WP_DEBUG_DISPLAY', env('WP_DEBUG_DISPLAY', WP_DEBUG)); at mukadi/wordpress-bundle/Config.php:59`

These changes eliminated the WP_DEBUG error messages.

Edit #3: As I reduce my ignorance of WordPress, creating the ...public/wp/wp-config.php file eliminates the need for any of the changes above.

truckee avatar Sep 29 '19 19:09 truckee

From Edit #3, all is now well.

Edit: Although it remains true that if one follows only the installation instructions the above errors occur. I learned this after restarting the installation. This tells me that the documentation is incomplete. Perhaps this issue should be reopened.

I restarted because I have yet to figure out how to use a single database for the application. That effort continues.

truckee avatar Sep 30 '19 17:09 truckee

Hello @truckee , sorry for that late response.

Edit #3: As I reduce my ignorance of WordPress, creating the ...public/wp/wp-config.php file eliminates the need for any of the changes above.

you don't need to create create the "public/wp/wp-config.php" file, it could be removed on a new wordpress installation, and the "public/wp/" directory is not meant to be tracked by git.

As symfony versions < 4 do not support symfony flex, you are forced to do all the configuration yourself. would not you have forgotten to add the "public/wp-config.file" file ?

Although it remains true that if one follows only the installation instructions the above errors occur. I learned this after restarting the installation. This tells me that the documentation is incomplete. Perhaps this issue should be reopened.

Thank you for the remark, I now see that the documentation is centered on an installation on symfony 4, I should update it for those who use symfony 3.4 too.

mbo2olivier avatar Oct 01 '19 16:10 mbo2olivier

Thanks for your reply.

I found that in order to use an existing schema I needed to create the wp-config.php file before WordPress installation so that my schema would have the wp_ tables.

Am I correct that ...mukadi/wordpress-bundle/Config.php:38 requires modification to add an extra parent to the directory?

Off topic: I'm also wondering about the necessity of WordPress's .htaccess file in ...\public. My project's objective is to add Symfony to a client's existing WordPress site. So I want their site's routes to remain unchanged; I can force my app's routing to avoid collision with any of the client's.

truckee avatar Oct 01 '19 16:10 truckee

I found that in order to use an existing schema I needed to create the wp-config.php file before WordPress installation so that my schema would have the wp_ tables.

What does the "wp-config.php" file that you create in the wp folder look like?

Am I correct that ...mukadi/wordpress-bundle/Config.php:38 requires modification to add an extra parent to the directory?

yes, the basic idea here was to put the wp-config.php file at the root of the "public" folder to be able to find the '.env' file at the root of the project.

I'm also wondering about the necessity of WordPress's .htaccess file in ...\public. My project's objective is to add Symfony to a client's existing WordPress site. So I want their site's routes to remain unchanged; I can force my app's routing to avoid collision with any of the client's.

the presence of an .htaccess file in the "public" directory is not mandatory, if everything is well configured the wordpress routes should remain unchanged except those located in the admininstration part.

P.S: My English is not very good, please be forgiving if you can not understand what I'm writing or inversely :-)

mbo2olivier avatar Oct 02 '19 08:10 mbo2olivier

In a fresh installation of Symfony 4.3.4 and mbo2olivier/mukadi-wordpress-bundle per the documentation, launching the site results in the error shown in the title.

Symfony profiler's phpinfo() shows $_SERVER['APP_ENV'] =dev. There does not exist a .env file in ...\public\wp. Copying .env to ...\public\wp has no effect.

Stack trace:

Symfony\Component\Dotenv\Exception\PathException:
Unable to read the "G:\Documents\workspace\match\public/wp/../.env" environment file.

  at vendor/symfony/dotenv/Dotenv.php:484
  at Symfony\Component\Dotenv\Dotenv->doLoad(false, array('G:\\Documents\\workspace\\match\\public/wp/../.env'))
     (vendor/symfony/dotenv/Dotenv.php:65)
  at Symfony\Component\Dotenv\Dotenv->load('G:\\Documents\\workspace\\match\\public/wp/../.env')
     (vendor/mukadi/wordpress-bundle/Config.php:38)
  at Mukadi\WordpressBundle\Config->__construct('G:\\Documents\\workspace\\match\\public/wp')
     (public/wp-config.php:7)
  at require_once('G:\\Documents\\workspace\\match\\public\\wp-config.php')
     (public/wp/wp-load.php:42)
  at require_once('G:\\Documents\\workspace\\match\\public\\wp\\wp-load.php')
     (public/wp/wp-blog-header.php:13)
  at require_once('G:\\Documents\\workspace\\match\\public\\wp\\wp-blog-header.php')
     (vendor/mukadi/wordpress-bundle/Wordpress/Wordpress.php:102)
  at Mukadi\WordpressBundle\Wordpress\Wordpress->loadWordpress()
     (vendor/mukadi/wordpress-bundle/Wordpress/Wordpress.php:79)
  at Mukadi\WordpressBundle\Wordpress\Wordpress->getContent()
     (vendor/mukadi/wordpress-bundle/Wordpress/Wordpress.php:60)
  at Mukadi\WordpressBundle\Wordpress\Wordpress->initialize()
     (vendor/mukadi/wordpress-bundle/Controller/WordpressController.php:32)
  at Mukadi\WordpressBundle\Controller\WordpressController->wpAction(object(Wordpress))
     (vendor/symfony/http-kernel/HttpKernel.php:151)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:68)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/http-kernel/Kernel.php:198)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (public/index.php:45)
  at run()
     (public/index.php:49)

Edit: Changing mukadi/wordpress-bundle/Config.php:38 to: (new Dotenv())->load($path.'/../../.env'); allows getting a new error message:

Warning: Use of undefined constant WP_DEBUG - assumed 'WP_DEBUG' (this will throw an Error in a future version of PHP) in G:\Documents\workspace\match\vendor\mukadi\wordpress-bundle\Config.php on line 60

Warning: Use of undefined constant WP_DEBUG - assumed 'WP_DEBUG' (this will throw an Error in a future version of PHP) in G:\Documents\workspace\match\vendor\mukadi\wordpress-bundle\Config.php on line 61

Edit #2: Added WP_DEBUG=true to .env block ###> mukadi/wordpress-bundle ### Added define('WP_DEBUG_DISPLAY', env('WP_DEBUG_DISPLAY', WP_DEBUG)); at mukadi/wordpress-bundle/Config.php:59`

These changes eliminated the WP_DEBUG error messages.

Edit #3: As I reduce my ignorance of WordPress, creating the ...public/wp/wp-config.php file eliminates the need for any of the changes above.

I can solve this problem by edit1. But I assume this is not a right procedure as i have to chnaged the core file from vendor folder.

webgrity2016 avatar Nov 19 '19 12:11 webgrity2016