'PHP: One system directory for a framework

Is one system directory for a framework used by multiple projects (applications) a good idea? Or should one have a single system folder per application?

It would be easier to update just one base, but perhaps they are more disadvantages then advantages to this technique?



Solution 1:[1]

Having a separated folder for each of your projects it is a better approach because, if you update a common framework directory, you have to be sure that all your projects are working fine. But if you use a framework folder per project you can update all your projects one by one.

Solution 2:[2]

It depends on your updates. And on your framework. If you edit the framework on a per-project basis than obviously you don't want to have all those edits in your central framework.

But if all you do is edit your app which depends on your framework, or you just make couple minor tweaks of the framework that are applicable to most your projects, I suppose having one framework folder is fine.

What matters is that you can easily reproduce desired environment to production/deployment, and that you don't end up with a framework so edited for multiple projects so you can't make sense of it.

Solution 3:[3]

If you're using your own framework, like I do, so you know what you're updating or modifying, you can use symbolic links. This is the typical structure I use. As you can see, the projects have only one directory that contains the entire framework

/home/sal/myframework

/home/sal/www
  /myproject_a
    /application
    /framework
    /public
  /myproject_b
    /application
    /framework
    /public

This is how to create the symbolic links:

linux:

ln -s /home/sal/myframework /home/sal/www/myproject_a/framework
ln -s /home/sal/myframework /home/sal/www/myproject_b/framework

windows:

mklink /D /home/sal/myframework "/home/sal/www/myproject_a/framework"
mklink /D /home/sal/myframework "/home/sal/www/myproject_b/framework"

with php:

$target = '/home/sal/myframework/'; 
$link = '/home/sal/www/myproject_a/framework; 
unlink($link);
symlink($target, $link); 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 PachinSV
Solution 2 tonino.j
Solution 3 Sal Celli