[:en]PHP tips and tricks[:]

By admin, February 20, 2018

[:en]Once I used to be a Java and Python backend programmer, the similarities I could find among Python and PHP were the web server (Apache), the roots and style.

Why PHP?

Why not? When this article was written, there were a plethora of systems out there backed by this language, some of them industry’s giants as Facebook. I myself worked with PHP for a couple of years both front-end and backend, mostly customizing and ingesting data to SugarCRM. Also, the new version – PHP 7.x comes with improvements that can optimize speed and memory usage performance. The core also allows more features and drives to packages and frameworks that are on the verge of allowing functional programming.

 

Some basics (regarding resources, of course)

As usual, I selected some useful links regarding this subject.

UTF-8 BOM
https://stackoverflow.com/questions/5368150/php-header-excel-and-utf-8
PHP + CRON
https://stackoverflow.com/questions/4421020/use-php-to-create-edit-and-delete-crontab-jobs
https://code.tutsplus.com/tutorials/managing-cron-jobs-with-php–net-19428
IIS + PHP
https://jamesmccaffrey.wordpress.com/2017/01/26/installing-php-on-windows-10-and-iis/
IIS+Apache2.4+PHP
http://lifeofageekadmin.com/how-to-install-apache-2-4-mysql-and-php-on-windows-server-2012/
Cool Apache conf
https://askubuntu.com/questions/50344/how-to-have-two-versions-of-php-installed-and-switch-easily-between-them
https://www.server-world.info/en/note?os=CentOS_7&p=httpd&f=6

Generating big excel spreadsheets

Thus, in order to allow downloading “big” tables – they are not big if they fit an Excel spreadsheet at all – but still big for some engines, as PHPExcel.

So after researching a bit, I’ve found https://github.com/box/spout ,  a fast and low resource consuming XLSX generator.

This was a key tool in order to use PHP as interface for some front-end solutions I’ve been working on.

Even creative, I really do not fancy solutions like posted in http://www.the-art-of-web.com/php/dataexport/, even reckognizing that they might be useful in very very very specific scenarios (as of 2015 maybe).

 

Changing the PHP version in CentOS – from 5.6 to 7.1

Here are a sequence of commands and a repository where get an EPEL

$php -v

(should show somethin like 5.6.x)

First, install epel and web static repository
$ sudo yum install epel-release
$ sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
$ sudo yum update

Check the available packages
$ sudo yum search php7

Other examples
$ sudo yum search mod_php7

Backup opcache

$ sudo cp /etc/php.d/opcache.ini /etc/php.d/opcache.ini.bak

Remove old 5.6 packages

$ sudo yum remove php56w php56w-cli php56w-common php56w-fpm php56w-gd php56w-mbstring php56w-mysqlnd php56w-opcache php56w-pdo php56w-pear php56w-pecl-igbinary php56w-pecl-memcache php56w-pecl-memcached php56w-process php56w-xml

Install the 7.1 packages

$ sudo yum install php71w-bcmath php71w-cli mod_php71w php71w-common php71w-dba php71w-devel php71w-embedded php71w-enchant php71w-fpm php71w-gd php71w-imap php71w-interbase php71w-intl php71w-ldap php71w-mbstring php71w-mcrypt php71w-mysqlnd php71w-odbc php71w-opcache php71w-pdo php71w-pdo_dblib php71w-pear php71w-pecl-apcu php71w-pecl-apcu-devel php71w-pecl-geoip php71w-pecl-igbinary php71w-pecl-igbinary-devel php71w-pecl-imagick php71w-pecl-imagick-devel php71w-pecl-libsodium php71w-pecl-memcached php71w-pecl-mongodb php71w-pecl-redis php71w-pecl-xdebug php71w-pgsql php71w-phpdbg php71w-process php71w-pspell php71w-recode php71w-snmp php71w-soap php71w-tidy php71w-xml php71w-xmlrpc

If needed, you can replace php71-common by php71w-common

$ sudo yum install yum-plugin-replace
$ sudo yum replace php-common –replace-with=php71w-common

Check the updated version

$php -version

Copy back the opcache configuration
$ sudo mv /etc/php.d/opcache.ini.bak /etc/php.d/opcache.ini

Copy if needed, your configuration
$ sudo mv /etc/php.ini.rpmsave /etc/php.ini
$ sudo mv /etc/php-fpm.d/www.conf.rpmsave /etc/php-fpm.d/www.conf
$ sudo mv /etc/php.d/z-memcached.ini.rpmsave /etc/php.d/z-memcached.ini

Checking some extensions (CLI mode)

verify iconv
$ php -i | grep -i “iconv support”
$ curl -V
$ php -m

Further Reference:

https://webtatic.com/packages/php71/

 

[:]