How to Check PHP Version and MySQL Version with XML Extension on Ubuntu VPS for MyBB Installation


2 views

For PHP version check:

php -v

Sample output:

PHP 8.1.2-1ubuntu2.14 (cli) (built: Aug 18 2023 11:41:11)
Copyright (c) The PHP Group

For MySQL version:

mysql --version

Or for MariaDB:

mariadb --version

Example output:

mysql  Ver 8.0.34-0ubuntu0.22.04.1 for Linux on x86_64

Two methods to verify XML support:

php -m | grep xml

Or more detailed:

php -i | grep -i xml

Sample output showing XML is enabled:

libxml
xml
xmlreader
xmlwriter

Create a verification script if needed:

<?php
$requirements = [
    'PHP Version' => version_compare(PHP_VERSION, '5.1.0', '>='),
    'MySQL Version' => function_exists('mysqli_connect'),
    'XML Extension' => extension_loaded('xml')
];

foreach ($requirements as $name => $met) {
    echo "$name: " . ($met ? "✔" : "❌") . "\n";
}
?>

Run it with:

php test_requirements.php

For Ubuntu/Debian systems:

apt list --installed | grep -E 'php|mysql|mariadb'

To check specifically for XML package:

apt list --installed | grep php.*xml

Command-line alternative to phpinfo():

php -r 'phpinfo();' | less

Search for XML section by typing /xml in less viewer.


For PHP version:

php -v

Sample output:

PHP 8.1.2 (cli) (built: Mar  4 2022 18:13:46)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies

For MySQL version:

mysql --version

Or for MariaDB:

mariadb --version

To verify XML extension is installed:

php -m | grep xml

Should return xml if installed. For detailed module list:

php -m

Create a temporary PHP file for detailed info:

echo "" > phpinfo.php
php phpinfo.php | less

For MySQL server version (when logged in):

mysql> SELECT VERSION();

Using apt to verify installed versions:

apt list --installed | grep -E 'php|mysql|mariadb'

Create a bash script to check requirements:

#!/bin/bash

# Check PHP
php_version=$(php -v | head -n 1 | cut -d " " -f 2)
echo "PHP Version: $php_version"

# Check MySQL
mysql_version=$(mysql --version | awk '{print $5}' | cut -d ',' -f 1)
echo "MySQL Version: $mysql_version"

# Check XML extension
php -m | grep -q xml && echo "XML Extension: Installed" || echo "XML Extension: Missing"

Save as check_versions.sh and make executable:

chmod +x check_versions.sh
./check_versions.sh

If XML extension is missing:

sudo apt install php-xml
sudo systemctl restart apache2  # or nginx/php-fpm