Component based web project directory layout with git and symlinks - linux

I am planning my directory structure for a linux/apache/php web project like this:
Only www.example.com/webroot/ will be exposed in apache
www.example.com/
webroot/
index.php
comp1/
comp2/
component/
comp1/
comp1.class.php
comp1.js
comp2/
comp2.class.php
comp2.css
lib/
lib1/
lib1.class.php
the component/ and lib/ directory will only be in the php path.
To make the css and js files visible in the webroot directory I am planning to use symlinks.
webroot/
index.php
comp1/
comp1.js (symlinked)
comp2/
comp2.css (symlinked)
I tried following these principles:
layout by components and libraries, not by file type and not by "public' or 'non public', index.php is an exception. This is for easier development.
expose onle the minimal set of files in a public web directory and make everything else unaccesable to the web. Symlinking files that need to be public for the components and libs to a public location, but still mirroring the layout. So the component and library structure is also visible in the resulting html code in the links, which might help development.
git usage should be safe and always work. it would be ok to follow some procedure to add a symlink to git, but after that checking them out or changing branches should be handled safely and clean
How will git handle the symlinking of the single files correctly, is there something to consider?
When it comes to images I will need to link directories, how to handle that with git?
component/
comp3/
comp3.class.php
img/
img1.jpg
img2.jpg
img3.jpg
They should be linked here:
webroot/
comp3/
img/ (symlinked ?)
If using symlinks for that has disadvantages maybe I could move images to the webroot/ tree directly, which would break the first principle for the third (git practicability).
So this is a git and symlink question. But I would be interested to hear comments about the php layout, maybe you want to use the comment function for this.

As soon as you need to reuse some set of files elsewhere, that's when you should start thinking in term of components or (in git) submodules
Instead of managing webroot, and comp, and lib within the same repo (which is the SVN or the "Centralized way" for CVCS), you define:
n repos, one per component you need to reuse (so 'img' would be a Git repo reused as a submodule within webroot, for instance)
a main project for referencing the exact revision of those submodules you need.
That is one of advantages of submodules of symlink: you reference one exact revision, and if that component has some evolutions of its own, you don't see them immediately (not until you update your submodule anyway).
With a symlink, you see whatever state is the set of files at the other end of that link.

Related

git - "ignore" or avoid versioning subdirectories

I want to have all my configuration files versioned using Git in a remote repository at Github. I'm using Debian 7 testing, and all my configuration files are under the /home/user_name/ directory.
I created the usual .gitignore with all the files that I want to ignore and the files and directories that I want to allow versioning. My problem begins when I go to Documents, for example, and I see in zsh that folder is under the same versioning as the home directory.
I understand that Git works that way, but I need to know if it's possible to avoid that.
One classic way to version configuration files is to create a subdirectory like ~/etc/ and let your ~/.something files be symbolic links to ~/etc/something. Then, you can version ~/etc/ normally.
You can manage to ignore everything but your configuration files, but you'll always have little glitches like: the day you run git clean -fdx in the wrong place, you delete all your data.
Write */ in your .gitignore to ignore directories. Make exceptions with !foodir. Consider prefixing with slashes (see documentation for details).

Follow symlinks in SVN

I have a linux directory (and don't need any windows checkout):
/home/me/projects/project1
In this project, I need SVN (1.8.8) to follow a symlink "link1":
/home/me/projects/project1/link1/<some_directories_and_files>
But SVN won't let me do that, it just add link1 but not its content. If I try to add its content, I get an error:
svn add link1/*
svn: E145001: Can't schedule an addition of '/home/me/projects/project1/link1/first_directory' below a not-directory node
I tried converting link1 to hard link but I can't do that either:
ln /path/to/my/linked/directory link1
ln: ‘/path/to/my/linked/directory’: hard link not allowed for directory
Any idea? How do you handle this kind of configuration? I just need to commit everything from /home/me/projects/project1 from a simple svn commit
If I understand your problem, you have:
project1/
project1/link1 -> ../../some/where/else
If you do a simple svn add link1 it adds a symlink entry to the subversion repository, but what you're trying to accomplish is getting the stuff under somewhere else into the tree.
If this is the case, then you're fighting in the wrong direction, you should make the real files and directories under link1, and make the target locations symlinks into the link1 directory. That would be a simple solution to the problem.
Another solution would be to make the location ../../some/where/else an svn location in it's own right, and make link1 an externals definition to that location. When you commit in the main directory, the externals would be committed at the same time which would achieve storing the information; however to ensure that the other location was kept in sync, you would have to make sure to update it to the same version as the stored data.
In my case, on my desktop, I have a settings directory:
$HOME/settings
This is a checked out copy of a directory containing .bashrc, .profile, .vimrc, .vim, etc. files and folders from an svn repo. All my profile files and directories were symlinks into this folder, so for example .profile -> settings/.profile, etc. When I make changes, they are reflected in the svn tree, which I can commit back to in order to ensure that I don't lose my config settings when I go to another system.
If you really want svn to follow symlinks as hardlinks (You can't make directory hardlinks because it would be a bad thing™), then you'll have to hack the svn client source so that it did what you wanted; but this would be a maintenance nightmare.
You could get away with making the symlink into a bind mount point directed at the target, but that has it's own issues - you would need to be root to accomplish this, and it ends up leaving funny entries in your /proc/mounts to accomplish this:
mount --bind /absolute/path/to/some/where/else project1/link1
Bind mounting does not work when mounting to inside the svn tree since the working copy format changes introduced by svn 1.7 - svn operations attempt to move files from .svn/tmp to the target folder, which would be a cross device link. The workaround in this case is to go from the inside out, i.e.:
mount --bind project/link1 /absolute/path/to/somewhere/else
With the change in the svn working copy format of a single .svn folder for the checked out tree, you will need to perform all subsequent operations from the true svn location, as it won’t work from the bind mounted folder, on the assumption that you have not mounted the entire checked out tree at that target location.

svn export all but some directories

I am doing a svn export of the repo to a temp location, then I remove some directories before I copy the code base to a deployment directory.
Is there a way to "exclude" a list of directories during the "export" command?
The reason for this is so that the export is faster (don't need to fetch stuff I remove in this deploy)tail and therefore the deployment script is faster.
You can use the concept of Sparse Directories Exclusion to achieve this. For details on it, you can read it here.
This blog post has also explained the above concept.
Say I no longer care about what’s going on some directory of one my
project working copies. Maybe I don’t care about the Subversion
project’s website any more. Well, with this new exclusion feature, I
can tell Subversion to remove that directory:
$ cd ~/projects/subversion/trunk
$ svn update --set-depth=exclude www
D www
$ ls www ls: cannot access www: No such file or directory
$
Done deal. When I update my working copy in the future, I
will not receive any changes aimed at that www directory. If I later
decide that I once again care about that directory, I can
“resubscribe” to it again:
$ svn update --set-depth=infinity www
A www
A www/links.html
A www/testing-goals.html
…
A www/tigris-permissions.html
A www/webdav-usage.html Updated to revision 36292.
$

Install modx in a subfolder

I like my webspace tidy :)
Therefore if my root-folder is html/ I would like to install modx (version 2.2) in the subdirectory html/modx/
For my website-visitors everything should be the same as if I would have installed modx in the root folder (html/).
I also don't want to do without friendly urls.
To make it even more difficult: I also really like the builtin modx file browser and I would love to use it for every file and folder in the document root (so every file inside html/* should be displayed).
(How) is this possible?
Additional question: if it is possible, is it better to reinstall modx in the subfolder or to move my installation to the new location (html/modx). As my installation is only a few days old, either option would be fine.
What version of MODx are you using?
Usually you would do an advanced installation (a separate version of MODx). You can move the existing MODx install to your sub-directory but you will need to update all of the config.core.php files and MODX_CORE_PATH constants to reflect this. You will also need to leave and update at least the index.php file in your web root directory. The config files that would need updating include:
config.inc.php
manager/config.inc.php
connectors/config.inc.php
core/config/config.inc.php
core/config/config.inc.php is the most important file and you will want to make sure ALL of the paths listed in there are correct.
The file browser will work fine providing you check all the URL and filesystem paths are correct in the Manager settings.
Change your .htaccess setting:
RewriteBase /subfoldername/
and install it as typically you do.

How to block HTTP access to a Git repository?

I'm playing around with the idea of using Git for deployment and updates of my web applications, but the problem is that by doing it the way I'm doing it, the .git directory (and therefore all my source code) would be accessible via HTTP. This is what is holding me back from really implementing this idea.
How do I prevent HTTP access to my Git repository?!
Probably the best way is to not make the Git repo itself your web root, but rather a copy of it (made, perhaps, with git archive). You could also place the .git directory somewhere else in your file system, and then set the core.worktree option to your web root, so when you check out the files they will be written there (but not the .git directory itself).
You can also use a htaccess directive to forbid access to .git from the web.

Resources