If you like DNray Forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...

 

Running PHP as user

Started by Mazaykina, Jul 07, 2022, 02:28 AM

Previous topic - Next topic

MazaykinaTopic starter

Hi, please provide alternative recommendations for executing php under Apache as a user, aside from using php as CGI.
  •  


argoway

SUPHP is a method of initiating PHP as an independent user. Similar to the Apache suexec extension, SUPHP also enables running PHP as a specific user or group that owns a particular website in shared hosting environments.

In my view, mod_suphp is a fusion of mod_php and php_cgi, however, it offers advantages over php_cgi such as the processing of Htaccess directives and the avoidance of creating child threads during script processing. Nonetheless, it also has drawbacks. If there is even a minor error in the script, it will result in a 500 error, whereas if the script functions properly in mod_php mode, it may not work in suphp due to the differences in the method of processing.
  •  

RZA2008

There are various options for calling a PHP script, including running it independently through SSH using a utility or accessing it directly through a web browser. Another way is by setting a schedule with Cron.

I would recommend seeking the support of your web hosting provider for the first run of the script. This will involve specifying a particular script, which will allow hosting specialists to have a better understanding of the task and provide more precise guidance.
  •  

Ingrid

One method is mod_php, which is an Apache module that executes PHP scripts directly within the server. It's highly efficient and allows for better performance since PHP runs as part of the Apache server process. Just make sure your server has this module enable. You can usually do this via your package manager or compiling Apache from source with mod_php included.

Another option is FastCGI, which is a protocol designed to interface programs with a web server. By using mod_fastcgi or mod_fcgid with Apache, you can run multiple instances of PHP that handle requests parallely. This approach can improve performance, especially under high loads, as it reduces the resource consumption associated with spawning new processes repeatedly.

You can also use PHP-FPM (FastCGI Process Manager), which is particularly well-suited for heavy loads. PHP-FPM can manage pools of PHP processes independently, allowing Apache to pass requests to it efficiently. To set this up, you'll need to install PHP-FPM and configure Apache to use it via a reverse proxy. This method retains the performance benefits of FastCGI while also offering additional features such as adaptive process spawning and adaptive timeout mechanisms.

Moreover, consider using a containerization tool like Docker. By deploying PHP in a container, you can isolate your application environments, making deployments smooth and predictable. Combining Docker with Apache allows you to manage your PHP application's dependencies easily and ensures that it's always running in the same environment, reducing "works on my machine" scenarios.

For local development, tools like XAMPP or MAMP allow you to run Apache and PHP on your local machine without much hassle. They come with everything you need to get started quickly, including MySQL and phpMyAdmin, making them perfect for testing and debugging.

You can also think about serverless architectures, which might appear unconventional for PHP, but platforms like AWS Lambda now support PHP, enabling you to run your code without managing servers. While this approach requires some restructuring of your applications, it could save you overhead and provide scalability.
  •  


If you like DNray forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...