Thursday, September 24, 2015

Install Apache 2.4, PHP 5.6, and MySQL 5.6 on FreeBSD 10

# pkg info | egrep -i 'apache|php|mysql'

apache24-2.4.10_2
php56-5.6.3
mysql56-server-5.6.22

Quick Notes:

  • To have Apache talks to PHP-FPM, you no longer need to install mod_fastcgi or mod_fcgid because it's built-in since Apache 2.4. The official module to use is mod_proxy_fcgi instead of the ancient mod_fastcgi and mod_fcgid (were third party modules).
  • Since Apache 2.4.9, the built-in mod_proxy_fcgi module now supports network sockets (Unix socket support for mod_proxy_fcgi).
  • Since PHP 5.5, you no longer need to install APC (Alternative PHP Cache) because Zend Optimizer+ is directly built in.
  • PHP 5.6 is shipped with the phpdbg interactive debugger.
  • Since MySQL 5.6.8, it won't ship those MySQL configuration tempalte files because this release continues the process begun in MySQL 5.6.6 of making changes to the default values of server parameters. The motivation for these changes is to provide better out-of-box performance and to reduce the need for database administrators to change settings manually. These changes are subject to revision in future releases as we gain feedback.
  • PHP Fights HHVM and Zephir with PHPNG

# pw useradd -n git -s /bin/tcsh -w yes -c "a description" -m

# vim /usr/local/etc/php-fpm.conf

listen = 127.0.0.1:9000
;listen = /tmp/php-fpm.sock

listen.owner = www
listen.group = www
listen.mode = 0660

# vim /usr/local/etc/apache24/httpd.conf

LoadModule proxy_module libexec/apache24/mod_proxy.so
LoadModule proxy_fcgi_module libexec/apache24/mod_proxy_fcgi.so

LoadModule mpm_event_module libexec/apache24/mod_mpm_event.so
#LoadModule mpm_prefork_module libexec/apache24/mod_mpm_prefork.so

LoadModule rewrite_module libexec/apache24/mod_rewrite.so

LoadModule ssl_module libexec/apache24/mod_ssl.so

ServerName bsd-dev.local:80

DocumentRoot "/home/srv/apache2.4"

<Directory "/home/srv/apache2.4">
  AllowOverride All
</Directory>

Include etc/apache24/extra/httpd-ssl.conf
Include etc/apache24/extra/httpd-vhosts.conf

# vim /usr/local/etc/apache24/extra/httpd-vhosts.conf

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/home/srv/apache2.4/drupal8"
    ServerName drupal8.bsd-dev.local
    #ServerAlias www.dummy-host.example.com
    ProxyPassMatch ^/(.*\.php(/.*)?)$ unix:/tmp/php-fpm.sock|fcgi://127.0.0.1:9000/home/srv/apache2.4/drupal8/
    DirectoryIndex index.php index.html index.htm
    ErrorLog "/var/log/drupal8-bsd-dev.local-error_log"
    CustomLog "/var/log/drupal8-bsd-dev.local-access_log" common
</VirtualHost>

<VirtualHost *:443>
    SSLEngine on
    SSLCertificateFile "/usr/local/etc/apache22/ssl/mydomain.com/1b20ec56bae90f.crt"
    SSLCertificateKeyFile "/usr/local/etc/apache22/ssl/mydomain.com/mydomain.com.key"
    SSLCertificateChainFile "/usr/local/etc/apache22/ssl/mydomain.com/gd_bundle-g1-g1.crt"

    ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/home/srv/web-dev/apache22/host_not_found/$1

    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "/home/srv/web-dev/apache22/host_not_found"
    ErrorLog "/var/log/apache22/host-not-found-error_log"
    CustomLog "/var/log/apache22/host-not-found-access_log" common
</VirtualHost>

<VirtualHost *:443>
    SSLEngine on
    SSLCertificateFile "/usr/local/etc/apache22/ssl/mydomain.com/1b20ec56bae90f.crt"
    SSLCertificateKeyFile "/usr/local/etc/apache22/ssl/mydomain.com/mydomain.com.key"
    SSLCertificateChainFile "/usr/local/etc/apache22/ssl/mydomain.com/gd_bundle-g1-g1.crt"

    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/home/srv/web-dev/apache22/drupal6"

    ServerName web-dev.local
    ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/home/srv/web-dev/apache22/drupal6/$1

    DirectoryIndex /index.php index.php index.html index.htm

    ErrorLog "/var/log/apache22/host-not-found-error_log"
    CustomLog "/var/log/apache22/host-not-found-access_log" common
</VirtualHost>

# /usr/local/etc/rc.d/apache24 restart

# httpd -t -D DUMP_VHOSTS

VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server web-dev.local (/usr/local/etc/apache24/extra/httpd-vhosts.conf:23)
         port 80 namevhost web-dev.local (/usr/local/etc/apache24/extra/httpd-vhosts.conf:23)

*:443                  is a NameVirtualHost
         default server web-dev.local (/usr/local/etc/apache24/extra/httpd-vhosts.conf:82)
         port 443 namevhost web-dev.local (/usr/local/etc/apache24/extra/httpd-vhosts.conf:82)

# vim /etc/hosts

127.0.0.1 bsd-dev.local
127.0.0.1 drupal8.bsd-dev.local

# /usr/local/etc/rc.d/apache24 restart

# httpd -V | grep MPM

Server MPM:     event

Check the PHP-FPM setting:

<?php
  echo phpinfo();
?>

Note: you should see the message: Server API: FPM/FastCGI

# cp /usr/local/share/mysql/my-default.cnf /etc/my.cnf

# vim /etc/rc.conf

mysql_enable="YES"
mysql_dbdir="/home/srv/mysql56"

# vim /etc/my.cnf

[mysqld]
innodb_buffer_pool_size = 512M
datadir = /home/srv/mysql56

# /usr/local/bin/mysql_install_db

Check if this file exists (remove it maybe?):

# ls /usr/local/my.cnf

# find /home/srv/mysql56/ | xargs -I {} chown mysql:mysql {}
# find /home/srv/mysql56/ -type d | xargs -I {} chmod 700 {}
# find /home/srv/mysql56/ -type f | xargs -I {} chmod 660 {}

# /usr/local/etc/rc.d/mysql-server restart

# /usr/local/bin/mysql_secure_installation

# mysql -u root -p

mysql> GRANT ALL PRIVILEGES ON *.* TO 'test'@'%' IDENTIFIED BY '123456';
mysql> FLUSH PRIVILEGES;

# rm ~/.mysql_history

# cd
# touch ~/.my.cnf
# chmod 400 ~/.my.cnf
# vim ~/.my.cnf

[client]
host = localhost
port = 3306
user = root
password = MyPassword

[clientconn1]
host = localhost
port = 3306
user = root
password = MyPassword
database = MyDBName

[mysqldump]
host = localhost
port = 3306
user = root
password = MyPassword

Reference:

https://wiki.apache.org/httpd/PHP-FPM
http://blog.ijun.org/2012/01/mysqldump-read-password-from-file-for.html

No comments: