0

I'm currently running my custom bootstrap config, and I had a previous problem where MSM wouldn't work with it (Both in the Control Panel and the front end)

I managed to fix this problem, but now I get an "Error 500" on the front end, whenever I enter one of the sites other than the main one.

What could be causing this.

I have possibly nailed it down to being:

<?php require('./config.php'); ?>

In my "system/expressionengine/config/config.php" requesting my custom config file in the root directory. Could this be causing problems?

My custom config file can be found here:

https://github.com/madebymayo/ExpressionEngine-Environment-Config

EDIT: I must point out, that before placing my custom config in, the original config file worked perfectly for EE and MSM. But it doesn't really work with my workflow :)

PARTIALLY SOLVED...Still need help

My current setup is to have my custom "config.php" bootstrap in the root of my site.

I then Have the require('./config.php') in both the database.php and config.php files within "/system/expressionengine/config/"

My URL's look like this:

http://website.com

http://website.com/website_1

http://website.com/website_2

Now I think the problem is the

<?php require('./config.php'); ?>

I changed it to (Added dot):

<?php require('../config.php'); ?>

and both my website_1 and website_2 work. But it breaks my Control Panel and the Root URL.

Is there an If statement I could put in my config file, to say IF we're inside either website_1 or website_2 display:

<?php require('../config.php'); ?>

But if we're inside the root or in the CP, use:

<?php require('./config.php'); ?>
2
  • do you have anything going on in an .htaccess file for the domains that are having problems?
    – foamcow
    Jan 10, 2013 at 11:20
  • @foamcow Nothing in htaccess. But I have figured out the problem, I just don't know the fix for it... See my edit above.
    – Jason Mayo
    Jan 10, 2013 at 11:44

2 Answers 2

3

Try this:

require(dirname(__FILE__).'/path/from/current/file/to/config.php');

For example, assuming you have config.php in the standard system/expressionengine/config directory, you would use this line:

require(dirname(__FILE__).'/../../../config.php');
5
  • This sort of does something, it changes the 500 error to: Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data.
    – Jason Mayo
    Jan 10, 2013 at 13:48
  • hmm, I'm gonna guess if you're running locally on mamp it's not gonna be a php memory limit issue, but are there any plugins or anything a bit more "third party" in your config file that might just be conflicting with something else? Jan 10, 2013 at 15:17
  • That should be the path from the current file, not the index. I updated the answer to reflect it. Jan 10, 2013 at 15:30
  • Just ran into this and it solved it for me. Thanks! Apr 2, 2013 at 18:58
  • After trying again, many months after. This works!
    – Jason Mayo
    Sep 10, 2013 at 13:55
0

A useful trick I use in circumstances like this is to define an environment variable in an .htaccess file. These environment variables can then be accessed via PHP

So in website_1/ and website_2/, put the following line at the top of your .htaccess file:

SetEnv CONFIG_PATH_RELATIVE "../"

And then in the root site (where your control panel is), put the following line:

SetEnv CONFIG_PATH_RELATIVE "./"

Now, inside your main config.php file, at the top, do the following:

defined('CONFIG_PATH_RELATIVE') 
    || define('CONFIG_PATH_RELATIVE', (getenv('CONFIG_PATH_RELATIVE') ? getenv('CONFIG_PATH_RELATIVE') : FCPATH));

The above code says, "check for a constant named CONFIG_PATH_RELATIVE. If you find it, use it. If not, define that constant as the contents of the environment variable CONFIG_PATH_RELATIVE, and if you don't find an environment variable with that name, then use the EE built-in constant FCPATH."

Last, wherever you're requiring your custom config, change the statement to the following:

<?php require_once(CONFIG_PATH_RELATIVE.'config.php'); ?>

(Note that I've changed your require to a require_once. This is almost always better practice.)

The only real caveat is that some web hosts (usually the cheap ones) will not let you set environment vars in .htaccess. If you have one of those hosts, this technique will not work for you.

2
  • I just tried this (Running it locally on MAMP) and all of the site just gives me a 500 error now - CP and Front End?
    – Jason Mayo
    Jan 10, 2013 at 12:51
  • Okay, that's pretty odd. A 500 error means something is wrong with Apache's configuration; frequently that's because of something in an .htaccess file. So I'm guessing that MAMP doesn't like putting environment variables in .htaccess files, by default; or else that it doesn't have the Apache module mod_env activated by default. Unfortunately I hate Macs, so I know very little about how MAMP is set up out of the box. Hopefully someone can come along and shed some light on that.
    – adrienne
    Jan 10, 2013 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.