LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   symlinks with apache php, is there an alternative (https://www.linuxquestions.org/questions/linux-server-73/symlinks-with-apache-php-is-there-an-alternative-4175661229/)

Janvanl 09-20-2019 05:30 PM

symlinks with apache php, is there an alternative
 
Hi,

what i want is to point 4 subdirectories in 4 cms's to one physical directory with all images.

I tried using symlinks but the cms will not work with that.

Does someone have an idea on how to solve this?

regards,
Jan

scasey 09-20-2019 06:14 PM

Quote:

Originally Posted by Janvanl (Post 6038812)
Hi,

what i want is to point 4 subdirectories in 4 cms's to one physical directory with all images.

I tried using symlinks but the cms will not work with that.

Does someone have an idea on how to solve this?

regards,
Jan

To be clear, does cms mean Content Management System? If not, what does it mean?

Are you sure that it's the CMS that doesn't work? It could be the apache configuration.
apache symlink usage can be tricky. For example, I've discovered that setting FollowSymLinks for a directory does not propagate to sub-directories. (I was ready to throw a 'puter out the window before I figured that out)

berndbausch 09-20-2019 06:36 PM

Quote:

Originally Posted by Janvanl (Post 603881)

what i want is to point 4 subdirectories in 4 cms's to one physical directory with all images.

I tried using symlinks but the cms will not work with that.

Hard to believe.
Quote:

Does someone have an idea on how to solve this?
Bind mounts are an alternative to symlinks.

Janvanl 09-21-2019 02:56 AM

Thanks for the replies,

cms means content management system, cms made simple a PHP cms.

I have put "Options +FollowSymLinks" and "Options + Indexes" in the htaccess.
Now I do not get an error on the "pwd" anymore that cannot be set, but I jump back to the
root-directory of the cms.

I am testing this on a local machine and with bash I can run ls on the symlink,
it shows all the files in the directory that I put the symlink on.

So it is an apache/php/cmsms problem I guess.

Regards,
Jan

Janvanl 09-22-2019 05:24 AM

Hi,

I used mount --bind and with only one subdirectory that works.

Just what I want is to have a bunch of files (images) in ONE subdirectory and
link this directory to 4 different subdirectories from 4 CMSses so these 4 CMSses
can use the same pool of images.

I looked at "mount --make-shared mountpoint" but it seems to work the other way around.

I consider using rsync and have copies of the images in all subdirectories, but hope
there is a way to avoid that.

regards,
Jan

scasey 09-22-2019 05:36 AM

Quote:

Originally Posted by Janvanl (Post 6038905)
I have put "Options +FollowSymLinks" and "Options + Indexes" in the htaccess.
Now I do not get an error on the "pwd" anymore that cannot be set, but I jump back to the
root-directory of the cms.

I am testing this on a local machine and with bash I can run ls on the symlink,
it shows all the files in the directory that I put the symlink on.

So it is an apache/php/cmsms problem I guess.

Regards,
Jan

What do you mean by 'on the "pwd"'? How are you running pwd inside your php code?
What do you mean by "jump back to the root-directory..."

How are you defining the symlinks?
Show us the relevant section of your config/htaccess.
Show us the section of the php that's using the linked directory.

Once the symlink is set up, and +FollowSymLinks is set for the directory where the symlink is, the browser should just treat it like a real directory.

Janvanl 09-22-2019 06:29 AM

Thanks for the reply,

pwd - working directory, I got an error because the filemaneger inside CMSMS could not set the pwd (working directory)
pwd - print name of current/working directory (bash)

"jump back to the root-directory..."
I made a symlink to another directory outside the directory-tree for the CMS ln -s /var/www/ap ap
The CMS stores images in "[rootdir]/uploads/images" I made a subdirectory ap "..../uploads/images/ap" to which the symlink points.
On the commandline I can use "ls" and I get what I expected.
When I used the filemanager from the CMS and clicked the symlinked directory "ap", I jump to the "rootdirectory" of the CMS

defined the symlink
from directory /uploads/images
sudo -u www-data ln -s /var/www/ap ap

.htaccess just 2 lines because I test it on localhost
Options +FollowSymLinks
Options +Indexes

The PHP-Code of Filemanager of the CMS made with Smarty I will have to ask where to find it,
I am not the programmer.


regards,
Jan

ondoho 09-22-2019 07:34 AM

Try to narrow it down - is apache causing this to not work, or something inside all 4 CMS's (the latter seems unlikely)?
Do some testing without any CMS first - does the server serve symlinked directories at all?

And show us. Output, commands, logs...

Janvanl 09-22-2019 07:46 AM

Hi ondoho

the CMS is CMS Made Simple. I am testing local - the filemanager is the same.
So if CMSMS cannot handle symlinks it will not work for all of them.

The idea to test without CMSMS is good, I will do that now.

Be right back again.

regards,
Jan

ondoho 09-22-2019 08:13 AM

Quote:

Originally Posted by Janvanl (Post 6039308)
I am testing local - the filemanager is the same.

I don't understand this sentence.
Also CMSMS is only one - of four?

ehartman 09-22-2019 08:14 AM

Quote:

Originally Posted by Janvanl (Post 6039308)
So if CMSMS cannot handle symlinks it will not work for all of them.

Check too if the file or directory linked TO is within the apache "chroot" tree (often /var/www/htdocs) as apache cannot see ANY directories above it (or otherwise not below that directory).

Janvanl 09-22-2019 09:06 AM

OK
the symlink will not work without CMSMS either,

Thanks ehartman, I am trying this all within 1 Apache-install, all below var/www,
linked is to a subdirectory 2 levels below the sites root.

I will do this again on a test-install on the server where it should come because
if it works there then the problem is solved.

regards,
Jan

scasey 09-22-2019 09:24 AM

I'm going to ask this again, because you didn't answer specifically.
Is the +FollowSymLinks for the directory where the link is? That is:
Code:

<Directory /var/www/>
    Options +FollowSymLinks
    Options +Indexes
</Directory>

And /var/www/ap looks like
Code:

lrwxrwxrwx.  1 someuser somegrp        27 Apr 29 12:04 /var/www/ap -> /path/to/otherdir/
Again, Option +FollowSymLinks is specific to the directory for which it is defined. It does not propagate to sub directories as some other Options do.

PS Options can be specified on one line...
Code:

Options +FollowSymLinks +Indexes

scasey 09-22-2019 09:32 AM

Quote:

Originally Posted by ehartman (Post 6039324)
Check too if the file or directory linked TO is within the apache "chroot" tree (often /var/www/htdocs) as apache cannot see ANY directories above it (or otherwise not below that directory).

I note this in httpd.conf:
Code:

# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.

(emphasis added)
So, a working symbolic link can point outside the DocumentRoot (apache "chroot") tree, but of course the symbolic link itself must be within the DocumentRoot tree. (unless Aliased...but let's not go there today) :)

ehartman 09-22-2019 09:32 AM

Quote:

Originally Posted by Janvanl (Post 6039350)
nks ehartman, I am trying this all within 1 Apache-install, all below var/www, linked is to a subdirectory 2 levels below the sites root.

Another observation: I do not know how strong the "chroot" in Apache is (never used this myself), but you might try to use relative, not absolute, paths for the links as "/" may not be the same for Apache as for the whole filesystem.
So if the directory you want to link TO is /var/www/htdocs/some/dir
and the link should be in the directory /var/www/htdocs/somewhere/else
create the link by using
Code:

cd /var/www/htdocs/somewhere/else
ln -s ../../some/dir <name of the link>

so that you never have a pathname with "/" as the starting directory.


All times are GMT -5. The time now is 01:01 AM.