Let me give you an example of installing Memcached, which allows you to cache data in RAM.Continue reading “Installing Memcached”
Let me give you an example of a PHP script displaying a list of debtors from the Nika ASRM database:Continue reading “PHP script “TOP debtors of the Nika billing system””
I noticed once on one of the new Ubuntu servers an error when opening phpMyAdmin – “The extension mysqli | mysql not found.”Continue reading “How to solve “Extension mysqli | mysql not found””
I will give an example of a simple caching of PHP pages with an interval of 600 seconds (10 minutes).
Paste at the beginning of the code:Continue reading “Simple page caching”
I once noticed the following notification when writing a PHP script:
PHP Notice: Use of undefined constant uid - assumed 'uid' in /scripts/file.php on line 31 PHP Notice: Use of undefined constant value - assumed 'value' in /scripts/file.php on line 32
I will give an example of a PHP script to which I send SMS messages through the GoIP4 gateway.
First, we choose tariffs with only monthly charges:Continue reading “Script to send SMS via Goip4 gateway for ABillS”
Once it was necessary to upgrade the version of PHP 5.5.9 to 5.6 on Ubuntu Server 14.04 LTS, the usual update of the system components did not help:
sudo apt-get update sudo apt-get upgrade
You can try to upgrade the system to 16.04 or higher as I described in the article Updating Ubuntu 14.04 to 16.04. Together with the system will be updated and PHP.
If the system update fails, you can add a third-party source with PHP:
sudo add-apt-repository ppa:ondrej/php sudo apt-get update
And install the correct version from it, for example PHP 5.6:
sudo apt-get install php5.6 php5.6-mbstring php5.6-mcrypt php5.6-mysql php5.6-xml
Since there are several installed versions, disable the old version and activate the installed one:
sudo a2dismod php5 sudo a2enmod php5.6 sudo service apache2 restart
Similarly, you can install PHP 7.2:
sudo apt-get install php7.2 sudo a2dismod php5.6 sudo a2enmod php7.2 sudo service apache2 restart
Or PHP 7.0:
sudo apt-get install php7.0 sudo a2dismod php7.2 sudo a2enmod php7.0 sudo service apache2 restart
Once I updated EasyApache 3 to EasyApache 4 in cPanel and noticed in the PHP logs the following:
[29-Mar-2018 15:54:45 UTC] PHP Warning: Unknown: open(/var/cpanel/php/sessions/ea-php56/sess_3d96o7nnlnnr473p8619vqkdm1, O_RDWR) failed: Permission denied (13) in Unknown on line 0 [29-Mar-2018 15:54:45 UTC] PHP Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/cpanel/php/sessions/ea-php56) in Unknown on line 0
The warning occurs because PHP can not write session files to a directory to which it does not have access rights.
I looked at the rights of this directory, the group and owner was root, and it was also allowed to write and execute for everyone, except reading.
To resolve this warning, you can open full access for everyone:
chmod 777 /var/cpanel/php/sessions/ea-php56
Or open a PHP configuration, for example in the nano editor:
session.save_path = "/var/cpanel/php/sessions/ea-php56"
And change to:
session.save_path = "/tmp"
That used to be on the old EasyApache3 in the PHP configuration /usr/local/lib/php.ini.
After that, the warning did not appear.
I’ll give a couple of examples of saving the data of the incoming POST request to a file:
$s = implode('|', $_POST); exec('echo $s >> file.txt');
Example of option 2 with a specific parameter:
This error can occur after upgrading PHP to a newer version.
Actually, the split() function is deprecated with PHP 5.3.x and must be replaced in the code with preg_split()