Waslap
Waslap

Reputation: 571

PHP not served when not in document root

My apache 2.4.43 on F31 is not serving PHP from anywhere but the document root (which is default /var/www/html). I have directives in /etc/http/conf.d which does get included as apache fails to start if i make a syntax error in there. So if i have

Alias "/mine/" "/home/pete/mine/"

<Directory "/home/pete/mine/">
    Options MultiViews FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

and i have a file abc.php in /home/pete/mine then i get 404 when i try the URL http://localhost/mine/abc.php

BTW i do have apache added to an appropriate group so discretionary access control wouldn't hamper the matter.

I've straced apache and it seems it is expecting /home/pete/mine/abc.php to be a directory as it is looking for an .htaccess in there which makes me think it is ignoring .php extension here. When i place abc.php in /var/www/html then i can access it by http://localhost/abc.php fine. The same setup works on CentOS7 so this must be some Fedora31 apache version related problem or sysctl setting of some sort.

This is the strace:

    [root@localhost conf.d]# strace -f httpd -X 2>&1 | grep mine
    [pid 25020] read(14, "GET /mine/abc.php HTTP/1."..., 8000) = 398
    [pid 25020] stat("/home/pete/mine/abc.php", {st_mode=S_IFREG|0644, st_size=15914, ...}) = 0
    [pid 25020] openat(AT_FDCWD, "/home/pete/mine/abc.php/.htaccess", O_RDONLY|O_CLOEXEC) = -1 ENOTDIR (Not a directory)
    ^C
    [root@localhost conf.d]# stat /home/pete/mine/abc.php
      File: /home/pete/mine/abc.php
      Size: 15914           Blocks: 32         IO Block: 4096   regular file
    Device: fd02h/64770d    Inode: 23462670    Links: 1
    Access: (0644/-rw-r--r--)  Uid: ( 1605/   pete)   Gid: ( 1501/  pete)
    Access: 2020-05-25 15:27:12.996084665 +0000
    Modify: 2020-05-25 17:03:51.577115385 +0000
    Change: 2020-05-25 17:03:51.577115385 +0000
     Birth: 2020-05-25 12:00:02.317331989 +0000

The stat clearly shows it to be a regular file so why apache decides to treat it as a directory is beyond me.

I am also noticing AH01071: Got error 'Primary script unknown' in the logs

Upvotes: 0

Views: 71

Answers (1)

Lelio Faieta
Lelio Faieta

Reputation: 6689

You are using a wrong specification for the alias.

It should be

Alias "/mine" "/home/pete/mine"
<Directory "/home/pete/mine">
    Options MultiViews FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

see the Apache documentation for more details

Without the last / apache will look in that mine directory for a file based on the DirectoryIndex definition (your base file can be anything you define there)

Upvotes: 1

Related Questions