473,378 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Hiding a PHP app behind a symlink?

I've developed a simple content management system in PHP, and I'd like
to be able to put the code for it in a single place, and have several
sites on one server seamlessly share the code.

I want to put the app itself in /DOCROOT/MyCMS/.

I want to put a site that uses it in, say, /DOCROOT/site1,
/DOCROOT/site2, etc.

I want to place a symlink to /DOCROOT/MyCMS/ inside each site
directory, so /DOCROOT/site1/MyCMS/index.php is reachable as expected.

Here is the problem. Each individual site will need a separate config
file. So /DOCROOT/site1/ will contain both the symlink to the CMS,
and a config.php file.

I want code in /DOCROOT/MyCMS/ to be able to
require_once("../config.php"). But I'm new to symlinks, and a little
testing has shown me that unix command ls seems to disagree with
itself about how to follow symlinks "backwards". Do I need to take any
special action to make require_once() follow the symlink "back" to the
proper /DOCROOT/siteN/ directory?
Jul 16 '05 #1
2 5919
Patrick Lioi wrote:
I want to put the app itself in /DOCROOT/MyCMS/.

I want to put a site that uses it in, say, /DOCROOT/site1,
/DOCROOT/site2, etc.

I want to place a symlink to /DOCROOT/MyCMS/ inside each site
directory, so /DOCROOT/site1/MyCMS/index.php is reachable as expected.


You might want to do something like this:
Read the currently running script's directory from the $_SERVER vars.
Based on that, determine where the config file is located.
i.e.
<?
$arr_path = explode("/", $PHP_SELF);
include_once($DOCUMENT_ROOT .
"/" . $arr_path[0] . "/" .
"MyCMS/config.php");

?>

Jason

Jul 16 '05 #2
"Patrick Lioi" wrote...

*SNIPPED*
I want code in /DOCROOT/MyCMS/ to be able to
require_once("../config.php"). But I'm new to symlinks, and a little
testing has shown me that unix command ls seems to disagree with
itself about how to follow symlinks "backwards". Do I need to take any
special action to make require_once() follow the symlink "back" to the
proper /DOCROOT/siteN/ directory?


Make all your symlinks absolute, not relative and you should be fine :-)

ie,

ln -s /abs/path/to/file /abs/path/to/symlink

That will get around the problem of having relative symlinks failing but it
could make you symlinks a few bytes longer - considering symlinks are
usually much smaller than the files you're linking this shouldn't be a
problem. But I gather the main aim here is to only have to edit a single
instance of the core "library" functions etc for each site, in which case
yes, symlinks are the way to go.

If all else fails, and the libraries and sites are all on the same file
system you could use hard-links (ln without the -s). These are a bitch to
clean up though coz they "look" like regular files, but are actually
referencing the same inode (hard to track down all the hard links etc).
"man ln" is your friend :-)

-- James
_______________________________________
A random quote of nothing:
"... I should explain that I was wearing a black velvet cape that was
supposed to make me look like the dashing, romantic Zorro but which
actually made me look like a gigantic bat wearing glasses ..."
-- Dave Barry, "The Wet Zorro Suit and Other Turning
Points in l'Amour"
Jul 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: marco | last post by:
Hi all, I know about os.symlink(src, dst), but is there a way to overwrite an existing symlink e.g. "ln -sf"? Short of checking and, if necessary, having to delete the existing link by hand......
0
by: A. Murat Eren | last post by:
Hi, I have a problem about zipfile. I'm trying to add files from local file system into a zip file via zipfile module of python.. I have a function in my class which recursively adds files ...
0
by: lynn | last post by:
Hello, I tried to install on my mac osx 10.3.3 my mysql 4.0.13 databases on an other partition than its application; I know it is possible because I managed to do it previously with jaguar....
4
by: hazz | last post by:
What are the basic mechanisms behind an auto-hiding window which moves out of the way when not needed and flys back out when clicked on. Is this real complicated stuff? Thanks, -hazz
1
by: Amber | last post by:
The DataGrid allows you to make columns visible or invisible on demand - even edit and other special columns. This article will show you how it is done. Some developers have reported problems...
2
by: wheresjim | last post by:
I have a project in which I only need read access to a Microsoft Access database (.mdb file) via JDBC and unfortunately, the file is frequently locked by another application when I need access...
1
by: | last post by:
I'm developing a website (PHP/Apache), and I need to be able to use a 'symlink' inside a URL where the symlink is a folder not a file. I have been able to use symlinks that point directly to a...
162
by: Sh4wn | last post by:
Hi, first, python is one of my fav languages, and i'll definitely keep developing with it. But, there's 1 one thing what I -really- miss: data hiding. I know member vars are private when you...
2
by: Nikolaus Rath | last post by:
Hello, symlink(...) symlink(src, dst) Create a symbolic link pointing to src named dst. Is there any reason why this is so deliberately confusing? Why is the
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.