symlinks on apache (centOS) - .htaccess

I have a VPS for hosting sites and I'm trying to get Apache to follow symlinks but cannot figure it out. I've Googled for the past couple hours and everything seems really confusing. I don't know anything about htaccess mod_rewrite engine so that's not available.
Basically, I have a resources folder that's not in the root directory of one of the sites, it's inside another directory but I'd like a symlink in the root so that it appears to be both in the root directory AND in that other directory.
So the original is /sub/resources
and I want a symlink /resources to link to /sub/resources
Everything I try I get an Apache permission denied error. I'm creating the symlink with the root user using ln -s and setting permissions of the symlink to 755.
I've tried adding Options +FollowSymlinks to my root .htaccess file.
Also tried going to the httpd.conf file and ensuring it has
<Directory />
Options FollowSymLinks
AllowOverride Indexes
</Directory>
Very frustrating. Any suggestions?
Thanks,
Scott

Related

Change the location of the public(www) Apache folder on debian 8

I am facing a peculiar problem with apache2 running on debian 8. I followed a couple of tutorials to install it and everything worked great. The problem is that i have partitioned the disk as 9gb for the system files, 1gb swap and 30gb for the home folder so I wanted to move the www folder from it's current location (/var/www) to home(/home/www).
I found more than a few guides on how to do that, some saying that i should change the lines in apache2.conf from this:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
to this:
<Directory /home/paul/www/>
Options Indexes FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
</Directory>
As well as the documentRoot
Others suggested using the 000-default.conf file located in the /etc/apache2/sites-available folder and change the default folder from /var/www to /home/paul/www.
I did both and the folder was seen but not accessible, so i used the quick solution and use chroot 777. After that apache redirected me back to /var/www.
All settings point to /home/paul/www and the www folder has full read write permission. In fact neither the apache.conf nor 000-sites-available has any reference of /var/www so why does apache keep pointing me there? Is there something i missed?
p.s i did updates and upgrades multiple times as well as restarted the apache service and the entire pc.
you need to change the ownership of files to allow apache there
please try
chown -R www-data /home/paul/www/
however if you set a particion for your paul www why not mount the partition in /var/www
or you can create a symlink
ln -s /home/paul/www /var/www/paulsite
then edit your apache conf accordingly.
Regarding the edited file I recomend you use the 000-default better. in fact i would use that as a skeletone. and create a new file for your site then enable that site.
Ok so with a little research i realized that what i was trieing to do was not the best practice at all! (Thanx for the heads up Sudakatux).
I found the solution in askubuntu for anyone interested.
Instead of trieing to change the mechanics of apache i enabled the userdir module and set up public_html in my home folder with 755 permissions. I use a redirection script from the initial location to the various locations on my home directory. Works just fine!

how to give read premission to a folder using htaccess

i have 2 or more subfolders in my website. And i need to give read-only permission to all my sub-folder for protect from hacking.
Is there any way to do this?
chmod -R 777 where -R makes it recursive, so all underlying files of that folder will be set to the same permission, 777 in my example.
you need to do chown -R www-data:www-data your-directory-here
(here, www-data is the default apache username under debian 7)
and then chmod 711 your-directory-here.
But there's no way to set permissions using .htacces, it's all or nothing with .htaccess, but the web user is considered as apache, so www-data.
If you don't want users to acces to your directory on apache, simply edit /etc/apache2/sites-enabled/000-default and edit this:
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
like this:
<Directory />
Options -FollowSymLinks
AllowOverride None
Options -Indexes
</Directory>
Options -Indexes Disallows users to view your directory indexes
Options -FollowSymLinks Disallow apache to follow Symbolic links (don't edit this one if you need apache to follow some symbolic links).
btw, apache folders can't be edited from web client, you need a ssh access for that.
If you're using FileZilla or a similar FTP client you can right click on anything then use the UI to select permissions regarding every aspect of the file.

symlink hundreds of wordpress websites

PHP programmer here. Boss wants me to create multiple wordpress websites that are symlink'ed back to a single parent wordpress directory. Each website resides in a separate Linux user account. In other words, one parent, many children copies, all residing in different /home/ accounts. I need help with my symlink strategy...
So far, for each new linux web account,
install the database
sed replace config values into a temp config file
mysql insert some config data
symlink????
a. every wordpress file ??
b. the entire public_html directory ??
If I alter the parent wordpress PHP code, I can place a "real" copy of the config file in the child user directory, above the symlinked public_html. So, I need only use one child symlink to the parent's public_html directory. BUT, apache returns a 500 error. How do I set up the permissions?
Permissions are the issue. Would chgrp work? Which group? What file mode? Or would I need to create a special group to accommodate the apache user, nobody?
Any help would be greatly appreciated. Code samples welcome :)
Problem's Cause (paranoid security, "switch-user" blocking):
PHP 5 Handler suphp
Suexec on
Problem's solution (DSO):
PHP 5 Handler dso
Suexec off
Performance optimization, added +FollowSymLinks at httpd.conf LINE 75:
<Directory "/">
Options All +FollowSymLinks
AllowOverride All
</Directory>
Each linux user must have a wp-content directory and a wp-config.php file. Don't forget to set writing permissions to the wp-content directory.
You can symlink the rest of the wordpress files to the global wordpress ones.
The global wordpress files must not be writable by the linux users.
This is very possible to do. I have actually written a detailed post explaining the process of symlinking the WordPress directory.
Basically the idea is to replace the wp-config.php file.
Download the repo for WordPress from github with this you can switch to newer or older version of WordPress with a simple command. "git checkout 3.7-branch"
Here is the complete set of instructions:
http://www.htmlgraphic.com/symlinking-wordpress-core-files-wordpress-skeleton/

How to change DocumentRoot to a custom folder

I got my new VPS server with CentOS 5.8, I could not transfer my domain yet but I want to reach my site via http://my-server-ip and since I am using laravel framework I need to change default DocumentRoot httpdocs to httpdocs/public I have tried to put those lines to httpd.conf file:
<VirtualHost my-server-ip:80>
DocumentRoot /var/www/vhosts/my.domain.org/httpdocs/public
ServerName my.domain.org
</VirtualHost>
However after restarting apache it warns me like this:
Warning: DocumentRoot [/public] does not exist
What should I do?
You'll need to enable read (and possibly execute) privileges on the directory. As root try:
# Recursively set the owner of this folder to 'www'
chown -R www /var/www/vhosts/my.domain.org/httpdocs/public
# Recursively give the owner read and execute privileges
chmod -R u+rx /var/www/vhosts/my.domain.org/httpdocs/public
As an alternative on some setups the user might be called nobody. So if www doesn't work try:
chown -R nobody /var/www/vhosts/my.domain.org/httpdocs/public
EDIT:
As user tink pointed out in the comments
"...in Centos the user running apache is aptly called apache. In debian and it's derivatives, it's www-data."
might be that the apache user can't get into the new directory. try
chmod a+r /var/www/vhosts/my.domain.org/httpdocs/public
I had the same "403 page" problem. Just after I changed Document Root in my /etc/apache2/conf-available/sitename.conf from /var/www/html to /data/www.
To solve the problem I did the folowing:
1) Utilized chown and chmod examples, provided by Mike (2 posts above). Many thanks to him;
2) Added 2 lines to the end of /etc/apparmor.d/abstractions/web-data as follows:
/data/www/ r,
/data/www/** r,
and then run:
sudo service apparmor reload
3) I also needed to add the following bit of code to my apache.conf:
<Directory /data/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
May be some actions were superfluous, but It worked pretty nice for me (Apache v2.4.7, Ubuntu 14.04.1)

Apache <Directory> not applying to subdirectories

I'm running the latest Apache Server on Linux Mint 14 and trying to take my first babysteps with vhosts, where I encountered a general problem with my setup:
every option I declare in the <Directory> section doesn't seem to have any effect on any subdirectories - but as far as I know and according to the documentation it should.
For example: I'm trying to give permissions for .htaccess file by
<Directory /var/www/>
AllowOverride All
</Directory>
a .htaccess in /var/www would work properly, but e.g. a .htaccess in /var/www/test with contents "Deny from all" would take no effect.
Are there any options I have to set that I don't know of? This isn't my first apache setup so I'm kind of confused right now, but I can't find a solution.
Thank you in advance!
Got it, apache2.conf includes external vhost settings, so the default settings in sites-available/default kept overwriting mine.

Resources