wesleytodd / YeoPress

A Yeoman generator for WordPress
Other
1.08k stars 163 forks source link

Installing WP as a submodule causes 404 error #160

Closed sheixt closed 9 years ago

sheixt commented 9 years ago

Issue brief

I'm having an issue when attempting to run yo wordpress on my localhost (running on WAMPSERVER) and selecting the submodule option. After completing the installation, when I visit my site URL I'm presented with a 404 'Not Found' error.

Configuration settings:

WordPress URL: localhost/site-name
Table prefix: lt_
Database host: localhost
Database name: site-name
Database user: root
Database Password: 
Use Git: Yes
Would you like to install WordPress as a submodule? Yes
WordPress install directory: cms
WordPress content directory: content
Install custom theme? Yes
Destination directory: yeopress
Theme source type (git/tar): git
Task runner (gulp/grunt): grunt
GitHub username: wesleytodd
Github repository name: YeoPress
Repository branch: template

The installation of Git, the WP submodule and the theme all process without correctly and at the end I'm presented with the "All Done!! ... " notification. But when I visit http://localhost/site-name in my browser, I'm redirected to http://localhost/cms/wp-admin/install.php and (unsurprisingly) it gets a 404 (as the directory & file doesn't exist). Any suggestions on how I can resolve this problem?

Additional steps undertaken to try to find a workaround:

  1. I've attempted to amend the WordPress install directory to site-name/cms and this works to a point... When viewing the site URL in a browser I'm directed to the WP famous 5 minute install, but it is creating an additional directory in the URL structure site-name/site-name/cms/... which is a pain.
  2. I've also tried amending the WordPress install directory to /cms and I get an error saying:
Error: { [Error: Command failed: The followingpath is ignored by one of your .gitignore files:
/cms
(this continues....)

Note: If I chose the non-submodule approach, the install works fine.

Toddses commented 9 years ago

I'll take a look at this. I have a guess as to the issue. For reference, could you check your YeoPress version for me?

Toddses commented 9 years ago

OK here's the deal. YeoPress's default wp-config.php file does not work when wordpress is installed in a subdirectory (eg. localhost/site-name).

Two options.

1) Create a vhost on your local machine for something like site-name.dev and point it to your site-name installation directory. IMO this is the ideal option.

2) Update your wp-config.php like so:

if (!defined('WP_SITEURL')) {
    define('WP_SITEURL', 'http://' . $_SERVER['SERVER_NAME'] . '/site-name/cms');
}
if (!defined('WP_HOME')) {
    define('WP_HOME',    'http://' . $_SERVER['SERVER_NAME'] . '/site-name');
}
if (!defined('WP_CONTENT_DIR')) {
    define('WP_CONTENT_DIR', dirname(__FILE__) . '/site-name/content');
}
if (!defined('WP_CONTENT_URL')) {
    define('WP_CONTENT_URL', 'http://' . $_SERVER['SERVER_NAME'] . '/site-name/content');
}

That will work fine for your local wordpress sites.

Toddses commented 9 years ago

@sheixt I'll leave this open so you can confirm that the problem was resolved. I was able to recreate the issue and the above solution worked for me. But its interesting that it worked fine without the submodule install, as in theory it should still be an issue.

sheixt commented 9 years ago

@Toddses thanks for the prompt reply! I investigated creating a vhost on my local machine, however embarrassingly I only managed to cripple my WAMPSERVER setup...!

So after restoring it, I've gone for option 2 and that works like a charm! Thanks for the help.

Out of interest why did you prefer option 1?

Toddses commented 9 years ago

Typically when you deploy your site, it will live at the root URL (http://example.com). So you want to set up your local dev site to mimic the behavior you get from a root URL. This way you're not deploying a site that worked in a subdirectory, then going in and updating settings to deal with the root installation.

That said there are lots of use cases for keeping your local in a subdirectory, in particular if your live site will live in a subdirectory.

sheixt commented 9 years ago

Actually, I may been a little keen to close this... I was able to run through the install fine, the set-up all seems fine wit the exception that It cannot seem to locate the themes:

On review, the theme files are present in both the cms and content directories so I am unsure why WordPress cannot seem to locate it. Any suggestions?

Toddses commented 9 years ago

Most likely that's an issue with the WP_CONTENT_DIR constant. You might investigate what the output is of dirname(__FILE__). I'm not too familiar with windows behavior here.

Toddses commented 9 years ago

I do know when I deploy to our remote servers I have to change that dirname() call to $_SERVER['DOCUMENT_ROOT'] so that might be what you need as well.

sheixt commented 9 years ago

Bang on, first time. You sir are are my favourite person of the day. Thanks again for you help.

Toddses commented 9 years ago

You tend to remember the solutions to problems that bring you to tears :)

wesleytodd commented 9 years ago

@Toddses HAHA, best response all day!

sheixt commented 9 years ago

Haha brilliant! I'm grateful to have avoided that heartache.