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

Posted on

Which apache/httpd (root or www-data) user, who load /etc/php.ini when webserver startup? – A server stack is the collection of software that forms the operational infrastructure on a given machine. In a computing context, a stack is an ordered pile. A server stack is one type of solution stack — an ordered selection of software that makes it possible to complete a particular task. Like in this post about Which apache/httpd (root or www-data) user, who load /etc/php.ini when webserver startup? was one problem in server stack that need for a solution. Below are some tips in manage your linux server when you find problem about linux, php, security, httpd, php.ini.

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?

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.

Leave a Reply

Your email address will not be published. Required fields are marked *