How do we determine which user the php script is running under when I run the script on server? Is it running under the same user as apache or phpmyadmin by chance? My question maybe wrongly framed but I want to know which user so that I set appropriate permission for different folders in /var
The user that runs apache/php is www-data . Run sudo chown -R www-data:www-data /var/www/deploy. log to make the file editable by the web server. The other files you want to perform operations on also need to be writable by the webserver.
In PHP this can be retrieved using getmypid() which will return an integer number. This pid number can be saved to a file and each time the script is run a check made to see if the file exists. If it is the posix_kill() function can be used to see if a process is running with that pid number.
PHP is a server-side programming language, meaning it is executed at the web server before the website is sent to the end-user. This is why you can't see the PHP code when you view the source code.
The PHP manual says that exec('whoami') returns "the username that owns the running php/httpd process" Link.
Execute whoami
:
<?php echo exec('whoami'); ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With