Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7187439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:50:43+00:00 2026-05-28T18:50:43+00:00

Is there a favored method for specifying the root folder of your website/application without

  • 0

Is there a favored method for specifying the root folder of your website/application without having to resort to code like this:

require '../../../../config/settings.php';

I’ve used various methods before, and the one I’m currently considering is setting an environment variable on my host, so that I can do something like this instead:

require getenv('PROJECT_ROOT') . '/config/settings.php';

But this is really only feasible for systems with one project on them, and it has various other disadvantages, so I was wondering if there was a better method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:50:44+00:00Added an answer on May 28, 2026 at 6:50 pm

    If you wanted to go down the environment variables path, you are able to set environment variables from your Apache vhost. Check out SetEnv and SetEnvIf in the Apache docs. e.g. To supply an environment variable to all incoming requests for a given apache vhost:

    SetEnv PROJECT_ROOT='/path/to/my/project'
    

    e.g. To change the value of an environment variable based on host name:

    SetEnvIf Host www.example.com PROJECT_ROOT='/path/to/example/com'
    SetEnvIf Host www.example.org PROJECT_ROOT='/path/to/example/org'
    

    Other options include autoloading and bootstrapping. Autoloading works great for classes, but not for config files like your example. A good naming convention (such as PSR-0) will make mapping class names to file names much easier. Bootstrapping involves creating a file which you include from all of your scripts which in turn loads things like configuration settings. The bootstrap is a great place to set up autoloading. That way your bootstrap loads the configuration before the rest of the app is loaded, and you just assume it’s present elsewhere in your app.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There was some code like this: // Convenience to make things more legible in
There are things like f.call(...) f.apply(...) But then there's this (1, alert)('Zomg what is
There is previous little on the google on this subject other than people asking
There are a few ways to get class-like behavior in javascript, the most common
There are numerous libraries providing Linq capabilities to C# code interacting with a MySql
There are several shading languages available today like GLSL, HLSL, CG, which one to
There was a smbmrx sample code using RDBSS in WDK Vista. But since WDK
There are many methods to override, like initWithNibname: , awakeFromNib , loadView , viewDidLoad
There is something I miss with the notion of Synchronizing code in Android. Scenario
I am working on a large web application project and the previous designer favored

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.