Need localhost wordpress regular php site path advice

I’m trying to implant a wordpress blog into my already existant site

the site itself has most things stored in the root directory which of course with mamp is http://localhost:8888/sitename/ but i don’t want to use that path bc it will be broken when i upload it

I’m trying to set up a relative path, but is the syntax different for php includes?

i have folder structure
localhost/sitename/blog/wp-content/themes/mytheme/index.php

i want the index.php to link to my a footer.php in my ‘sitename’ root.

if i’m not incorrect, that should be

<?php include("../../../../footer.php"); ?>

going up 4 levels higher looking for the file… feel it should work! but that is not working… i tried adding and removing a ‘…/’ and it’s not there either… so what am i doing wrong??

and don’t just suggest i put the entire site into wordpress because for various reasons i cannot. only want the blog.

thanks!

i’m pretty sure this is something to do with setting the root path bc it bases the filepath on the original php file no matter how many includes there are. i’ve seen a vew articles online about setting a root directory in a variety of ways, but i’m not really sure how to do any of them exactly.

using $_SERVER[‘DOCUMENT_ROOT’] seems like it should help somehow, but as i understand that will go to localhost… not mysite, so i need some sort of variable to set up the path? but i don’t really know how to do that…

You need to set up a virtual host, then your local site can be http://sitename.loc. If you don’t then your html paths will never match the live server http://sitename.com.
Google it, there is plenty of info around, it’s not difficult.

With php paths, you need to know where your “root” is on the machine (not the server software). You can start at DOCUMENT_ROOT and alter to suit if you want. eg $root = $_SERVER[‘DOCUMENT_ROOT’].‘wordpress/’;
Then when you include you just need to know where things are in relation to $root.

You could also alter the includes path and not worry about it

i’m finding this pretty difficult, but maybe it’s just me. do i still need a virtual host with mamp? i thought mamp was a virtual host…

from the other similar thread wher eyou were posting i get the idea of
a configuration.php with:

define(‘BASE_DIR’, ‘path’);

and then using
include(BASE_DIR . “/header.php”);

  1. i assume the path for base_dir would be whatever mamp lists as the document root in the preferences?
    /Users/me/Documents/webdev/site/

2)what i am confused about though is including the configuration file because I have includes in different folders (bc i have a wp install with custom theme). do i need a copy of the configuration.php in two places because wp uses index.php located inside the wordpress theme itself? i mean the configuration file sets where the basedir is, so you can’t call it based on the basedir… right? does that make sense? :stuck_out_tongue:

Currently you have http://localhost, which has a root folder C:/mamp/public_html (or whatever it is. This is the web servers root. That means that the web server thinks there is no C:/ or C:/mamp, it thinks the entire world starts from / and has no clue this is actually a directory on your pc.

Now if you want to add another site you need to put it in the web root for mamp to find: C:/mamp/public_html/mysite. But there is a problem now as you need to access this by http://localhost/mysite, and all your urls etc also need to be written like this.

So what you want is another web server that has it’s own root and doesn’t need you to use http://localhost/path/to/site, but rather http://newsite.local. This is what virtual hosts are. They have their own root folder, which can be anywhere you want, and think the whole world starts from there.

  1. i assume the path for base_dir would be whatever mamp lists as the document root in the preferences?

No. PHP scripts can live anywhere and don’t care about the webservers limited view of the world.

what i am confused about though is including the configuration file

At some point you have to know where something is. Put your config file one directory above the doc root, then you always know how to get it relative to that root. So no matter where you are, include $_SERVER[‘DOCUMENT_ROOT’].‘…/config.php’ works.

ok… well since my main site on the server is in a folder named after my domain and is shared with several other domains i’d want to put it in the document root so it doesn’t get crossed with other things i have hosted. does that make a big difference?

as far as virtual hosting, i can easily switch where mamp is set to, to make the site i’m working on the root localhost. that should have the same effect as far as i can tell.

i’m just not sure, in my config file where to set that basedir variable on my local testing machine. provided it’s the root directory… would it be path = ‘/’ ? and could i theoretically just use $_SERVER[‘DOCUMENT_ROOT’] for now instead of the $variable if it’s in the root? just that that wouldn’t work necessarily once it’s deployed?

it’s also occurring to me that relying on the deployment being based on a certain root is a bit inflexible as far as it potentially moving deeper into a server at a later time.

apologies for my denseness… but thanks a lot for the replies :slight_smile:

so it doesn’t get crossed with other things i have hosted

This is why you need virtual hosts. Google it, I promise it is not hard at all! (It’s different per server though, no idea about mamp or your os).

as far as virtual hosting, i can easily switch where mamp is set to, to make the site i’m working on the root localhost

You could do that, and have to switch every time you change sites … or just do above … I promise, really, it’s not hard.

would it be path = ‘/’ ? and could i theoretically just use $_SERVER[‘DOCUMENT_ROOT’]

I think you’re not getting that the web server and the file system are different. For the web server / is it’s root. It is actually the directory C:/mamp/public_html, but the web server does not know this. Php on the other hand does, to it / doesn’t exist on windows, or is the root directory on *nix. Php needs your file system path.

it’s also occurring to me that relying on the deployment being based on a certain root is a bit inflexible as far as it potentially moving deeper into a server at a later time.

What you need to know is where to start from, then no matter how deep you always know where things are. With html this is simply / With php you need to get a file system path, you can use DOC_ROOT if you want, important thing is to know where your includes/libraries are in relation to this when you include them.

where is the document root, then, if not the root of the server?

i found a good article on setting up virtual hosts on mamp, so i can get that done, but i still don’t know how to start including things.

so, given the file structure i mentioned in the first post but with the site itself as the root,
(/sitename/blog/wp-content/themes/mytheme/index.php
needs to call /sitename/footer.php)

and the location of the virtual server on my machine
(/Users/me/Documents/webdev/sitename/) which you’ve told me is both necessary and unnecessary to know at different points

what can i do to include said file but using a modifyable absolute path?

well i ended up not worried about document root or anything like that. just linked directly to all the includes with relative paths (my main problem is that i was editing my index.php in the theme folder and using that to calculate paths, forgetting that it was really the main wp index.php), and then made a config.php file with a $siteroot variable to use in direct html links and css links. seems to be working good. document root can leave me right alone.