0

I want to secure my php ini access right.

We know that apache/httpd master process, is owned by root. Then it spawn new child process in www-data user.

If /etc/php.ini loaded by apache as root user, I want to limit read access of php.ini to root only.

So, Which apache/httpd (root or www-data) user, who load /etc/php.ini when webserver startup?

1
  • Couldn't you just change the permissions, restart httpd and see wether it still works or not? I do not think limiting access to php.ini is a good idea at all, but your use-case might be different. May 1, 2019 at 2:43

1 Answer 1

1

This permission change can be answered by snips from this answer

You can determine which user is running PHP by running a simple script that calls the 'whoami' program installed in most Linux:

<?php
echo `whoami`;

This gives you which user the files should have access to. Make sure that the user the PHP process is running under is the owner of php.ini and the *.php files. You can change the owner by using this command(replace theuser as per the whoami output):

% chown theuser:theuser -R /var/www/website/

If you do not have multiple users then permission 600 is fine.

% chmod 600  /etc/php.ini

And to verify the access use su - otheruser from root and try accessing the files.

2
  • Why would you need execute permission on an ini file ?
    – user9517
    May 1, 2019 at 7:02
  • I checked and we don't need execute permissions. So 600 would suffice.
    – Dextro67
    May 1, 2019 at 8:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .