Skip to content

Instantly share code, notes, and snippets.

@efarem
Created May 24, 2016 15:09
Show Gist options
  • Save efarem/4a8fc03dc69d81998f6e518620f63421 to your computer and use it in GitHub Desktop.
Save efarem/4a8fc03dc69d81998f6e518620f63421 to your computer and use it in GitHub Desktop.
Convert Apache to PHP-FPM
#!/bin/bash
# Install dependencies
sudo apt-get install -y apache2-mpm-worker
sudo apt-get install -y libapache2-mod-fastcgi php5-fpm
# Disable prefork & Enable fcgi
sudo a2dismod php5 mpm_prefork
sudo a2enmod actions fastcgi alias mpm_worker
# Create fcgi file
sudo touch /usr/lib/cgi-bin/php5.fcgi
# Change permissions
sudo chown -R www-data:www-data /usr/lib/cgi-bin
# Add configuration file
cat > /etc/apache2/conf-available/php5-fpm.conf << EOL
<IfModule mod_fastcgi.c>
AddHandler php5.fcgi .php
Action php5.fcgi /php5.fcgi
Alias /php5.fcgi /usr/lib/cgi-bin/php5.fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php5.fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization -idle-timeout 3600
<Directory /usr/lib/cgi-bin>
Require all granted
</Directory>
</IfModule>
EOL
# Enable PHP-FPM conf
sudo a2enconf php5-fpm
# Restart services
sudo service apache2 restart && sudo service php5-fpm restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment