Run PHP/php-fpm as root

https://serverfault.com/questions/788669/start-php-fpm-with-root-option-automatically

For example, when running shell_exec and you need to execute commands as root (using a GPIO light on a raspberry pi requires running python with sudo).

  1. Edit the php configuration: /etc/php5/fpm/pool.d/www.conf
    1. change the user and group to root
  2. In the service definition: /lib/systemd/system/php5-fpm.service
    1. add the -R flag to the end of the ExecStart line (to run as root)
  3. Reload the configuration
    $ systemctl daemon-reload
  4. Restart php5-fpm and nginx services.
  5. test it by creating (and running) a php file with contents like this:
    1. <?php
      $output = shell_exec(‘sudo whoami’);
      echo “<pre>$output</pre>”;
      ?>

    2. after running in the browser, you’ll see the username root printed if it worked.
Advertisements

Git basics

1. create a repository

2. git clone <project repository url>

3. create files in newly created directory for the project

4. add new files (start tracking their changes) to repository by running git add (file name) or git add * to add everything

5. commit changes by running git commit -m “(write a comment here about what changes were made)”

6. run git push to push the new changes up to the repository. Enter the github username and password. if two factor auth is setup, create a personal access token and use that as the password: https://github.com/settings/tokens

Once you’ve done the first commit, any time changes are made, you will have to git add (filename) for any new files or files changed, and git rm any files deleted. Then git commit and git push.

Python load scripts from subdirectories

https://stackoverflow.com/questions/1260792/import-a-file-from-a-subdirectory

  • Create a subdirectory – for example, name it lib (this is where you place the scripts that you want to load from).
  • Create an empty file named lib\__init__.py.
  • In your client code (in the directory above lib), write from (folder name) import (script name). If the script in the lib\ directory is called BoxTime.py and the function in BoxTime is called foo, import and call the function like this:
    from lib import BoxTime
    BoxTime.foo()

Blog at WordPress.com.

Up ↑