Skip to content

Instantly share code, notes, and snippets.

@faboo03
Last active October 10, 2016 13:02
Show Gist options
  • Save faboo03/e038e4009ed3944b8efa509cd77f5baf to your computer and use it in GitHub Desktop.
Save faboo03/e038e4009ed3944b8efa509cd77f5baf to your computer and use it in GitHub Desktop.
Install Apache With PHP-FPM

According to : https://serversforhackers.com/video/apache-and-php-fpm

Install Repositories:

sudo apt-get update
sudo apt-get install -y vim tmux curl wget unzip software-properties-common

sudo add-apt-repository -y ppa:ondrej/apache2
sudo add-apt-repository -y ppa:ondrej/php5-5.6
sudo apt-get update

sudo apt-cache show apache2
sudo apt-cache show php5-fpm

Install Apache:

sudo apt-get install -y apache2

cd /etc/apache2/mods-enabled
ll | grep mpm
# mpm_event is used!

Install PHP-FPM:

sudo apt-get install -y php5-fpm \
     php5-mcrypt php5-mysql php5-gd php5-curl

php -v

sudo service php5-fpm status

Edit www.conf to lsiten on network listen = 127.0.0.1:9000:

sudo service php5-fpm restart

Configure Apache:

# See what's available
ll /etc/apache2/mods-available | grep proxy

# Enable proxy modules
sudo a2enmod proxy proxy_fcgi

sudo service apache2 restart
Virtualhost:

sudo vim /etc/apache2/sites-available/example.conf

Vhost:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    ServerAlias example.*.xip.io

    DocumentRoot /var/www/example.com/public

    <Directory /var/www/example.com/public>
        Options -Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
    </Directory>

    <FilesMatch \.php$>
        # 2.4.10+ can proxy to unix socket
        # SetHandler "proxy:unix:/var/run/php5-fpm.sock|fcgi://localhost/"

        # Else we can just use a tcp socket:
        SetHandler "proxy:fcgi://127.0.0.1:9000"
    </FilesMatch>

    ErrorLog ${APACHE_LOG_DIR}/example.com-error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined

</VirtualHost>

Modules and Reloading Apache

sudo a2dissite 000-default
sudo a2ensite example
sudo service apache2 reload

sudo a2enmod rewrite
sudo vim /var/www/example.com/public/.htaccess

Add the below, then:

sudo service apache2 restart
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L].htaccess
sudo service apache2 restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment