When you use AWS Lightsail, you probably have WordPress packed by Bitnami. And that one is considered by many as not production ready because when you need to upgrade PHP, you have to create a new instance and migrate your entire WordPress blog or Multisite blog network.
But there is also an alternative way.
Without Migration
Here’s how to upgrade to any version of PHP on Bitnami without migration. Also works for WordPress or WordPress Multisite. I use AWS Lightsail for simplicity.
Quick overview
- Install the PHP
- Update php.ini to use the non-default MySQL socket location used by the Bitnami server
- Create a php-fpm pool that runs as the “daemon” user
- Update the Apache configuration to use the new PHP version
Let’s do it!
Enable PHP repository
sudo apt-get update
sudo apt-get -y install lsb-release ca-certificates curl
sudo curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
sudo apt-get update
Install PHP 8.2
sudo apt update
sudo apt install -y php8.2-bcmath php8.2-cli php8.2-common php8.2-curl php8.2-gd php8.2-imap php8.2-intl php8.2-mbstring php8.2-mysql php8.2-readline php8.2-soap php8.2-xml php8.2-xmlrpc php8.2-zip php8.2-fpm
If you need a different version of PHP, change 8.2 with whatever version you need.
Edit php.ini
sudo vi /etc/php/8.2/fpm/php.ini
1.
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"
If you have MySQL instead of MariaDB, 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/mysql/tmp/mysql.sock"
2.
Find
mysqli.default_socket =
Replace with
mysqli.default_socket = "/opt/bitnami/mariadb/tmp/mysql.sock"
If you have MySQL instead of MariaDB, replace with
mysqli.default_socket = "/opt/bitnami/mysql/tmp/mysql.sock"
Enable php-fpm
Create php-fpm pool file
sudo vi /etc/php/8.2/fpm/pool.d/wp.conf
Add
[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.2 fpm service
sudo systemctl enable php8.2-fpm
sudo systemctl restart php8.2-fpm
Edit file
sudo vi /opt/bitnami/apache2/conf/bitnami/php-fpm.conf
For some installations, file is located at
sudo vi /opt/bitnami/apache2/conf/php-fpm-apache.conf
Inside the file find
<IfDefine USE_PHP_FPM>
<Proxy "unix:/opt/bitnami/php/var/run/www.sock|fcgi://www-fpm" timeout=30
</Proxy>
<FilesMatch \.php$>
<If "-f %{REQUEST_FILENAME}">
SetHandler "proxy:fcgi://www-fpm"
</If>
</FilesMatch>
Find
www.sock
Replace with
ww2.sock
Restart Apache
sudo /opt/bitnami/ctlscript.sh restart apache
Check installed PHP version
Method 1
Go to WordPress admin -> Tools -> Site Health -> Server
Method 2
Create phpinfo.php file at
/opt/bitnami/wordpress/phpinfo.php
Add
<?php
phpinfo();
Check in browser
"https://yourwebsite.com/phpinfo.php"
With Migration
For WordPress Multisite, use plugin MigrateGuru. It’s the best and free.
Leave a Reply