Apache 403 on certain folders - apache

I'm running dev server on Centos 6.4 with Apache 2.2. I just moved a site from the production to dev to perform upgrades. I modified file owner to apache:apache (httpd user) and set all directories to 755 and files to 644. I have few other sites in the DocumentRoot folder with similar settings and they run fine (using same CMS, PHP, MySQL versions etc).
I have no virtual hosts defined and Allow all on everything. httpd.conf is default.
I'm not able to make site working from the folder I just moved from the production. I'm getting 403 every time.

As suggested in
https://serverfault.com/questions/272947/apache-on-centos-5-6-gives-me-permissions-denied-error/272956#272956
Usually that comes from Selinux not giving access to the folder. do
ls -alZ /var/www
and if the html folder doesn't have the context system_u:object_r:httpd_sys_content_t, fix it with chcon
chcon -v -R --type=httpd_sys_content_t /var/www/html
http://wiki.centos.org/HowTos/SELinux

Related

PHPmyadmin and Wordpress directories access denied

Running wordpress locally on a centOS 7 server running the latest apache, PHPmyadmin and mariadb-server.
IP/wordpress and IP/phpmyadmin on systems within the local network yields "403 forbidden" "you dont have permission to access (directory) on this server."
How can I fix this to allow the website to be seen on the public internet?
Could be a lot of things.
In your main Apache configuration file (e.g. /etc/httpd/conf/httpd.conf on Arch Linux), confirm your DocumentRoot path. The files you want to serve must reside there, or in sub-directories from there (If not, you might want to use an Alias to specify another path). Since you call IP/wordpress and IP/phpmyadmin, then you probably have directories called wordpress and phpmyadmin under your DocumentRoot path.
You also want to check the Directory groups in your Apache configuration file. Under those, the main culprit would be the Require directive set to all denied or something else too much restrictive like ip your_ip.
Finally, PHP can restrict path access with the open_basedir directive. Look for it in your php configuration file (e.g. /etc/php/php.ini on Arch Linux). If the line is commented, you're fine. But if a path is specified, your wordpress and phpmyadmin files must reside there.
Depending on your setup, any directive mentioned above could be in another Apache configuration file (e.g. /etc/httpd/conf/extra/* on Arch Linux).
Take a look at Apache and PHP online documentation for information about those directives.
Probably there is an issue with your directory privileges.
Use the follwing command to check it:
cd your_site_directory
ls -l
You can have a look to have a better understanding on directory privileges here.
As mentioned here apache runs under "apache" user.
Have a look at this post here to fix the issue.
All files should belong at least to apache group. To do it you can use
cd your_site_directory
chgrp -R apache ./*

Apache can't serve DocumentRoot : no execute permission error

I am trying to migrate a web application from a Slackware config of Apache to a CentOS 7 one. DocumentRoot set to /home/STORAGE and there is a simple index.html file in it for testing. Both /home/STORAGE and index.html have 777 permissions set, yet Apache reports :
access to /index.html denied ... because search permissions are missing on a component of the path.
On the other hand, phpMyAdmin works fine, configured with a separate .conf file in /etc/httpd/conf.d . I tried using their example to make a .conf file for my app, but it still reports the same error. I don't even know where to start looking here.
EDIT:
I think this has something to do with the user of Apache. It is set to a local user in httpd.conf not to root, but the only pages the server serves are those in directories owned by root.
It was not a permission error but a Selinux issue. I decided to use the default /var/www/html for the application but still, had to allow write access to some dirs. Here is what I typed:
sudo chcon -t httpd_sys_rw_content_t /some/dir/in/var/www/html -R
The first time I typed it without -R and the permissions didn't change (check with ls -Z /dir/path). Now it is fine.

Access forbidden on apache2 on ubuntu14.04

I have installed apache2 server on Ubuntu 14.04. It is working well with the files and directories which i have created here after installation, but if i copy any file or folder from anywhere else (already written) then is gives Forbidden error message.
Thanks in advance.
For a file to be accessible by apache2, it should be owned by the user which runs the apache2 server. On most systems the user is www-data or httpd or apache. To find which user is that, just look into your apache2.conf or httpd.conf. Once you know the user, make it the owner of the copied files/folders or reiterate it for the whole /var/www//html folder.
sudo chown -R www-data:www-data /var/www/html
This should do it. But, if it doesn't, verify that the user has at least read and execute permissions on the folder (write also, if you need to write some data through your script).

Amazon EC2 How Do I host My Own Content? Stuck on having a working test apache page

I am using this guide:
http://codingthis.com/platforms/linux/how-to-host-simple-content-with-amazon-elastic-cloud-computing-ec2/
I have a folder named public_html in my /home/ec2-user directory with a test.html file.
What I have done so far:
sudo yum -y install httpd php
sudo chkconfig httpd on
chmod 755 /home/ec2-user (I HAVE NO IDEA WHAT THIS DOES)
sudo nano /etc/httpd/conf/httpd.conf
(changed DocumentRoot to DocumentRoot /home/ec2-user/public_html)
TLDR: How do I make it load my content (my html file) instead of the apache test page
EXTRA:
I have a security group enabled for my instance with rules:
ICMP Allow ALL
TCP Allow ALL
UDP Allow ALL
TCP port 80 (Http)
isnt your document root public_html instead of www? so why did u put ur pages under www directory?
If you have no content in the DocumentRoot that you configured then the default Apache install will show you that page instead of yours. Also, check the DirectoryIndex configuration to make sure that if you're using index.php or default.html or something else that this is configured as well. It defaults to index.html
Chmod755/directory/directory/etc.. Will give access to that directory. So if your website is in the folder *home/ec2-user/public_html* you would then need to give access to that directory.
Example: chmod 755 home/ec2-user/public_html
I was having the same issue. I fixed it by changing the permissions on the ec2-user directory like so:
chmod +x home/ec2-user
This give execution permissions to everyone on your user directory.
I had the same problem. All I have to do was just restarting the ec2 to apply the changes. - takes me 2h :(

Local Development, Apache vs Developer - file permissions

I am interested in setting up a local php testing / development environment using the lamp stack.
I would like to use the php plugin for eclipse (I typically work with java and am very familiar with eclipse).
First of all, is it proper practice to develop my site locally directly within the apache /var/www directory?
If this is ok, can somebody describe how to properly set the permissions of the www directory so that eclipse (not being run as root) has access to read/modify php files within that directory?
This is strictly for local development so I assume security isn't as high of an issue.
It doesn't matter, I personally placed it in /var/www/ and put it under the www-data group, and placed my username into the www-data group.
You add yourself into the group with:
sudo usermod -a -G www-data <username>
Change the group to www-data just in case you haven't:
sudo chgrp -R www-data /var/www
Get new files to inherit the permissions (750)
sudo chmod -R 2750 www-data /var/www
Some people prefer to put it in /home/username/www/ which would be easier.
If you prefer to put it somewhere else, like your Eclipse workspace directory, you can change Apache's DocumentRoot (or create a VirtualHost with a different DocumentRoot). Edit Apache's httpd.conf file, and add this at the end:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName mytestserver.localhost
DocumentRoot /path/to/project/dir
</VirtualHost>
The *s can be left as-is; that means they will work regardless of your IP address.
The ServerName can be anything you want, as long as you add a corresponding entry in your /etc/hosts file, e.g.:
127.0.0.1 mytestserver.localhost
I often make all my local servers end in ".localhost", just as a convention.
Finally, restart Apache. Then you can access the server at http://mytestserver.localhost. Repeat as necessary to use multiple virtual hosts, each pointing to a different project.
As long as the files can be read by everyone, which is usually the default, you should be fine.
It's definitely possible to work on your site directly in your server's /var/www/ directory. however, it's probably better practice to setup a local environment (using something like XAMPP) to edit your website on a development machine and then upload it to your live server when it's ready. that way you don't introduce any bugs or errors into the live site temporarily.