403 Forbidden, Index of / catch 22 - wordpress

I'm having a really rough time on this one and have tried a ton of solutions which have worked for certain people but not for me. Firstly my set up:
Ubuntu 14.04.2
Apache 2.4.7
I'm currently migrating my site to wordpress into the folder structure /var/www/dev which is set up as a virtual host - dev.conf looks like:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
ServerAdmin ubuntu#12.345.678.90
DocumentRoot /var/www/dev
ServerName dev.mysite.com
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/dev/>
Options -Indexes +FollowSymLinks
AllowOverride All
#Require all granted
Order allow,deny
allow from all
</Directory>
</VirtualHost>
My problem is that when I access my home page in a browser for the first time dev.mysite.com it directs me to a 403 page:
Forbidden
You don't have permission to access / on this server.
I also have an .htaccess file in my root folder that looks like this currently:
DirectoryIndex index.php index.html
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I followed 2 different sets of advice so far - one saying to change my config Option to:
Options +Indexes
However when i navigate to my home page it gives me the physical folder "Index of /" with a list of all my files and folders - which I don't want. So I've left it as
Options -Indexes
Another set of advice said add this to the htaccess file:
DirectoryIndex index.php index.html
I've also checked my folder permissions, all owned by my apache user admin ubuntu:ubuntu and all follow the standard wordpress folder permissions e.g. all folders are 755 all files are 644 (rough rule of thumb).
I've also tried as you can see (commented out above) using the new apache 2.4 standard
Require all granted
instead of
Order allow,deny
allow from all
I'm also restarting the server every time I make a change so nothing silly like that. What am I doing in the above config that's not letting me load my site?
Specifically my homepage goes to 403 Forbidden, any other page e.g. dev.mysite.com/features loads this error message:
User-agent: *
Disallow: /wp-admin/
EDIT:
The above issues only occur when the url is loaded initially - if I refresh the page it loads as it should.
Here's my file ownership structure - perhaps this may provide useful:
-rw-rw-r-- 1 ubuntu ubuntu 350 Sep 26 19:35 .htaccess
-rw-rw-r-- 1 ubuntu ubuntu 4951 Sep 9 13:21 wp-activate.php
drwxrwxr-x 9 ubuntu ubuntu 4096 Sep 9 13:21 wp-admin
-rw-rw-r-- 1 ubuntu ubuntu 271 Sep 9 13:21 wp-blog-header.php
-rw-rw-r-- 1 ubuntu ubuntu 5007 Sep 9 13:21 wp-comments-post.php
-rw-rw-r-- 1 ubuntu ubuntu 3130 Sep 24 10:32 wp-config.php
-rw-rw-r-- 1 ubuntu ubuntu 2764 Sep 16 17:23 wp-config-sample.php
drwxrwxr-x 6 ubuntu ubuntu 4096 Sep 24 10:46 wp-content
-rw-rw-r-- 1 ubuntu ubuntu 3286 Sep 16 17:23 wp-cron.php
drwxrwxr-x 12 ubuntu ubuntu 4096 Sep 9 13:21 wp-includes
-rw-rw-r-- 1 ubuntu ubuntu 2380 Sep 9 13:21 wp-links-opml.php
-rw-rw-r-- 1 ubuntu ubuntu 3123 Sep 9 13:21 wp-load.php
-rw-rw-r-- 1 ubuntu ubuntu 34669 Sep 16 17:23 wp-login.php
-rw-rw-r-- 1 ubuntu ubuntu 8252 Sep 9 13:21 wp-mail.php
-rw-rw-r-- 1 ubuntu ubuntu 11062 Sep 16 17:23 wp-settings.php
-rw-rw-r-- 1 ubuntu ubuntu 25124 Sep 16 17:23 wp-signup.php
-rw-rw-r-- 1 ubuntu ubuntu 4035 Sep 9 13:21 wp-trackback.php
-rw-rw-r-- 1 ubuntu ubuntu 3055 Sep 16 17:23 xmlrpc.php

Forbidden 403 simply means that there is some problem with permissions. When server is trying to access the requested resource then it is being restricted due to permission issues, so those who were advising on modifying Indexes weren't even close because Indexes option is to control the directory listing. Below is excerpt about Indexes option from Apache
If a URL which maps to a directory is requested and there is no
DirectoryIndex (e.g., index.html) in that directory, then
mod_autoindex will return a formatted listing of the directory.
Clearly root cause of your issue is "permissions".
Now, for the solution part - since I don't know your all the content of your .htaccess and dev.conf, so below your be my step by step approach:
Try below code snippet. I am trying to disable your .htaccess files effect and see if that's root cause. If it works then you to review all the content of your .htaccess for possible issue.
<Directory /var/www/dev/>
Options -Indexes +FollowSymLinks
AllowOverride None
Order allow,deny
allow from all
</Directory>
Try below code snippet. Default Apache access for Directory is Allow from All, so I am removing it and let default take effect and no ordering .. Anyways you were also trying same thing ..
<Directory /var/www/dev/>
Options -Indexes +FollowSymLinks
AllowOverride All
</Directory>
On a side note, I would suggest that first try to do chmod 777 for your web app directories and files, because in most cases permission issue is because of UNIX permissions and not Apache permissions.
Followup edit:
For further debugging we will need server error info, can you enable maximum debugging and get the content from error.log and access.log (if HTTPS access then from ssl log). Reference
Also, could you please provide context of DirectoryIndex directive and URL you are using.
All odds are that you have permission issue, may be because of Apache or UNIX.
So, lets first comprehensively rule out UNIX permissions issue, so momentarily try out chmod 777 for your web app resource, if it works we know it is UNIX permission issue and we will see what to do next.
I am getting skeptical about RewriteBase / and RewriteRule . /index.php [L] in your .htaccess file .
Give a try to RewriteBase /var/www/dev or whatever you think could be more relevant but NOT /
Also, try to play around with RewriteRule, so instead try absolute path of index.php, so use RewriteRule . /var/www/dev/<<XYZ>>/index.php
Give a try using exact below, if you don't have mod_cgi module included then you may need to.
<Directory "/home/domain/www">
Options +Indexes FollowSymLinks +ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Final solution:
For those who are looking for solution - once OP recursively granted permission using chmod -R www:data, he could solve this issue. So, to conclude - this issue was not because of Apache configuration but because of UNIX permissions. Read OP's comments below for more details.

Related

Permission denied on Centos7, Apache, Mod Passenger and Ruby 2.6.3

I never tried working with Cent-OS for hosting my Rails applications. I was using before and now I got a server which is running Cent-OS 7. I installed Apache, Phusion Passenger, RVM, Ruby 2.6.3 and bundle updated the Rails app. Everything was fine up to this.
I added the Virtual-Host and restarted the Apache2 server, I got 403 Forbidden message from the browser.
Also I checked the error_log I got the following errors.
[Tue Feb 11 08:34:14.377938 2020] [core:error] [pid 125490] (13)Permission denied: [client 172.69.78.16:30474] AH00035: access to / denied (filesystem path '/home/santosh/sites') because search permissions are missing on a component of the path
[Tue Feb 11 08:34:14.593925 2020] [core:error] [pid 125490] (13)Permission denied: [client 172.69.78.16:30474] AH00035: access to / denied (filesystem path '/home/santosh/sites') because search permissions are missing on a component of the path
The virtual host:
<VirtualHost *:80>
ServerName domain.com.np
ServerAlias www.domain.com.np
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
# ModPagespeed on
# Tell Apache and Passenger where your app's 'public' directory is
DocumentRoot /home/santosh/sites/app/public
PassengerRuby /home/santosh/.rvm/gems/ruby-2.6.3/wrappers/ruby
# Relax Apache security settings
<Directory /home/santosh/sites/app/public>
Allow from all
Options -MultiViews
# Uncomment this if you're on Apache >= 2.4:
Require all granted
</Directory>
</VirtualHost>
And the permission of the app directory is as:
drwxrwxr-x. 4 santosh santosh 31 May 18 2019 app
I couldn't figure out what I am missing. Please help me.
Have you checked the folder permissions on the server, try running 'ls -l' on your folder.

Error 404 post name permalink wordpress

I have just migrated my WordPress site from a Windows to a Linux server. Everything seems to work except the posts with the permalinks set to /%postname%/. I assumed this was mod_overwrite issue.
I have changed the httpconf file from AllowOverride None to AllowOverride All
And then reset the server just to make sure it took effect.
My .htaccess looks like this:
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
I'm running Apache 2.2 on CentOS5 on a dedicated server.
To add: all the pages are working except the posts with these custom permalinks.
I have set permission to 666 for the .htaccess
The same happened with me too. It turned out that .htaccess was not the issue for me. The issue was in server configuration file.
For AWS EC2 server:
Step 1: Edit configuration file
sudo nano /etc/httpd/conf/httpd.conf
Edit this file and change
<Directory /var/www/html/wordpress/>
AllowOverride None
</Directory>
to
<Directory /var/www/html/wordpress/>
AllowOverride All
</Directory>
Note that here, /var/www/html/wordpress/ is path to the root folder where WordPress project was hosted.
Step 2: Restart server
Please don't forget to restart your server after you do the changes to the .conf file.
sudo service httpd restart
For Ubuntu server:
Step 1: Edit configuration file
sudo gedit /etc/apache2/apache2.conf
Edit this file and change
<Directory /var/www/html/wordpress/>
AllowOverride None
</Directory>
to
<Directory /var/www/html/wordpress/>
AllowOverride All
</Directory>
Note that here, /var/www/html/wordpress/ is path to the root folder where WordPress project was hosted.
Step 2: Restart server
Please don't forget to restart your server after you do the changes to the .conf file.
sudo service apache2 restart
Keep AllowOverride none.
Remove the .htaccess file and any trace of that messy set of rewrite rules and just add this in virtualhost:
FallbackResource /index.php
Neither mod_rewrite, neither .htaccess are needed.
By adding per-dir configurations you are basically complicating your life. Everything will be much harder to do, for what? to have dynamic changes by changing a file? .htaccess is meant for non-admin users who need to modify directory configurations.
Since you are the admin, configure everything possible in Virtualhost instead.
Giving rw permissions to everyone to files is definetly not the way to go either. httpd does not need write access to anything.

Apache www-data group write permissions to modify Wordpress not working

I'm trying to give write permissions to Apache www-data group to be able to install new plugins directly from Wordpress webadmin console but it seems like these permissions are ignored.
I have to give write permissions to www-data user and everything works fine. But why user and not just group?
I'm working on Debian 7.5 with LAMP (Apache 2.2, php5, MySql 5.5) stack and Wordpress 3.9.1.
Wordpress folders are on /var/www/mysite and the website is managed by a virtual host:
<VirtualHost *:80>
ServerName my.site.com
ServerAdmin thewebmaster#localhost
DocumentRoot /var/www/mysite
ErrorLog ${APACHE_LOG_DIR}/mysite-error.log
CustomLog ${APACHE_LOG_DIR}/mysite-access.log combined
</VirtualHost>
www-data group seems ok getent group www-data says www-data:x:33:www-data and file permissions too. Showing ls -l this works...
drwxrwsr-x 5 www-data www-data 4096 Jun 19 07:22 mysite
and this doesn't (with root user as owner):
drwxrwsr-x 5 root www-data 4096 Jun 19 07:22 mysite
Any suggestions? Thanks in advance

wordpress permalinks not working - htaccess seems ok but getting 404 error on pages

I updated the permalink structure to /%postname%/ and this updated my .htaccess with:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
But I still get 404 errors on the pages. Are there any other settings that I need to change?
Edit: if it helps the apache log seems to be looking directly in the permalinked folder. I.e.:
[Wed Oct 16 11:12:32 2013] [error] [client xx.xx.xx.xxx] File does not exist: /var/www/exampledomain/news, referer: http://exampledomain.com/
For other people landing on this page -
Another issue could be (If you are using Apache as your web server) is your httpd.conf or your sites-available/sitename.conf file needs editing.
Your web directory will need to allow the .htaccess file to override it's settings.
look for your web dir in the file - it will be in the bulk of the conf file or segregated into a VirtualHost section.
<Directory /path/to/site>
#add the following setting to allow .htaccess in your web dir to work
AllowOverride FileInfo
#other settings ---
</Directory>
This will allow you to set up WordPress URLs however you want, within WordPress.
***Edited - Thank You nietonfir For update. Use the least amount of privilege at first. If this doesn't work then replace AllowOverride FileInfo with AllowOverride All
There can be multiple things preventing the rewrite rule from working. My ubuntu server needed 3 things changed to get permalinks working.
In newer versions of apache2, you need to enable the module:
sudo a2enmod rewrite
sudo service apache2 restart
You may also need to modify the apache2.conf file.
sudo nano /etc/apache2/apache2.conf
Change your web directory override rule to AllowOverride All.
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
After that, restart the service again.
The .htaccess file in the WordPress install directory needs to be owned or readable/modifiable by the webserver.
This can be accomplished by changing owner to www-data (usually the webserver user), or changing permissions.
sudo chown www-data /var/www/wordpress-install/.htaccess
OR
sudo chmod 664 /var/www/wordpress-install/.htaccess
Login to your Wordpress admin backend and save the permalink settings, and they should hopefully be working.
This is now solved. I hadn't enabled mod_rewrite. So I did this:
$ sudo a2enmod rewrite
Enabling module rewrite.
To activate the new configuration, you need to run:
service apache2 restart
$ service apache2 restart
* Restarting web server apache2
You would want to tell apache to follow your .htaccess file. You can do this by editing the apache.conf file
$sudo nano /etc/apache2/apache.conf
Scroll down to the line
By default it will be:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
change the value of AllowOverride to All so now it becomes:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Press ctrl+x and press y to save the configuration file. In order to make this changes to server first enable the mod_rewrite by.
$ sudo a2enmod rewrite
And then restart the server
$ sudo service apache2 restart
Done!
Source: https://www.wst.space/riddling-with-wordpress-permalink-setup-issues/
use below .htaccess code, just put your project name (which is in www directory) in below code
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /project_name/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /project_name/index.php [L]
</IfModule>
# END WordPress
Thanks
I was facing with the same problem and had one more thing to look for.
Here is what you need to do for wordpress permalinks work properly:
Make sure you have the proper permission modes for files and folders in your wordpress directory:
sudo find . -type f -exec chmod 644 {} +
sudo find . -type d -exec chmod 755 {} +
For permalink structure make sure mode_rewrite is enabled in apache:
sudo a2enmod rewrite
sudo service apache2 restart
One more thing to check if this describes your problem:
htaccess and mod_rewrite are set up correctly
404 error on some permalinks but not others
Ensure that there are no existing .php files or directories in the same folder as your Wordpress install with names matching a Wordpress permalink.
For example, if you have the following Wordpress page permalinks:
example.com/name_one/
example.com/name_two/
and the directory containing your Wordpress install includes the following file:
name_one.php
then this will be the result:
http://example.com/name_two/ – this permalink will work
http://example.com/name_one/ – this permalink will NOT work
More importantly, the second URL will give a 404 instead of running name_one.php, meaning this problem is hard to diagnose, as it can give the same symptoms as an incorrectly written .htaccess file.
If you are setting up a new or cloned site on ubuntu, remember to symlink the site configuration file e.g. /etc/apache2/sites-available/your-file.conf to the /etc/apache2/sites-enabled folder so apache loads it.
Just run: sudo a2ensite your-file.conf, then sudo service apache2 reload.
sudo a2dissite your-file.conf to remove symlink i.e. disable config.
Users of WAMP (Windows): Some versions of WAMP (all versions?) do not enable mod_rewrite or permit following SymLinks by default. To enable the required functionality navigate to the apache/conf/httpd.conf file, open with a text editor and uncomment the line LoadModule rewrite_module modules/mod_rewrite.so (i.e., delete the hash/pound sign at the front of the line). Then further down in the same file there is a section that starts with the line "Options FollowSymlinks". Change the second line in that section from "AllowOverride none" to AllowOverride all. Save edited httpd.conf and restart all WAMP modules. Your permalinks should now work.
For more details, Fixing Permalink Problems
Yet another possibility: I just updated my macOS which always screws up the Apache config file. Among other things, I also had to re-enable the mod_rewrite module. Find the line that says,
#LoadModule rewrite_module libexec/apache2/mod_rewrite.so
And remove the hash so it says,
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
If you are using Apache, double check no errors in Directory in VirtualHost, Apache wont warn you if you input an incorrect directory:
<Directory /var/www/html/site/wordpress>
Options FollowSymLinks
AllowOverride Limit Options FileInfo
DirectoryIndex index.php
Require all granted
</Directory>
<Directory /var/www/html/site/wordpress/wp-content>
Options FollowSymLinks
Require all granted
</Directory>

I need to be able to a) use virtual hosts in my home folder on Linux, and b) use symlinks

So I have Ubuntu 12.04 (Desktop) and want to setup a virtual host for a.localhost. I know how to setup the sites-enabled and /etc/hosts. What I haven't been able to figure out is how to direct the virtual hosts to /home/aubrey/a.project and link /home/aubrey/a.project/b to /home/aubrey/Project A/b and be able to access it all using http://a.localhost/b
Another Explanation:
Ironically, I did this just fine on Windowz and xampp. I just want to be able to keep plugin code in repositories in my home folder and a WordPress install in something like /home/aubrey/a-wordpress and have /home/plugin-project/plugin-a linked to /home/aubrey/a-wordpress/wp-content/plugins/plugin-a.
Does this problem apply to all files within the plugins directory? Specifically static files like CSS or JS? Or does this problem only occur with PHP files?
If it's only the PHP files, check your PHP configuration. Maybe you have an open_basedir configured there?
If I'm not mistaken, you want +SymLinksIfOwnerMatch, not -SymLinksIfOwnerMatch. The - says to disallow the directive as opposed to the + which turns the directive on. But it's definitely possible that something else is going to cause problems here.
Okay, this is what I did to get things working:
First, enabled userdir
sudo a2enmod userdir
Then, edited /etc/apache2/mods-enabled/php5.conf
<IfModule mod_php5.c>
<FilesMatch "\.ph(p3?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
# To re-enable php in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
<IfModule mod_userdir.c>
<Directory /home/*/public_html>
#php_admin_value engine Off
</Directory>
</IfModule>
</IfModule>
Notice I commented out the php_admin_value to allow PHP.
Then, created a virtual host:
<VirtualHost *:80>
ServerName philknight.localhost
DocumentRoot /home/aubrey/public_html/philknight-wordpress
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /home/aubrey/public_html/philknight-wordpress>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
And, in /home/aubrey/public_html/philknight-wordpress was able to create a link to wp-content elsewhere in my home folder, /home/aubrey/Documents/Projects & Companies/Excion/Metz Tennis/PhilKnight/wp-content/themes/philknight to be exact actually. I used the common SHIFT_CTRL drag method, but I'm sure ln -s would work too.
Hope this helps anyone, comment if you have questions...
Permissions:
drwxrwxrwx 4 www-data www-data 4096 Aug 20 18:46 /home/aubrey/public_html
drwxrwxrwx 8 aubrey aubrey 4096 Aug 20 21:11 /home/aubrey/Documents/Projects & Companies/Excion/Metz Tennis/PhilKnight/wp-content
Also had to chmod 777 -R /home/aubrey/Documents/Projects & Companies/Excion/Metz Tennis/PhilKnight/wp-content/plugins and /home/aubrey/Documents/Projects & Companies/Excion/Metz Tennis/PhilKnight/wp-content/themes

Resources