What userid will my PHP and CGI scripts run under? Text Tutorial Print

  • 28

The user ID (UID) under which your PHP and CGI scripts run depends on your web hosting environment and how the server is configured.

Here’s how it usually works:

 

 Shared Hosting (like 4GoodHosting)

On shared hosting environments like 4GoodHosting, your scripts generally run under:

🔹 Your Own User Account

  • Both PHP and CGI scripts typically run as your hosting account’s user, not as the global nobody or apache user.

  • This is achieved through server modules like:

    • suPHP (for PHP)

    • CGIwrap or suEXEC (for CGI scripts)

This setup ensures:

  • Improved security – Scripts can’t interfere with other users.

  • File ownership consistency – Uploaded files are owned by your user account.

 

🔹 How to Check the Running User

You can create and run a small test script to find out.

For PHP:

Create a file named whoami.php:

php
<?php echo 'Current user: ' . get_current_user(); ?>

For CGI (Perl example):

Create a file whoami.cgi:

perl
#!/usr/bin/perl print "Content-type: text/plain\n\n"; print "Current user: " . getpwuid($<) . "\n";

Make sure it’s in your cgi-bin, and has 755 permissions.

 

🛑 In Some Other Environments:

  • If mod_php is used (less common now), scripts may run as nobody or apache.

  • On dedicated/VPS servers, you have more control and can configure this.

 

✅ Summary:

Script Type User ID (Shared Hosting) Notes
PHP Your hosting username via suPHP or PHP-FPM
CGI Your hosting username via suEXEC or CGIwrap

If you’re using 4GoodHosting and need confirmation for your specific plan, I can guide you how to check or interpret cPanel server settings.


Was this answer helpful?

« Back