Nikita Cunskis
Nikita Cunskis

Reputation: 31

give access to file outside www/html folder

I have LAMP server

Server version: Apache/2.4.29 (Ubuntu)

PHP: PHP 7.2.5-0ubuntu0.18.04.1

I need to give an php SQLITE3 access to db outside www/html folder. Right now my filesystem looks this way.

/root
    ./database
        user.db
/var
    ./www
        ./html
            index.html
            reg.php

user.db must be located in /root/database, so just putting it inside var/www/html isn't solution for me.

So I need to give access to this folder for Apache or php. I found some information here https://httpd.apache.org/docs/2.4/urlmapping.html, but didn't get how this works and where I need to put this?

Upvotes: 1

Views: 4005

Answers (1)

drmad
drmad

Reputation: 620

The problem here is Linux permissions, not URL mapping, as PHP is running in the server, in the backend.

If you run PHP as an Apache module, (mod_php or something like that), it will run with the Apache user and group (usually www-data:www-data or nobody:nogroup, it depends of the LAMP configuration).

So, you should give permissions and change ownership to the user.db file and its tree, something like:

chmod o+x /root
chmod o+x /root/database
chown www-data:www-data /root/database/user.db 

You can read more about permissions here.

Upvotes: 1

Related Questions