Empowering you with the knowledge to master Linux web hosting, DevOps and Cloud

 Linux Web Hosting, DevOps, and Cloud Solutions

Tag: php-fpm

Installing PHP GEOS module on a RunCloud Server

PHP GEOS is a PHP extension for geographic objects support, while RunCloud is a cloud server control panel designed for PHP applications. With PHP GEOS module installed on RunCloud, PHP applications can take advantage of geographic data and use the GEOS (Geometry Engine – Open Source) library to perform spatial operations.

In this blog post, I will show you how to install PHP GEOS module on RunCloud module.

Steps
1. Install the required development tools

Before installing the PHP GEOS module, make sure that the required development tools are installed on your Ubuntu server. You can install them by running the following command:

apt-get install autoconf

2. Install GEOS library
Next, download and install the latest GEOS (Geometry Engine – Open Source)

wget http://download.osgeo.org/geos/geos-3.9.4.tar.bz2
tar xvf geos-3.9.4.tar.bz2
cd geos-3.9.4/
./configure
make
make install

3. Install PHP GEOS module

Now, it’s time to install the PHP GEOS module. Follow the steps below to install it for PHP 8.2:

# Set module name
MODULE_NAME="geos"

Download the latest module files

git clone https://git.osgeo.org/gitea/geos/php-geos.git
mv php-geos/ php-geos_PHP82

# make clean will always fail if you never compile it before
make clean
/RunCloud/Packages/php82rc/bin/phpize --clean
/RunCloud/Packages/php82rc/bin/phpize
./configure --with-php-config=/RunCloud/Packages/php82rc/bin/php-config
make && make install

This will install geos.so in the correct php extension directory

4. Add the module to PHP.ini file
echo "extension=$MODULE_NAME.so" > /etc/php82rc/conf.d/$MODULE_NAME.ini

And finally restart the PHP FPM service
systemctl restart php82rc-fpm

It’s important to note that the above steps are specific to PHP 8.2. If you wish to install the module for a different version, you will need to modify the commands accordingly. For instance, you can replace PHP 8.2 with 8.1 with below changes:
Replace /RunCloud/Packages/php82rc/bin/phpize with /RunCloud/Packages/php81rc/bin/phpize, replace ./configure –with-php-config=/RunCloud/Packages/php82rc/bin/php-config with ./configure –with-php-config=/RunCloud/Packages/php81rc/bin/php-config, replace /etc/php82rc/conf.d/$MODULE_NAME.ini with /etc/php81rc/conf.d/$MODULE_NAME.ini, and replace systemctl restart php82rc-fpm with systemctl restart php81rc-fpm.

You can contact me if you need help with installing any custom modules on RunCloud control panel.

Downgrading PHP Version on Bitnami WordPress in AWS Lightsail instance

Hi all

Recently, I helped one of my clients who was using an Amazon Lightsail WordPress instance provided by Bitnami. Bitnami is advantageous in that it provides a fully working stack, so you don’t have to worry about configuring LAMP or environments. You can find more information about the Bitnami Lightsail stack here.

However, the client’s stack was using the latest PHP 8.x version, while the WordPress site he runs uses several plugins that need PHP 7.4. I advised the client to consider upgrading the website to support the latest PHP versions. However, since that would require a lot of work, and he wanted the site to be up and running, he decided to downgrade PHP.

The issue with downgrading or upgrading PHP on a Bitnami stack is that it’s not possible. Bitnami recommends launching a new server instance with the required PHP, MySQL, or Apache version and migrating the data over. So, I decided to do it manually.

Here are the server details:

Debian 11
Current installed PHP: 8.1.x

Upgrading or downgrading PHP versions on a Bitnami stack is essentially the same as on a normal Linux server. In short, you need to:

Ensure the PHP packages for the version you want are installed.
Update any configuration for that PHP version.
Update your web server configuration to point to the correct PHP version.
Point PHP CLI to the correct PHP version.
Restart your web server and php-fpm.

What we did was install the PHP version provided by the OS. Then, we updated php.ini to use the non-default MySQL socket location used by the Bitnami server. We created a php-fpm pool that runs as the “daemon” user. After that, we updated the Apache configuration to use the new PHP version.

1. Make sure packages for your target version of PHP are installed
To make sure that the correct packages are available on your system for the PHP version you want, first make sure your system is up to date by running these commands:

sudo apt update
sudo apt upgrade
If it prompts you to do anything with config files, usually, you should just go with the default option and leave the current config as-is. Then, install the packages you need. For example, you can use the following command to install common PHP packages and modules:
sudo apt install -y php7.4-cli php7.4-dev php7.4-pgsql php7.4-sqlite3 php7.4-gd php7.4-curl php7.4-memcached php7.4-imap php7.4-mysql php7.4-mbstring php7.4-xml php7.4-imagick php7.4-zip php7.4-bcmath php7.4-soap php7.4-intl php7.4-readline php7.4-common php7.4-pspell php7.4-tidy php7.4-xmlrpc php7.4-xsl php7.4-fpm

2. Make sure PHP configuration for your target version is updated
Find the mysql socket path used by your Bitnami stack by running this command:

# ps aux | grep –color mysql.sock
mysql 7700 1.1 2.0 7179080 675928 ? Sl Mar21 11:21 /opt/bitnami/mariadb/sbin/mysqld –defaults-file=/opt/bitnami/mariadb/conf/my.cnf –basedir=/opt/bitnami/mariadb –datadir=/bitnami/mariadb/data –socket=/opt/bitnami/mariadb/tmp/mysql.sock –pid-file=/opt/bitnami/mariadb/tmp/mysqld.pid

Edit php.ini file

vi /etc/php/7.4/fpm/php.ini

Find

[Pdo_mysql]
; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
pdo_mysql.default_socket=

Replace with

[Pdo_mysql]
; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
pdo_mysql.default_socket= “/opt/bitnami/mariadb/tmp/mysql.sock”

Find

mysqli.default_socket =

Replace with

mysqli.default_socket = “/opt/bitnami/mariadb/tmp/mysql.sock”

Create a php-fpm pool file

vi /etc/php/8.1/fpm/pool.d/wp.conf

[wordpress]
env[PATH] = $PATH
listen=/opt/bitnami/php/var/run/www2.sock
user=daemon
group=daemon
listen.owner=daemon
listen.group=daemon
pm=dynamic
pm.max_children=400
pm.start_servers=260
pm.min_spare_servers=260
pm.max_spare_servers=300
pm.max_requests=5000

Feel free to adjust the PHP FPM settings to match your server specifications or needs. Check out this informative article for more tips on optimizing PHP FPM performance. Just keep in mind that Bitnami configures their stack with the listen.owner and listen.group settings set to daemon.

This pool will listen on unix socket “/opt/bitnami/php/var/run/www2.sock”.

Enable and restart PHP 8.1 fpm service

systemctl enable php7.4-fpm
systemctl restart php7.4-fpm

3. Update your web server configuration to point to the correct PHP version

Edit file

vi /opt/bitnami/apache2/conf/bitnami/php-fpm.conf

For some installations, file is located at

vi /opt/bitnami/apache2/conf/php-fpm-apache.conf

Inside you file find



SetHandler “proxy:fcgi://www-fpm”

Find and replace www.sock with www2.sock

4. Make sure PHP-CLI points to the right PHP version

Rename the default PHP installed by bitnami.

mv /opt/bitnami/php/bin/php /opt/bitnami/php/bin/php_8.1_bitnami.

create a symlink from newly installed PHP 7.4

ln -s /usr/bin/php7.4 /opt/bitnami/php/bin/php

Test the installed version by running below command
~# php -v
PHP 7.4.33 (cli) (built: Feb 22 2023 20:07:47) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies

5. Restart PHP-FPM and your webserver

sudo systemctl restart php7.4-fpm; sudo /opt/bitnami/ctlscript.sh restart apache

Powered by WordPress & Theme by Anders Norén