ANS Documentation

Improve This Doc
  • Cloud
  • Domains and DNS management
  • Backup and High Availability
  • eCommerce Stacks
  • Security
  • Email
  • Monitoring and usage management
  • Networking
  • Operating systems
    • Linux
      • Basics
      • Apache
      • Control Panels
      • FTP
      • Magento
      • Miscellaneous
      • MySQL
      • NGINX
      • PHP
      • PHP-FPM
      • Setting up Websites
      • NFS
      • VPN
      • Percona
      • SSH
      • SSL
      • Git
      • Redis
      • Elasticsearch
      • MongoDB
      • Ncdu
    • VMware ESXi
    • Windows
  • Webcelerator
  • MyUKFast
  • Home >
  • Operating systems >
  • Linux >
  • Apache >
  • Apache with PHP-FPM

Apache with PHP-FPM¶

By default Apache will run PHP as mod_php. This means that it will load the PHP libraries for every Apache process even when Apache is serving a static files such as an image or text. This can cause bloating of the Apache memory usage on your server. Another issue with running PHP as mod_php is that the Apache users needs to be able to read the files in your document root and any files it writes will be created with Apache as the owner. This may be fine if you only have one or two sites on your server but may become an issue with more sites which may require other 3rd parties to access those files.

Apache version 2.4+ allows you to hand off PHP processing to PHP-FPM which runs as a separate process. You can check your Apache version with this command.

httpd -V

This shows your version.

Server version: Apache/2.4.6 (CentOS)

You will then need to add this section to your Apache configuration to pass .php files over to your PHP-FPM socket.

<FilesMatch "\.php$">
    SetHandler "proxy:unix:/var/run/php-fcgi-firstdomaincom.sock|fcgi://127.0.0.1"
</FilesMatch>
ProxyTimeout 600

Note the ProxyTimeout setting here. When Apache passes content to PHP-FPM for processing, it sees PHP-FPM as a proxy. If you have a long running PHP script, Apache may time out before it completes. On the other hand, you want to protect your server from running a PHP script indefinitely.

The /var/run/php-fcgi-domaincom.sock section needs to be the socket configured in your PHP-FPM configuration file.

Fully featured examples of this and other Apache functionality can be found on the following page:

Sample Vhosts

Next Article > Control Panels

  • Useful Links
  • SMB
  • Enterprise
  • Channel
  • Public Sector
  • ANS Data Centres
  • About ANS
  • Careers
  • Blog
  • Get in touch
  •  
  • Sales 0800 458 4545
  • Support 0800 230 0032
  • Get in touch

© ANS Group Limited | Terms and Conditions | Corporate Guidance | Sitemap
ANS Group Limited, registered in England and Wales, company registration number 03176761, registered office 1 Archway, Birley Fields, Manchester M15 5QJ