I have some issues with my server, for example public_html is my root folder, if I put any php file in root I have this error:
403 Forbidden
You don't have permission to access /check.php on this server.
I try to change permissions on the file is the same. Now the php file is with 0644 permissions
How I can solve this?
Thank you
this is what httpd conf
<Directory "/">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
Allow from all
</Directory>
<Directory "/usr/local/apache/htdocs">
Options All
AllowOverride None
Require all granted
</Directory>
<Files ~ "^error_log$">
Order allow,deny
Deny from all
Satisfy All
</Files
Check if your public_html folder has 755 permission.
If this doesn't work, check if In your /usr/local/apache/htdocs/httpd.conf settings are like the below
<Directory "/usr/local/apache/htdocs">
Options Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
If the settings are correct there, check your .htaccess file.
Last but not the least. Check if your files and folders have the save usergroup as public_html folder
that means you do not have the required permissions to access this file.
open a terminal in that directory and write
ls -l check.php
If the owner of the file isnt www-data or some server user then you have to change it with
chmod 755 check.php
chown www-data:www-data check.php
Related
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.
How can I deny access permission to an entire folder except one file?
For example, my DocumentRoot is "/var/www/html" and there I have a folder called example. In there, there are many files and one of them is index.php. So I want to give access permission only to this file, and deny access permissions to the other files in that folder.
did you try something like this into your apache configuration (server httpd.conf or .htaccess file) ?
<Directory "/var/www/html/example">
<FilesMatch index.php*>
Order allow,deny
Allow from all
</FilesMatch>
Order deny,allow
Deny from all
</Directory>
OK, I've been having some issues with aws or something, such that I cannot seem to get mod_rewrite to work.
Just for testing purposes I've done the following:
1 used aws console to deploy fresh ami 64 bit instance from wizard
2 yum installed apache
3 edited /etc/httpd/conf/httpd.conf:
so that
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
looks like
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
4 made sure that
LoadModule rewrite_module modules/mod_rewrite.so
is in the file and uncommented.
5 restarted apache:
sudo /sbin/service httpd restart
6 created two new files:
/var/www/html/test1.html
contains:
this is test1!
/var/www/html/test2.html
contains:
this is test2!
7 created file:
/var/www/html/.htaccess
contains (IN TOTAL):
RewriteEngine on
RewriteRule ^test1\.html$ test2.html [L]
8 went to:
http://[my aws server]/test1.html
Am getting "this is test1!"
I am doing something wrong here, but for the life of me I have no idea what. Any help is greatly appreciated...
EDIT: I added nonsense chars/numbers to the beginning of my .htaccess file, and restarted apache (not 100% sure that is needed, but what the hey...), and nothing happened. In other words, I expected that going to the url [aws server]/test1.html would result in some kind of error, but it did not. I suspect apache is not even reading the .htaccess file.
EDIT: I added the following to my httpd.conf file:
RewriteLog "/tmp/rewrite.log"
RewriteLogLevel 9
The file is created when I restart apache, but nothing ever goes in there when I go to either page I've set up. I'm failing to do something very, very basic here, but I'm not sure what...
Not sure if this is the cause of your problems, but you shouldn't mess with the
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
line, and it should be something like:
<Directory />
Options FollowSymLinks
AllowOverride None
Deny from all
</Directory>
You should add the directory of your document root as a different container:
<Directory /var/www/html/>
Options FollowSymLinks
AllowOverride All
Allow from all
</Directory>
Took me a while to find this but in some installs Apache will use multiple config files.
Look in "/etc/apache2/sites-enabled/000-default" and check that AllowOveride is set to All
Try it. This work for me.
The first, you need to make sure the .htaccess file put in correct directory.
For this, you go to sites-enabled folder and check which the .conf files are enabled.
cd /etc/apache2/sites-enabled
ls
Ex: 000-default.conf
Then, goto sites-available folder to edit that .conf file.
cd ../sites-available
sudo gedit 000-default.conf
Find to DocumentRoot and check directory again.
If you put .htaccess file in /var/www/html/.htaccess so this line look like this:
DocumentRoot /var/www/html/
The second, You need modify <Directory> block look like this.
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
#RedirectMatch ^/$ /apache2-default/
</Directory>
Finally, you save file and restart apache
service apache2 restart
Hope this help!
I need to allow directory listing only for a particular directory: /var/www/test. I followed the steps given here http://wiki.apache.org/httpd/DirectoryListings but I am doing something wrong because of which I get Forbidden 403 message if I browse http://localhost/test. Following is what I have in my /etc/apache2/sites-available/test. Can you spot any error with this config?
<VirtualHost *:80>
DocumentRoot /var/www
<FilesMatch index.html>
deny from all
</FilesMatch>
<Directory /var/www/php/>
AllowOverride None
deny from all
</Directory>
<Directory /var/www/>
AllowOverride None
</Directory>
<Directory /var/www/test>
Options +Indexes
AllowOverride All
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
The Order you're specifying for /var/www/test is deny,allow, so the Deny from all on /var/www is taking precedence over the Allow from all for /var/www/test. Switch that to allow,deny and you'll get the behavior you're expecting.
I'd also strongly recommend that you remove the <FilesMatch index.html>. It'll just cause you problems down the road. index.html has nothing to do with automatic directory indexing; it's only involved when you've explicitly created such a file, so this directive will just keep normal index.html files from ever working.
Iam trying to redirect my home page or any other page on the site to a particular php page .
This is my htaccess
Redirect 301 http://test.com/info http://test.com/get_forms_data.php
Options +FollowSymlinks
RewriteEngine ON
RewriteRule ^test.php$ http://test.com/get_forms_data.php [R=301,L]
I have checked my apache server .rewrite is enabled .
It still doesnt work .
If no matter what you put into your .htaccess file, you don't even get an error, that means that you probably need to have
AllowOverride All
set in your site configuration.
If you're on ubuntu, the place to look for the configuration is /etc/apache2/sites-available/. There you should find a file called default if this is a stock install of the default LAMP stack (https://help.ubuntu.com/community/ApacheMySQLPHP).
The key part there is this:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
Now change AllowOverride None to AllowOverride All. After that don't forget to restart your apache like so:
$ service apache2 restart
As an addition to Morgan's answer, putting AllowOverride All in your virtual host is sometimes not enough. I had this in my virtual host:
<VirtualHost *:80>
...
<Directory />
...
AllowOverride All
...
</Directory>
</VirtualHost>
You would expect this to work, wouldn't you, <Directory /> means it should be applied to everywhere on the file system. But .htaccess was still being ignored. Restarting the server did not help. I put junk in the .htaccess file to confirm it was not being read.
My mistake was assuming a virtual host overrides the global configuration. Kind of it does: my above configuration overrides any global settings for the / directory. But the global configuration overrides it back for /var/www/ and below. My fix is:
<VirtualHost *:80>
...
<Directory /var/www>
...
AllowOverride All
...
</Directory>
</VirtualHost>
(this assumes none of the other configuration needed to apply outside /var/www; if it does, make a separate <Directory /> block for just that special configuration.)
I was struggling with the same problem, and Darren Cook's answer gave me the definitive clue to find the solution.
My app was in some folder out of th public www path, lt's say in /opt/my_app.
I couldn't create a VirtualHost, so I created a symlink in Apache's public www ponting to my folder:
/var/www/html/my_app -> /opt/my_app
The thing is, in my App's Apache config file, I was specifying:
<Directory /opt/my_app>
AllowOverride All
</Directory>
And my .htaccess file wasn't being read. Then I saw that in Apache's configuration there was this:
<Directory /var/www/html>
AllowOverride None
</Directory>
Then I realised that Apache config files do not care about symlinks, and therefore the general rule was being applied to my App's foler. I changed Directory to:
<Directory /var/www/html/my_app>
AllowOverride All
</Directory>
And everything worked.
If Redirection doesn't work inspite of updating apache2.conf
According to the accepted answer, I updated AllowOverride None to AllowOverride All in the apache2.conf file, however redirection via .htaccess file was still not working for me!
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All # did not work inspite of setting to "All"
Order allow,deny
allow from all
</Directory>
What worked for me...
I had to also enable module redirection
// enable module redirection
sudo a2enmod rewrite
Of course, do not to forget to restart your apache server for the changes to take effect
Reference
Assuming /var/www/html is the working directory:
Change from AllowOverride None to AllowOverride All
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>