Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP: How can a number of websites share the same include file?

Options
  • 28-03-2008 4:49pm
    #1
    Closed Accounts Posts: 12,382 ✭✭✭✭


    Hello

    I'm hoping someone can help me with this.

    I run the websites jobsdublin.ie, jobscork.ie, etc. I have a site for each county.

    At the moment each site has it's own code. This means if I find a bug, I have to update the code for every site. This is very innefficient.

    I'd like to change the sites so they share a common functions.php file (or something like that) so I can easily update every site by changing the single functions.php file.

    This is my question:

    Where should I put the functions.php file? Should one of the sites own this file? If so, how can the other sites access it? For example, if I SSH in as jobsdublin, I can't "cd .." below /home/jobsdublin as he doesn't have permission to access /home, so I'm not sure how I can share functions.php between all the site.

    Anyone have any suggestions?

    Hopefully I'm making sense.

    Thanks :)


Comments

  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Really depends on the server setup.
    Obviously as you've seen, all sites need to be on the same server. Assuming that every site runs as the same user, e.g. "Apache", then there's no reason why you couldn't dump the functions.php file into /home/ and explcitly give the "Apache" user read-only access to this file. Then every site calls include("/home/functions.php)"

    I'm not overly familiar with Unix permissions, but I'm assuming that a user can be given explicit permissions on an individual file - i.e. they don't need access to the parent directory.


  • Registered Users Posts: 1,127 ✭✭✭smcelhinney


    I would recommend using a version control system like CVS or SVN. This will allow you to create and hold code, version it, tag it, and check out to wherever you want to.

    This is the way I manage multiple sites, and it works quite well. I basically set up a module in CVS with common functions. When I have committed all my changes, I run a server script that checks out all relevant files to their syndicated locations.

    Incidentally, what type of server are you running? Just a thought, but if you are using *nix system, would it not be possible to create symbolic links for all the includes you require? ie. create a symbolic link for functions.php, that points to a file in a central location?

    Dunno if this will work, as I've only ever used symbolic links for directories, never for files.

    HTH,
    Stephen


  • Registered Users Posts: 5,517 ✭✭✭axer


    Who are you hosting with? are all the websites on the same server? Have you tried FTPing into your hosting account? Can you access all your websites when you FTP to account with the one login?


  • Registered Users Posts: 2,919 ✭✭✭Bob the Builder


    I would recommend using a version control system like CVS or SVN. This will allow you to create and hold code, version it, tag it, and check out to wherever you want to.

    This is the way I manage multiple sites, and it works quite well. I basically set up a module in CVS with common functions. When I have committed all my changes, I run a server script that checks out all relevant files to their syndicated locations.

    Incidentally, what type of server are you running? Just a thought, but if you are using *nix system, would it not be possible to create symbolic links for all the includes you require? ie. create a symbolic link for functions.php, that points to a file in a central location?

    Dunno if this will work, as I've only ever used symbolic links for directories, never for files.

    HTH,
    Stephen

    I tried CVS a while back. It's a perfect solution to what your doing, but I never had enough time to get it working properly.

    Never tried SVN


  • Registered Users Posts: 7,739 ✭✭✭mneylon


    I presume you have root access ....

    I know one of our clients uses a bunch of common includes / libraries.

    I *think* they just use a symlink of some kind.

    I'd recommend playing around on a dev machine to make sure that stuff doesn't explode, but it should be possible


  • Advertisement
  • Registered Users Posts: 3,886 ✭✭✭cgarvey


    SVN or Symlink (watch link owner, and FollowSymLinks in Apache config) is how I do it


  • Closed Accounts Posts: 12,382 ✭✭✭✭AARRRGH


    Thanks everyone for your replies. I'm sorry I've only replied now.

    Seamus's suggestion sounds the easiest -
    seamus wrote:
    Assuming that every site runs as the same user, e.g. "Apache", then there's no reason why you couldn't dump the functions.php file into /home/ and explcitly give the "Apache" user read-only access to this file. Then every site calls include("/home/functions.php)"

    - so I will give that a try.

    It's a Unix server, with all the sites on the same machine. I have root access to the server.

    Thanks.


  • Registered Users Posts: 1,268 ✭✭✭deegs


    why not use put the file in a sub directory of your main website. That way you can access with the full 'html' link as opposed to the server reference and not affect traffic figures.


Advertisement