Monday, April 30, 2018

PHPConsoleOutput

Simple PHP console output helper.

While using PHPUnit, you may want to output or debug your tests.
Normal echo/print_r/dump only outputs after PHPUnit's output, if at all.
Using ConsoleOutput will echo inline with PHPUnits output,
giving you a better context of your output/debugging.

Usage:
$this->consoleOutput = new ConsoleOutput();

$this->consoleOutput->showWarning('test showWarning');

test showWarning

View on GitHub

Monday, April 16, 2018

PHPFormatSize

Simple PHP formatter for bytes
Usage:

$this->formatSize = new FormatSize();

$bytes = 4398046511104;
$decimals = 2;
$formatted = $this->formatSize->formatBytes($bytes, $decimals);
$this->assertEquals('4.00 TB', $formatted); 


View on GitHub 

Monday, April 2, 2018

Ubuntu 16.04 Xenial serve PHP7 using PHP7-fpm and Apache 2.4

Ubuntu 16.04 Xenial
Serve PHP7 using PHP7-fpm and Apache 2.4

By default, in Ubuntu 16.04 Xenial, installing the packages for PHP, PHP-fpm, and Apache does not result in a working php website.  The extra configuration required follows:

Install Apache2
> sudo apt-get -y install apache2

Install php, with some common packages
> sudo apt-get -y install php php-cli php-mbstring php-gd php-mcrypt php-pgsql php-mysql php-xml php-curl php-intl

Create your own apache vhost config

> vi /etc/apache2/sites-available/vhosts

<VirtualHost *:80>
    ServerName tutorial.localhost
    DocumentRoot /path/to/tutorial/web
    SetEnv APP_ENV "dev"
    <Directory /path/to/tutorial/web>
        AllowOverride All
        Require all granted #<-- 2.4 New configuration
    </Directory>
</VirtualHost>

Enable your vhost config
> sudo a2ensite vhosts

Disable the defualt config
> sudo a2dissite 000-default

And the missing parts of conflagration:

Enable php7-fpm
> sudo a2enconf php7.0-fpm

Enable rewrite so frameworks such as Symfony, Zend, Larvel, etc work with 'pretty' urls
enable proxy so apache can send php requests to php7-fpm
> sudo a2enmod rewrite proxy proxy_fcgi

And restart apache
> sudo systemctl restart apache2

PHP should be working now
> vi /path/to/webroot/phpinfo.php

<?php
phpinfo();

End of document. Thanks for reading.