473,654 Members | 3,076 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5951
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($D OCUMENT_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
4489
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... Thanks! --
0
1857
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 or dirs into zip: -------8<-------------------8<--------------------8<------------------8<----- def add_file(self, fileName):
0
1444
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. So, as I did before, I copied complete var of mysql into the other partition. I eliminated the var in mysql directory and I made a "var" symlink between the mysql directory and the var new location ; after I verified the group, user name and...
4
1695
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
840
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 controlling the visibility of columns in the DataGrid control. The problem usually comes down to one fact. The DataGrid has a property called AutoGenerateColumns. The default value is "True". This means that when AutoGenerateColumns is set to True,...
2
1685
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 to it. I figured that I could bypass the lock file by creating a symlink (my os is Fedora Core 3 Linux) and just putting the url to the Symlink into the connection. Obviously I am having problems with this approach. Has anyone else done
1
2270
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 file. Now I need to be able to have the symlink point to a folder (which is a parent to other content). I have used PHP code to generate a SYMLINK to a folder, and I have successfully tested the symlink through PUTTY. What I can't seem to do is...
162
10216
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 prefix them with 2 underscores, but I hate prefixing my vars, I'd rather add a keyword before it. Python advertises himself as a full OOP language, but why does it miss one of the basic principles of OOP? Will it ever be added to python?
2
7344
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
0
8290
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8815
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8707
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8482
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7306
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6161
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5622
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2714
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.