topdown / VVV-Dashboard

Dashboard for Varying Vagrant Vagrants https://github.com/Varying-Vagrant-Vagrants/VVV
254 stars 40 forks source link

Non-default WP structures #15

Closed GaryJones closed 8 years ago

GaryJones commented 8 years ago

I use WPStarter which puts the WP files into a wp subdirectory, leaves wp-content/at root, and moves all configuration out of wp-config.php and into .env.

With this format, VVV-Dashboard fails to determine if debug is on, fails to open wp-admin (hard-coded to the wrong location) and can't retrieve the list of plugins and themes.

It would be great if VVV-Dashboard could account for non-standard structure of WP such as WPStarter or Bedrock.

topdown commented 8 years ago

@GaryJones how do you install with this in VVV? Do you have a custom init script for it?

Never mind, I think I figured it out. I'll see what I can do with this.

topdown commented 8 years ago

I started working on a fix for this and hit a wall. There is a major problem with WPStarter as it does not follow the normal paths. VVV Dashboard's latest versions heavily rely on WP-CLI to load things like themes, plugins and manage updates. Because these paths are all changed WP-CLI is looking in the wrong places. At the moment I am not seeing a option flag for it.

GaryJones commented 8 years ago

Is it possible to read inside index.php, or wp-config.php, or look for existence of .env to guess whether it's a form of WPStarter? cc @wecodemore

topdown commented 8 years ago

Thats what I am working on or testing now.

topdown commented 8 years ago

So VVV Dash now checks if its WPStarter or any site setup the same way with .env

I also have all of the config vars loaded for the host, but its a mess and would need to be identical because of all of the line searching and splitting.

I do not have the newest VVV Dash features working for it yet, eg. Themes, Plugins, and Backups so those are shut off for .env sites at the moment. Still have not figured this out because these features use WP CLI

Test out the develop branch and let me know what you see, errors, etc...

topdown commented 8 years ago

I was wrong about the WP CLI issue, it was a path issue which returns NULL in WP CLI.

So this should be working pretty good from my testing for WPStarter but Bedrock is a whole new game.

I have plans to do some major refactoring which will help. Once that is done I can work on a cleaner way to do it.

So @GaryJones if you could do a checkout on the develop branch and let me know how WPStarter is working for you that would be great.

Thanks

GaryJones commented 8 years ago

Fast work!

Not seeing any change though.

screenshot 2015-12-03 09 35 33

I've purged everything, halt'd and up'd, but still not seeing any difference to when I first reported.

Here's my file structure:

screenshot 2015-12-03 09 40 39

I did see at least three instances of a hard-coded /public/wp, though my setup would be /htdocs/wp (that's from BradP's VV). I changed the ones in index.php, but didn't see any change.

The vvv-dash-hosts.php file also tries to look for the .env at:

$env_file = VVV_WEB_ROOT . '/' . $host_info['host'] . '/.env'; rather than in htdocs too. Some indeed may want the .env next to (outside) the host web root, but your code should probably check for it inside first, and if not found, then check up one level (as core WP does when looking for wp-config.php).

topdown commented 8 years ago

Did you re-copy the dashboard-custom.php to default/dashboard-custom.php @topdown create an update script :) It has new path settings that could help. (Purge Hosts) and reload page.

When I installed WPStarter with composer it created a public folder instead of htdocs and .env is up 1 directory out of public path and wp-content folder is content. 2 of the new settings checks an array for scan path and wp-content. But I think as you said the .env will not get picked up. Basically the way I installed all DOT files and composer files are out of public stream as they should be.

How did you get this install? layout?

So what I want you to do is dashboard-custom.php to default/dashboard-custom.php Then verify something for me, if .env is still in the public path when you refresh the dashboard the debug icon for that host should say NOT INSTALLED

Then just as a test move .env to the same dir as vvv-hosts. It should fix it. I will have to check both paths like you said.

topdown commented 8 years ago

Working on this again and moved my .env like your setup. Thought it was all said and done until I loaded themes and plugins from that test WPStarter site and then the site has the same errors. Interestingly enough I get exception errors because the .env is in the wrong path.

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Dotenv: Environment file .env not found or not readable. 
Create file with your environment settings at /srv/www/wpstarter/.env' in /srv/www/wpstarter/public/content/vendor/vlucas/phpdotenv/src/Loader.php:78 

So I am not sure how you installed it, but looks like it requires the Composer path setup.

GaryJones commented 8 years ago

Did you re-copy the dashboard-custom.php to default/dashboard-custom.php @topdown create an update script :)

Yes, I had done that.

It has new path settings that could help. (Purge Hosts) and reload page.

Yep, did that too.

My install process was to use BradP's VV (which I think is where the htdocs comes from), remove the contents of the web root, drop in the composer.json, composer install and go from there.

topdown commented 8 years ago

I tried moving things around to match your paths and it just opened a huge can of worms. Pretty much nothing in WP works. Also, still if I leave .env in the public path it spits exceptions.

You must be using a modified composer.json, because the normal one does not work without a lot of changes. Kinda defeats the purpose I would think since its suppose to be less work.

Now if I just install it the normal way using composer.json it works fine. Which also puts .env outsite public path.

GaryJones commented 8 years ago

I'll have to have a play and see what I did then - I certainly didn't intend to do anything different than the WPStarter default.

FWIW, http://wecodemore.github.io/wpstarter/docs/quick-start.html shows .env.example as a peer to wp/ and wp-config.php, not outside the public path.

Pinging @Giuseppe-Mazzapica and @franz-josef-kaiser for their input.

gmazzap commented 8 years ago

@GaryJones Can you please summarize what's the issue? Not being native english speaker, read and understand the full thread takes a bit of time...

GaryJones commented 8 years ago

@Giuseppe-Mazzapica: VVV Dashboard creates a dashboard for VVV (!), with extra functionality for WP sites - being able to see the list of themes / plugins, direct link to wp-admin, do a DB backup etc, but these don't work when the site is setup as per WPStarter, since the WP files are in a different place. The presence and location of .env, in trying to determine the correct paths, also makes things difficult.

gmazzap commented 8 years ago

Well, the location of .env should not be a problem at all. That file is loaded and parsed by wp-config.php so I guess that even if VVV Dashboard does not know where .env file is, there should be no problem at all.

Moreover, is not possible to assume a fixed location of wp-config.php, because WordPress allows to have wp-config.php in a different folder. There's even a Codex entry that explain how to have wp-config.php in a different folder of WordPress. See https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory

I'm not familiar to this library, but I guess that it needs some configuration to setup the ABSPATH of the WordPress installation that is the folder that contains wp-load.php. (The wp-config.php must be in either inside ABSPATH folder or in its parent folder).

After that, to be sure to recognize all themes and plugins, the only way is to load wp-load.php. Just to make a simple example, there might be additional theme folders that are registered using https://developer.wordpress.org/reference/functions/register_theme_directory/ and it is impossible to recognize those folders without loading WP.

On the countrary, if the WordPress environment is loaded, no matter if the website make use of .env, WP Starter or anything else, everything can be located using WordPress functions and constants and you can be sure that everything you see is what WordPress will see...

GaryJones commented 8 years ago

After that, to be sure to recognize all themes and plugins, the only way is to load wp-load.php. Just to make a simple example, there might be additional theme folders that are registered using https://developer.wordpress.org/reference/functions/register_theme_directory/ and it is impossible to recognize those folders without loading WP.

That's something I hadn't considered.

topdown commented 8 years ago

To get theme, plugin and version info VVV-Dashboard is using WPCLI which loads WordPress Which is also why the WP file path info needs to be right for any of it to work which is loaded off of .env and composer. So I have to scrape the .env to get the required info, which I do and it works fine with this configuration/install https://github.com/wecodemore/wpstarter/blob/master/composer.json

But, no matter what I do, if I move .env in the public path like you have it, composer blows up with exceptions and this has nothing to do with VVV Dashboard, I'm talking visiting the actual site. To me makes sense as a .env file with config info should not be in the public path just by standards.

I'm going to try the composer.json from the WPStart home page and see what happens.

GaryJones commented 8 years ago

To me makes sense as a .env file with config info should not be in the public path just by standards.

The problem is shared hosting may have a structure like:

In this case, .env from site-a.com and site-b.com can't be moved out of the public root, since that would then act as the .env for the main site.

On non-shared hosting, devs can of course do what you recommend, but, that's not the default for WPStarter, so it would be great if VVV Dashboard could accommodate that.

topdown commented 8 years ago

I want to support everything, I just can't seem to get a working install with your paths.

It is the default using https://github.com/wecodemore/wpstarter/blob/master/composer.json I move nothing in my setup except changing required paths that VV creates Use VV to create a site example.dev Then delete everything except the vagrant files

vagrant ssh
cd /srv/www/example
wget https://raw.githubusercontent.com/wecodemore/wpstarter/master/composer.json
composer install

Change paths in wp-cli.yml and vvv-init.sh Add db credentials in the .env-sample and move to .env Locally vagrant provision Thats it.

As far as shared hosting, hopefully they block DOT files, because not all hosting do. Huge security issue. Also thats not your path setup here https://cloud.githubusercontent.com/assets/88371/11556990/084cd922-99a2-11e5-9e46-76464b547c0b.png

OK, so using the composer.json on this page http://wecodemore.github.io/wpstarter/docs/quick-start.html I get installed with .env in public path, but not with the composer.json that is in their repo which is the same as this one http://wecodemore.github.io/wpstarter/docs/complete-example.html

So 2 completely different setups with 1 package. ^_^

Regardless, at least I have a working install with the .env in public and I can actually get something done to fix this for you.

GaryJones commented 8 years ago

As far as shared hosting, hopefully they block DOT files, because not all hosting do.

Mine doesn't by default, but it's only a few lines in .htaccess to do so.

Also thats not your path setup here https://cloud.githubusercontent.com/assets/88371/11556990/084cd922-99a2-11e5-9e46-76464b547c0b.png

That's a local filesystem for vagrant, and doesn't match the account root for (my) shared hosting.

Looking again, yes, VV has htdocs/as the default, and WPStarter uses public. Regardless though, someone could setup the --webroot with VV as something else entirely.

topdown commented 8 years ago

My problem was I could not get a working install with your setup. Which is requited to do any sort of programing for it since a working WP needs to be loaded.

The issue was we were using 2 different composer.json files, both coming from WPStarter http://wecodemore.github.io/wpstarter/docs/quick-start.html The one I was using was here http://wecodemore.github.io/wpstarter/docs/complete-example.html

These each do different installs. I now have a working WP install with .env in the public path so I can work on fixing this. Thanks

GaryJones commented 8 years ago

The issue was we were using 2 different composer.json files, both coming from WPStarter http://wecodemore.github.io/wpstarter/docs/quick-start.html The one I was using was here http://wecodemore.github.io/wpstarter/docs/complete-example.html

@Giuseppe-Mazzapica Something to fix in documentation upstream?

franz-josef-kaiser commented 8 years ago

@GaryJones just FYI, Giuseppe currently is on vacation and not available. Ad different examples: "WP Starter" offers examples for a reason. You can tweak your composer.json to fit your structure. From the docs:

"env-example" [in your composer.jsons extra array] is used to tell WP Starter which file to copy as .env.example in project folder.

You can point to a .env file residing in any folder. Renaming from .env.example to .env and adding DB credentials, etc. is required tough.

Further @topdown you can find the following in the docs link you posted above:

The source used is the same Gist that contains the it_IT.php file and is used to show how to use a custom package to collect files that you want to share among WP Starter projects.

In other words, you can distribute your package with requiring a separate package or just a subfolder that has all the basics needed to get up and running.

gmazzap commented 8 years ago

I just don't see which is the point to locate the .env file. WP Starter don't force to set in env file anything relevant.

For example, a valid .env file (or whichever is the file name) can contain:

DB_NAME=mydb
DB_USER=myuser
DB_PASSWORD=mysecret

And I don't get how locate a file that contains this info can be helpful for your aim.

In short:

In short, I guess the only way is accept some sort of configuration that allow an user to define where the WordPress path is. WP CLI has a configuration --path that does just that (see http://wp-cli.org/config/).

Another way could be parse the composer.json that may contain a wordpress-install-dir entry in the extra object. That configuration comes from the WordPress core installer for Composer (https://github.com/johnpbloch/wordpress-core-installer) that is the most used WordPress core installation package (almost a de facto standard), even if it is surely not the only one.

topdown commented 8 years ago

If you guys are using the dashboard with these types of installs. Could you checkout branch refactor-actions and see how it works and let me know.

As a side note: looking for the .env files is just to verify that it is not a standard install, thats it. From there paths are pulled from composer.json, wp-cli.yml, vvv-hosts and checked.

topdown commented 8 years ago

Just a little note: I merged refactor-actions into develop for a week or so before I release and merge to master. So all of the changes are now in develop also with the latest features. I also deleted refactor-actions branch so you will want to switch to either develop or master.

topdown commented 8 years ago

If anyone in here is still having issues with this feel free to open a new ticket or bring this one back to life. The latest develop and master branches are using a new host detection setup which can be added to if needed, but I have tested some .env setups without issue. Closing this for now. Feel free to open a new ticket if you have any more issues. Thanks