# Apache2 directory permissions are messed up

## bigdave1

Hello all,

I've been working on starting up a web/email server and I accidentally messed up the directory permissions in /var/www/localhost/htdocs so when I try to access the webpage I get a 403 Forbidden error. Here are the directory permissions:

/var/www/localhost

```

mail localhost # ls -la

total 24

drwxr-xr-x  6 root   root 4096 May 23 02:12 .

drwxr-xr-x  4 apache root 4096 May 23 12:14 ..

drwxr-xr-x  2 root   root 4096 May 23 02:12 cgi-bin

drwxr-xr-x  3 root   root 4096 May 23 02:12 error

drwxr-xr-x 15 apache root 4096 May 26 04:43 htdocs

drwxr-xr-x  3 root   root 4096 May 23 02:12 icons

mail localhost # 

```

/var/www/localhost/htdocs

```

mail htdocs # ls -la

total 1504

drwxr-xr-x 15 apache root     4096 May 26 04:43 .

drwxr-xr-x  6 root   root     4096 May 23 02:12 ..

drwxr-xr-x  2 root   root     4096 May 23 21:29 ADDITIONS

-rwxr-xr-x  1 root   root    12943 May 23 02:42 CHANGELOG.TXT

drwxr-xr-x  3 root   root     4096 May 23 02:42 DOCUMENTS

-rwxr-xr-x  1 root   root    15148 May 23 02:42 GPL-LICENSE.TXT

-rwxr-xr-x  1 root   root     3981 May 23 02:42 INSTALL.TXT

-rwxr-xr-x  1 root   root     1569 May 23 02:42 LICENSE.TXT

drwxr-xr-x  2 root   root     4096 May 23 02:42 VIRTUAL_VACATION

drwxr-xr-x  2 root   root     4096 May 23 02:47 admin

-rwxr-xr-x  1 root   root     2326 May 23 02:12 apache_pb.gif

-rwxr-xr-x  1 root   root     1385 May 23 02:12 apache_pb.png

-rwxr-xr-x  1 root   root     2410 May 23 02:12 apache_pb22.gif

-rwxr-xr-x  1 root   root     1502 May 23 02:12 apache_pb22.png

-rwxr-xr-x  1 root   root     2205 May 23 02:12 apache_pb22_ani.gif

-rwxr-xr-x  1 root   root     3853 May 23 02:42 backup.php

-rwxr-xr-x  1 root   root     2816 May 23 02:42 broadcast-message.php

-rwxr-xr-x  1 root   root     2039 May 23 02:42 common.php

-rwxr-xr-x  1 root   root    12394 May 23 11:11 config.inc.php

-rwxr-xr-x  1 root   root     1913 May 23 02:42 create-admin.php

-rwxr-xr-x  1 root   root     4494 May 23 02:42 create-alias.php

-rwxr-xr-x  1 root   root     4113 May 23 02:42 create-domain.php

-rwxr-xr-x  1 root   root    10012 May 23 02:42 create-mailbox.php

drwxr-xr-x  2 root   root     4096 May 23 02:42 css

drwxr-xr-x  2 root   root     4096 May 23 02:42 debian

-rwxr-xr-x  1 root   root     4959 May 23 02:42 delete.php

-rwxr-xr-x  1 root   root     1460 May 23 02:42 edit-active-admin.php

-rwxr-xr-x  1 root   root     1421 May 23 02:42 edit-active-domain.php

-rwxr-xr-x  1 root   root     2864 May 23 02:42 edit-active.php

-rwxr-xr-x  1 root   root     4834 May 23 02:42 edit-admin.php

-rwxr-xr-x  1 root   root     3770 May 23 02:42 edit-alias.php

-rwxr-xr-x  1 root   root     3085 May 23 02:42 edit-domain.php

-rwxr-xr-x  1 root   root     4989 May 23 02:42 edit-mailbox.php

-rwxr-xr-x  1 root   root     6570 May 23 02:42 edit-vacation.php

-rwxr-xr-x  1 root   root     8345 May 23 02:42 fetchmail.php

-rwxr-xr-x  1 root   root    57074 May 23 02:42 functions.inc.php

-rwxr-xr-x  1 root   root     5587 May 26 04:31 glogo.jpg

drwxr-xr-x  2 root   root     4096 May 23 02:42 images

-rwxr-xr-x  1 root   root     1311 May 26 04:36 index.html

-rwxr-xr-x  1 root   root     3600 May 23 02:42 index.php

drwxr-xr-x  2 root   root     4096 May 23 02:42 languages

-rwxr-xr-x  1 root   root     1006 May 23 02:42 list-admin.php

-rwxr-xr-x  1 root   root     1920 May 23 02:42 list-domain.php

-rwxr-xr-x  1 root   root     5529 May 23 02:42 list-virtual.php

-rwxr-xr-x  1 root   root     3222 May 23 02:42 login.php

-rwxr-xr-x  1 root   root      658 May 23 02:42 logout.php

drwxr-xr-x 17 apache apache   4096 May 25 00:28 mail

-rwxr-xr-x  1 root   root      805 May 23 02:42 main.php

-rwxr-xr-x  1 root   root      264 May 23 02:42 motd-users.txt

-rwxr-xr-x  1 root   root      264 May 23 02:42 motd.txt

-rwxr-xr-x  1 root   root     2706 May 23 02:42 password.php

drwxr-xr-x 12 apache apache   4096 May 26 04:43 phpBB

-rwxr-xr-x  1 root   root       20 May 23 11:06 phpinfo.php

drwxr-xr-x  2 root   root     4096 May 24 01:58 phpmyadmin

-rwxr-xr-x  1 root   root   115975 Jun 25  2007 postfixadmin-2.1.0-arvin-martin.patch

-rwxr-xr-x  1 root   root   951421 May 23 02:41 postfixadmin_2.2.0.tar.gz

-rwxr-xr-x  1 root   root     4166 May 23 02:42 search.php

-rwxr-xr-x  1 root   root     2037 May 23 02:42 sendmail.php

-rwxr-xr-x  1 root   root     9986 May 23 02:42 setup.php

drwxr-xr-x  2 root   root     4096 May 23 02:42 templates

-rwxr-xr-x  1 root   root     9468 May 26 04:27 under_construction.gif

-rwxr-xr-x  1 root   root    36875 May 23 02:42 upgrade.php

drwxr-xr-x  2 root   root     4096 May 23 02:42 users

-rwxr-xr-x  1 root   root     2353 May 23 02:42 variables.inc.php

-rwxr-xr-x  1 root   root     2214 May 23 02:42 viewlog.php

mail htdocs # 

```

/var/www/localhost/htdocs/mail (directory Squirrelmail uses)

```

mail mail # ls -la

total 264

drwxr-xr-x 17 apache apache   4096 May 25 00:28 .

drwxr-xr-x 15 apache root     4096 May 26 04:43 ..

-rw-------  1 root   root      324 May 25 00:25 .webapp

-rw-------  1 root   root   142892 May 25 00:25 .webapp-squirrelmail-1.4.13-r1

-rw-r--r--  4 root   root    15129 May 23 12:12 COPYING.locales

-rw-r--r--  4 root   root     9066 May 23 12:12 ChangeLog.locales

-rw-r--r--  4 root   root     2122 May 23 12:12 ReleaseNotes.locales

drwxr-xr-x  2 apache apache   4096 May 25 00:28 attach

drwxr-xr-x  5 root   root     4096 May 25 00:25 class

drwxr-xr-x  2 root   root     4096 May 25 00:25 config

-rwxr-xr-x  4 root   root      102 May 23 12:12 configure

drwxr-xr-x  3 root   root     4096 May 25 00:25 contrib

drwxr-xr-x  2 apache apache   4096 May 25 00:36 data

drwxr-xr-x  3 root   root     4096 May 25 00:25 doc

drwxr-xr-x  4 root   root     4096 May 25 00:25 functions

drwxr-xr-x 29 root   root     4096 May 25 00:25 help

drwxr-xr-x  2 root   root     4096 May 25 00:25 images

drwxr-xr-x  3 root   root     4096 May 25 00:25 include

-rw-rw-r--  1 apache apache    672 May 25 00:25 index.php

-rwxr-xr-x  4 root   root      221 May 23 12:12 install

drwxr-xr-x 47 root   root     4096 May 25 00:25 locale

drwxr-xr-x 25 root   root     4096 May 25 00:25 plugins

drwxr-xr-x  2 root   root     4096 May 25 00:25 po

drwxr-xr-x  2 root   root     4096 May 25 00:25 src

drwxr-xr-x  3 root   root     4096 May 25 00:25 themes

-rw-r--r--  4 root   root       21 May 23 12:12 version

mail mail # 

```

Anybody have any good ideas on how I should reset the permissions? Or to what they should be set?

Thanks!

----------

## FlorianSchmidt

First you should find out, what user/group your apache uses. You can look this up in /etc/apache2/apache2.conf (if apache is installed via ebuild).

after that you should run

```
chown -R [user]:[group] /var/www/localhost/htdocs
```

to reset all the permissions you could do the following.

But I must warn you that I do not know what kind of software you have installed inside of htdocs and what permissions are needed. In general, you should get some error messages that tell you where you need to tweak your permissions afterwards.

As root, of course  :Smile: 

```

chmod -R 000 /var/www/localhost/htdocs

chmod -R ug+rX /var/www/localhost/htdocs

```

From what I know about squirrelmail, you'll then need to run:

```

chmod ug+x /var/www/localhost/htdocs/mail/configure

chmod -R ug+w /var/www/localhost/htdocs/data

```

Phpmyadmin should run without additional permissions.

The rest is up to you   :Wink: 

regards

Florian Schmidt

----------

## bigdave1

Well, it turned out that the problem was with phpBB which was installed as well. As soon as I unemerged phpBB and restarted Apache2 everything started working fine.

So now thats fixed, anybody know of a good how-to for installing phpBB? I did a search on Gentoo-Wiki for phpBB but there are no entries. The documentation on the phpBB website isn't that great because it assumes you have it installed and can point the browser to the configuration page. Also, will phpBB and Squirrelmail work together if running on the same server? Here's my setup:

Web Server - Apache

E-mail - Postfix/Courier-imap

SQL Database - PostgreSQL

Webmail - Squirrelmail

I would very much like to have phpBB installed as well. Any suggestions?

----------

## FlorianSchmidt

I just did

```

emerge apache php phpBB

```

and my permissions look like this

```

localhost ~ # ls -l /var/www/localhost/htdocs/phpBB/

total 388

drwxr-xr-x  4 root   root    4096 May 27 10:36 adm

drwxr-xr-x  2 apache apache  4096 May 27 10:39 cache

-rw-r--r--  2 root   root    6207 May 27 10:36 common.php

-rw-rw-r--  1 root   apache     0 May 27 10:36 config.php

-rw-r--r--  2 root   root    6004 May 27 10:36 cron.php

drwxr-xr-x  2 root   root    4096 May 27 10:36 download

-rw-r--r--  2 root   root    1485 May 27 10:36 faq.php

drwxr-xr-x  2 apache apache  4096 May 27 10:36 files

drwxr-xr-x  7 root   root    4096 May 27 10:36 images

drwxr-xr-x 13 root   root    4096 May 27 10:36 includes

-rw-r--r--  2 root   root    4700 May 27 10:36 index.php

drwxr-xr-x  5 root   root    4096 May 27 10:36 install

drwxr-xr-x  3 root   root    4096 May 27 10:36 language

-rw-r--r--  2 root   root   21579 May 27 10:36 mcp.php

-rw-r--r--  2 root   root   56616 May 27 10:36 memberlist.php

-rw-r--r--  2 root   root   54849 May 27 10:36 posting.php

-rw-r--r--  2 root   root    4282 May 27 10:36 report.php

-rw-r--r--  2 root   root   39590 May 27 10:36 search.php

drwxr-xr-x  2 apache apache  4096 May 27 10:36 store

-rw-r--r--  2 root   root    8002 May 27 10:36 style.php

drwxr-xr-x  4 root   root    4096 May 27 10:36 styles

-rw-r--r--  2 root   root    9318 May 27 10:36 ucp.php

-rw-r--r--  2 root   root   27545 May 27 10:36 viewforum.php

-rw-r--r--  2 root   root   13897 May 27 10:36 viewonline.php

-rw-r--r--  2 root   root   60389 May 27 10:36 viewtopic.php

```

if I tell the webbrowser to give me http://localhost/phpBB/ everything works fine.

----------

## bigdave1

Which database software are you using for phpBB? I already have PostgreSQL installed which I use with Postfix for my e-mail server. I want to have my e-mail and web server running on the same box. Can I add on to my existing database and use it for phpBB?

----------

## FlorianSchmidt

I am not using phpBB, I just emerged it to show you the permissions.

As phpBB supports PosgreSQL (http://www.phpbb.com/about/features/#data-management) there should be no problem to use your exisitng database system.

If this is an Internet Mailserver, be so kind and run an relay test (http://www.abuse.net/relay.html) on it, just enter your hostname and hit "test for relay"

----------

## bigdave1

If I can use my existing database with phpBB, how do I incorporate it into my existing database? 

Also, when I go to install phpBB thru http://localhost/phpBB/install/index.php, it tells me that my database was not created in UNICODE or UTF8 and that I should trying installing with a database in UNICODE or UTF8 encoding. How do I get past this without messing up the database that Postfix uses?

----------

## AllenJB

I don't know about the other packages, but there's a known issue with PostfixAdmin 2.1.0-r1 - You can fix this by using 2.1.0 (there's no code differences between the two - just a minor dependency setup change that as far as I can tell won't affect most users)

----------

