How to Upgrade PHP on Bitnami WordPress in AWS Lightsail
I have an old Bitnami WordPress server on the Amazon Lightsail server. Bitnami does not support upgrading the PHP version. The recommended solution is to create a new bitnami WordPress instance and migrate the website to the new lightsail instance. Since this server had many websites configured, I do not want to migrate the websites to the new bitnami WordPress instance. Here is how I upgraded the PHP version on bitnami Debian 10 server from PHP 7.3 to PHP 8.1
What we do is install the PHP version provided by the OS. Then update php.ini to use the non-defult MySQL socket location used by the Bitnami server. Create a php-fpm pool that runs as the “daemon” user. After that, we update the Apache configuration to use the new PHP version.
First, enable PHP repository
1 2 3 |
apt -y install apt-transport-https lsb-release ca-certificates wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list |
Install PHP 8.1
1 2 |
apt update apt install -y php8.1-bcmath php8.1-cli php8.1-common php8.1-curl php8.1-gd php8.1-imap php8.1-intl php8.1-mbstring php8.1-mysql php8.1-readline php8.1-soap php8.1-xml php8.1-xmlrpc php8.1-zip php8.1-fpm |
If you need a different version of PHP, change 8.1 with whatever version you need.
Edit php.ini file
1 |
vi /etc/php/8.1/fpm/php.ini |
Find
1 2 3 4 |
[Pdo_mysql] ; Default socket name for local MySQL connects. If empty, uses the built-in ; MySQL defaults. pdo_mysql.default_socket= |
Replace with
1 2 3 4 |
[Pdo_mysql] ; Default socket name for local MySQL connects. If empty, uses the built-in ; MySQL defaults. pdo_mysql.default_socket= "/opt/bitnami/mysql/tmp/mysql.sock" |
Find
1 |
mysqli.default_socket = |
Replace with
1 |
mysqli.default_socket = "/opt/bitnami/mysql/tmp/mysql.sock" |
Create a php-fpm pool file
1 |
vi /etc/php/8.1/fpm/pool.d/wp.conf |
add
1 2 3 4 5 6 7 8 9 10 11 12 |
[wordpress] listen=/opt/bitnami/php/var/run/ww2.sock user=daemon group=daemon listen.owner=daemon listen.group=daemon pm=dynamic pm.max_children=5 pm.start_servers=2 pm.min_spare_servers=1 pm.max_spare_servers=3 pm.max_requests=5000 |
This pool will listen on unix socket “/opt/bitnami/php/var/run/ww2.sock”.
Enable and restart PHP 8.1 fpm service
1 2 |
systemctl enable php8.1-fpm systemctl restart php8.1-fpm |
Edit file
1 |
vi /opt/bitnami/apache2/conf/bitnami/php-fpm.conf |
For some installations, file is located at
1 |
vi /opt/bitnami/apache2/conf/php-fpm-apache.conf |
Inside you file find
1 2 3 4 5 6 7 8 |
<IfDefine USE_PHP_FPM> <Proxy "unix:/opt/bitnami/php/var/run/www.sock|fcgi://www-fpm" timeout=300> </Proxy> <FilesMatch \.php$> <If "-f %{REQUEST_FILENAME}"> SetHandler "proxy:fcgi://www-fpm" </If> </FilesMatch> |
Find
1 |
www.sock |
Replace With
1 |
www2.sock |
Restart Apache
1 |
sudo /opt/bitnami/ctlscript.sh restart apache |
See Bitnami