How to Upgrade PHP on Debian 9 10 11

Upgrade or Install PHP 8.2 on Debian running Apache2

This tutorial show you how to install or upgrade PHP 8.2 quick and easy for Apache web server running on Debian 9 or Debian 10 and Debian 11. PHP is the widely used server scripting language for dynamic and interactive websites and content management systems.

5 steps to perform PHP 8.2 for Apache2 on Debian.

1. Updating Debian as root

$ su -
$ apt update
$ apt upgrade -y && reboot

2. Add SURY PHP PPA Repository

SURY is a third-party repository that offers current PHP versions for Debian GNU/Linux, which is added as root.

$ apt -y install lsb-release apt-transport-https ca-certificates wget
$ 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" | tee /etc/apt/sources.list.d/php.list

3. Installing PHP 8.2 on Debian

$ apt update
$ apt -y install php8.2
$ update-alternatives --set php /usr/bin/php8.2

More than one PHP version can be installed on the system, run update-alternatives --set php [version] to enable a Version.

4. Install Important Modules for PHP 8.2 on Debian

$ apt -y install php8.2-cli php8.2-curl php8.2-gd php8.2-intl php8.2-mbstring php8.2-mysql php8.2-opcache php8.2-readline php8.2-xml php8.2-xsl php8.2-zip php8.2-bz2

5. Making PHP 8.2 module for Apache available

$ apt -y install libapache2-mod-php8.2
$ systemctl reload apache2

Finish! the installation is done. If you want to know which installed PHP version and modules are actually available, the next section shows.

Check the current PHP version

$ php -v 
PHP 8.2.3 (cli) (built: Feb 14 2023 16:53:07) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.3, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.3, Copyright (c), by Zend Technologies

Show current PHP configuration

The current PHP settings are displayed by creating a .php-file with the following content, to output the detailed settings in the web browser.

<?php
phpinfo();
?>

Save the file as phpinfo.php in the “/html” directory. Then open the newly created .php-file in a web browser.

http://example.org/phpinfo.php
php version on debian view in web browser
Image: http://my-domain/phpinfo.php

The system-wide PHP settings can be found under the path /etc/php, for modification using Apache 2 edit the php.ini file.

$ vi /etc/php/8.2/apache2/php.ini

If you do not see the installed php version, may the apache php module need to change to the desired version, run the apache helper command in the terminal, replace the version you have instead, like here php.7.4 in this example.

$ a2dismod php7.4
$ a2enmod php8.2
$ systemctl restart apache2

Check enabled PHP modules

Verify the running php module with this shell command.

$ php -m

Verify the running php module with view the phpinfo.php from the web browser.

<?php
phpinfo(INFO_MODULES);
?>

The PHP modules available for Apache 2 can find in the Apache web server path under /etc/apache2/mods-available

$ ll /etc/apache2/mods-available/php*
-rw-r--r-- 1 root root 855 Jul  5  2020 /etc/apache2/mods-available/php7.3.conf
-rw-r--r-- 1 root root 102 Jul  5  2020 /etc/apache2/mods-available/php7.3.load
-rw-r--r-- 1 root root 855 Dec 20 22:32 /etc/apache2/mods-available/php7.4.conf
-rw-r--r-- 1 root root 102 Dec 20 22:32 /etc/apache2/mods-available/php7.4.load
-rw-r--r-- 1 root root 855 Dec 20 22:32 /etc/apache2/mods-available/php8.2.conf
-rw-r--r-- 1 root root 101 Dec 20 22:32 /etc/apache2/mods-available/php8.2.load

Disable an Apache 2 module with a2dismod, use a2enmod to enable. The apt info command provides information about module information.

$ apt info libapache2-mod-php8.2

Specify the desired php version of a website in apache .htaccess file.

Action php /cgi-php82/php
AddHandler php82 .php

PowerShell Invalid Password Exception

In working with Powershell by creating user accounts, may the invalid password exception, InvalidPasswordException error message appears.

New-LocalUser: An exception of type “Microsoft.PowerShell.Commands.InvalidPasswordException”.

PowerShell The error message invalid password exception appers.

Cause

The Local Group Policy for password complexity requirements do not match the input, or the minimum password length is not met. The Powershell error message invalid password exception appers.

Solution

Change Minimum Password Length

Set Minimum Password Length to increase or decrease the password length to the desired length.

powershell error message invalid password exception appers.. Change Minimum Password Length

In Local Group Policy (gpedit.msc), change the Minimum Password Length, 0 for no Minimum Password Length.

Example. creates a user account in the powershell

The following Powershell command creates a user account with a password from the one line command, useful for script processing.

New-LocalUser user1 -Password (ConvertTo-SecureString "8170af" -AsPlainText -Force) -FullName user1 -Description user1 -PasswordNeverExpires -UserMayNotChangePassword

New User Account

If create a local user in Windows 10 or 11 you can use the User Accounts control panel. But you can also use PowerShell to create a new local user. This way we can easily automate creating a local account on Windows devices.

To create a local user with PowerShell you will need to have administrator access to the computer and run PowerShell as admin (elevated). Otherwise, you won’t be able to create accounts.

In this post, I will explain how you can create a new localuser.

New-LocalUser

To create a new local user we are going to use the New-LocalUser cmdlet in PowerShell. The cmdlt provide options to set a password for the account or create an account without a password.

Password exception

As you can see this won’t allow you to run the script autonomous, because you will need to enter a password. This is also the challenge with creating local users, most of the time you want to supply the password in a secure way.

If you run the script remotely or under your own supervision then you could write the password inside a PowerShell script and convert it to a secure string. But keep in mind, anyone who opens the script is able to read the password.