title: Where to store private key for encryption in PHP environment
body: <p>In my database I store information which is encrypted and decrypted on the fly via a PHP-class. </p>
  
  <p>Per application I use a private key appended with a user key to make sure the decryption only succeeds when a user tries to decrypt its own data. </p>
  
  <p>The user 'key' is stored in the database; but the private key (application level) is stored as txt-file in the FS. Off course 'above' the web-root.</p>
  
  <p>Considerations: 
  - If the database gets hacked: they end up with one part of the key, and encrypted data
  - If PHP-stops or is corrupt: they end up with a single page with only <code>include('../private/private.php')</code> in it.<br>
  - If NGINX fails: the connection is 'just' dropped.</p>
  
  <p>The only scenario I can think of is the corruption of the system itself. But the server runs a firewall, is updated regularly, runs fail2ban and only the services needed are run. SSH logins only via key-access etc etc</p>
  
  <p>I was wondering if this is the 'best' practice. 
  Or if there is a better way to do this kind of encryption with above specifications?
  What would be the correct access-rights to the key-file?</p>
  
  <p>At the moment the database and webserver are both on the same server facing the internet. Is it better to split them and create an internet facing server with only the webserver; and put the database server and key-file on a different server in a private network?</p>
  
  <p>edit: the private key to encrypt the data is build up by two components:<br>
  <code>$key = $app_key . $user_key</code></p>