O
O
Oleg Dyachenko2014-12-06 23:41:54
Apache HTTP Server
Oleg Dyachenko, 2014-12-06 23:41:54

How to run PHP script as root?

Good winter to you!
I'll start right away. I have Os X Yosemite. Enabled built-in Apache and unblocked built-in PHP.
When executing scripts that work with files on the computer, an access error pops up. It is successfully treated if in the folder with which I work, I specify the rights to read and write (if the second is required).
I run the script from the latest version of the Mozilla browser (although the same is true in Safari).
Empirically, it was noticed that the script is launched on behalf of Any Users. (actually, I reassign their rights)
Hence the crux of the matter. How can I run a php script on behalf of me, the user of this system, who has read and write permissions by default, so that I do not have to manually constantly change the access rights of Any Users on whose behalf the script is run?
And why does it run on behalf of Any Users, because I manually launch it in the system through the browser? (for sure, this is due to the security policy, but I have not yet penetrated all the nuances, if not difficult, tell us briefly)
At the moment there is a solution, just manually set the access rights in the folders I need, but this is not true, because there is a user in the system , I, under which I freely change all files. It seems logical to me to make all changes under it.
Thank you in advance for your answers and warm sunshine to you.
UPD - a disclosed solution for the uninitiated
It was difficult for me to apply everything that was described below, since apparently I'm still quite a noob.
Both solutions were correct, I chose to run the Apache server on behalf of the user.
To do this, in the php configuration, I looked under what username my Apache server is running (create a php file with the phpinfo () function and open it in the browser, in the Configuration table, look for the User / column Group, it contains the username, in my case it was _www)
Next, go to the /etc/apache2/httpd.conf file and look for your username there. For me it was line 181 User _www
line 182 Group _www Changed
the value of _www to my username, saved and reloaded Apache.
That's it, now it works with read/write permissions
ATTENTION 1 - write the username without extra characters, as it is, my first mistake was to write _username. Of course the server didn't even start. Removing the underline, everything worked out.
ATTENTION 2 - be aware of what you are doing. The fact is that they wrote it correctly below, these rights, in my case, the administrator, give you the ability to write and read almost all files on the computer, and if you are hacked, the attacker will have almost complete access to the computer. I have a local server and I need it, plus when I'm done I turn off Apache. However, the security of Unix systems is primarily guaranteed by the rigid distinction between what is allowed and what is not. Do not break this rule again.
Thank you for your attention

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nazar Mokrinsky, 2014-12-07
@OLDJman

The browser has nothing to do with the server, the request is accepted by Apache. Look in the Apache config (presumably the envvars file) for the APACHE_RUN_USER and APACHE_RUN_GROUP parameters.
I categorically do not recommend specifying root there, since the downloaded WP theme with a virus will be able to format your system or something more interesting.
You copy files on behalf of your user - that is, the rights initially cost your user. Actually, you can put your user in the config, but again, the script will have access to your home folder and the files you created, so you still need to think what to run.

V
Vlad Zhivotnev, 2014-12-07
@inkvizitor68sl

Regardless of the fact that this is a VERY STUPID idea - you can install apache2-mpm-itk, and write root root in the AssignUserID entry.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question