PHP Include not working with symlink'd files

I’ll abridge this and try to make it as clear as possible without extraneous verbage. Thank you in advance.

THE SETUP

  1. ‘/construct/’ directory, which contains page-layout master files, located in ‘/home/xxxx/construct/’

  2. Master files in ‘/construct/’ contain PHP Includes intended to search one level up the tree. For example:

[php]<php include("/bodyCopy/copy-content.php"); ?>[/php]

  1. The ‘/construct/’ directory is SYMLINKED into different subdomains (of the same domain with all things being equal in each subdomain). For example:

[#]http://sampleaccount1.mywebsite.com/construct/[/#]

…wherein the same ‘/construct/’ directory and its files is actually symlinked ~ this action (with ‘/construct/’) will be repeated in multiple subdomains.

THE PROBLEM

  1. The PHP includes I am using in the page-layout masters located in the symlinked ‘/construct/’ directory…

[php]<php include("/bodyCopy/copy-content.php"); ?>[/php]

…is supposed to pull the ‘copy-content.php’ file from the ‘/bodyCopy/’ directory WITHIN the subdomain, but…

  1. BECAUSE the page-layout master file is symlinked (as it resides in ‘/construct/’), the PHP Include command is searching for the ‘/bodyCopy/’ directory in ‘/home/xxxx/construct/’ where the ‘/construct/’ directory resides.

There is no such path as ‘/home/xxxx/construct/bodyCopy/copy-contet.php’.

  1. So, I would like to know how to get a PHP Include command, which is located in a directory/file (located above the root) that is symlinked into a subdomain, to look one level up INSIDE the subdomain, to ‘include’ a file. In other words…

*NOTE: My earlier research showed that symlinked files are not capable of PHP Including files from within the directories or subdomains in which they are symlinked. Of course, FCKEditor and CKEditor are often symlinked and DO search (and write to) directories and files in which they are symlinked. Thus, I am assuming there is a solution to my problem.

I appreciate any help anyone can provide. Thank you very much for your time, patience, and tutelage.

–JET–

Try editing your php.ini file line include_path to include both locations. But let me see if I have this…

/home/xxxx/construct/ <-- contains files for access by other scripts but it is symbolically linked to another directory.
/home/xxxx/bodycopy/ <-- contains the file you want access to

your subdomain goes to /home/xxxx/construct but you need access to the xxxx directory so your include lines should start with the two dots. or look like this

…/bodycopy/fileyouwant.php <-- tells the line to go up one directory and look for bodycopy directory then the file in that directory.

If I misunderstood please try explaining it again.

/home/xxxx/construct/ <— contains is the directory I symlink into…

/home/xxxx/public_html/sampleaccount/ <— wherein ‘sampleaccount’ is one of many a subdomains that will require the symlinked ‘/construct/’ directory

[php]<?php include("/bodyCopy/copy-content.php"); ?>[/php] <— The ‘/bodyCopy/’ directory here is located in each subdomain, but the PHP command line as written above is located in files contained in the ‘/construct/’ directory which is symlinked. Because this PHP command line is in a file that originate from a location above Web root before being symlinked in each subdomain, it is trying to search for a ‘/bodyCopy/’ directory above Web root instead of trying to search for a ‘/bodyCopy/’ directory inside the subdomain.

In other forum, somebody posted this as the solution…

<?php include($_SERVER["DOCUMENT_ROOT"] . "/bodyCopy/copy-content.php"); ?>

your still not making any sense.

where is bodycopy located on the server not what is your php code you said

That is not a location that is a line of code. If you need to navigate to the driectory in a shell prompt where is it located as in what is the working directory of the bodycode file

Let me put it another way.

1)) A directory called /construct/ is located here above Web root:

/home/xxxx/construct/

I am using a symlink to include that directory into several subdomains on the same domain so that /construct/ and its content appear (via symlink) as a directory in those subdomains

2)) A directory called /bodyCopy/ is located here inside a subdomain which is on the same domain as the /construct/ directory:

http://sampleaccount.mywebsite.com/bodyCopy/

‘sampleaccount’ is one of many subdomains that will require the /construct/ symlink. /bodyCopy/ is also located in each of those subdomains.

3)) The file I need to reference using PHP Include is inside of /bodyCopy/, but the PHP Include command line is in a file inside of the /construct/ directory.

Therefore, the line of code <?php include("/bodyCopy/copy-content.php"); ?> (which is located in a file inside of /construct/, wherein /construct/ is symlinked TO subdomains FROM Web root) is searching in the Web root for the /bodyCopy/ directory instead of searching in the subdomain for it.

I need <?php include("/bodyCopy/copy-content.php"); ?> to search the /bodyCopy/ directory in the subdomain because there is NO /bodyCopy/ directory in the Web root.

Sorry, I can’t explain it any more clearly than that.

what is your webhost root location? Meaning if you type www.yourdomain.com which folder does it access on your server?

mine is /services/web/

/home/myusername

Website files are in /home/myusername/public_html/

ok and construct folder is located in /home/xxxx/construct correct?

Correct

easiest way to get access to the files in the construct folder is to add /home/xxxx/construct to you include_paths line in the php.ini file. that way you can ditch the symbolic links. so that when you type include(“myfilename.php”); it looks in not only the root web folder (/home/myusername/public_html/) but also in /home/xxxx/construct for the file. you will need to restart your web server (I assume apache) with sudo apachectl restart after the php.ini file edit.

usually located in /etc/php5/ or /etc/apache2/

Thanks. I didn’t think about that.

Sponsor our Newsletter | Privacy Policy | Terms of Service