Sunday, December 30, 2018

Apache 2.4 /PHP7.3 /PHP-FPM /freeBSD 12 (part 1)

Install Apache 2.4:
# cd /usr/ports/www/apache24/ && make install clean BATCH=yes
Just append BATCH=yes at the end of the command and they will go straight away as they are without asking anymore.

httpd.conf:
# cp /usr/local/etc/apache24/httpd.conf /usr/local/etc/apache24/httpd.conf.original
# ee /usr/local/etc/apache24/httpd.conf

Virtual host configuration:
# Ensure that Apache listens on port 80
Listen 80
<VirtualHost *:80>
    ServerName 13.211.209.48
    ServerAlias example
    DocumentRoot "/usr/local/www/apache24/life110volts.com"
    DirectoryIndex index.php index.html

    <Directory /usr/local/www/apache24/life110volts.com>
        Options -Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
    </Directory>

    <FilesMatch \.php$>
         SetHandler "proxy:unix:/var/run/php5-fpm.sock|fcgi://localhost/"
    </FilesMatch>

    ErrorLog /var/log/life110volts.com-error.log

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

    CustomLog /var/log/life110volts.com-access.log combined

</VirtualHost>

VirtualHost Examples: https://httpd.apache.org/docs/2.4/vhosts/examples.html


Website:
# mkdir /usr/local/www/apache24/life110volts.com
# ls -l /usr/local/www/apache24/life110volts.com
# chown -R www:www /usr/local/www/apache24/life110volts.com
# chown -R 755 /usr/local/www/apache24/life110volts.com
# ee /usr/local/www/apache24/life110volts.com/index.html
# ee /usr/local/www/apache24/life110volts.com/index.php
# ee /usr/local/www/apache24/life110volts.com/info.php

Start/Stop:
# sysrc apache24_enable=yes
# apachectl configtest
# service apache24 onestart
# service apache24 restart && service nginx reload

Curl the web page on Localhost.
# cd /usr/ports/ftp/curl && make install clean
# curl -i 127.0.0.1:8080/info.php
# curl -i 127.0.0.1:8080

Install PHP 7.3
To get a list of all available PHP version packages provided by FreeBSD Ports repositories
# ls /usr/ports/lang/ | grep php
# whereis mod_php73
# cd /usr/ports/lang/php73 && make install clean
(choose the php-FPM box)
(# make config)
# rehash
# php -v
# cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini

Install PHP-FPM
FastCGI Process Manager - alternative FastCGI implementation
In addition to Apache and PHP-FPM, we will also install the PHP FastCGI Apache module, libapache2-mod-fastcgi, to support FastCGI web applications. In order to get the ability of handling the FastCGI protocol, mod_proxy and mod_proxy_fcgi have to be present in the server.
#LoadModule proxy_module libexec/apache24/mod_proxy.so
#LoadModule proxy_fcgi_module libexec/apache24/mod_proxy_fcgi.so

Normally PHP-FPM configuration files are located on /usr/local/etc/php-fpm.conf file and /usr/local/etc/php-fpm.d path. This is normally excellent start and all pool configs goes to /usr/local/etc/php-fpm.d directory. You need to add following include line on your php-fpm.conf file:
include=/etc/php-fpm.d/*.conf

Configure PHP-FPM
# ee /usr/local/etc/php-fpm.d/www.conf
listen = 127.0.0.1:9000 //
listen = /var/run/php-fpm.sock
listen = /var/run/php72-fpm.sock //
listen.owner = www
listen.group = www
listen.mode = 0660

# sysrc php_fpm_enable=YES

Start/Stop:
# service php-fpm stop
# service php-fpm start
# service php-fpm restart
# service php-fpm status

Nginx:Installing 
# cd /usr/ports/www/nginx && make config-recursive
- Accept the defaults.
# make install clean

Edit Nginx.conf
# nano /usr/local/etc/nginx/nginx.conf

# sysrc nginx_enable="YES"
# sudo nginx -t
# sudo service nginx reload

Location of importants files:
Nginx:
# ee /usr/local/etc/nginx/nginx.conf
Document Dir:
# ls /usr/local/www/
Modules dir:
Logs:
/var/log/nginx/example.com.access.log;

Apache:
# ee /usr/local/etc/apache24/httpd.conf
Web dir or DocumentRoot/ Directory:
# ls -l /usr/local/www/apache24/data
Modules.d directory:
# ee /usr/local/etc/apache24/modules.d/030_php-fpm.conf
Logs:
tail -f /var/log/httpd-access.log
tail -f /var/log/httpd-error.log
Includes:
# ee /usr/local/etc/apache24/Includes/php.conf

PHP:
# ee /usr/local/etc/php-fpm.d/www.conf
# ee /usr/local/etc/php-fpm.conf
# ee /usr/local/etc/php.ini

freeBSD:
# ee /etc/rc.conf

Courtesy:
1. How to install NGINX in CentOS 7 or FreeBSD and configure it to act as a Reverse Caching Proxy for Apache

No comments:

Post a Comment