Linux MintUbuntu Based

How To Install PHP on Linux Mint 22

Install PHP on Linux Mint 22

In this tutorial, we will show you how to install PHP on Linux Mint 22. PHP, which stands for Hypertext Preprocessor, is a widely-used server-side scripting language. It is particularly popular for web development, enabling developers to create dynamic web pages, handle forms, interact with databases, and perform various server-side tasks. With the release of PHP 8.3, developers gain access to new features, performance enhancements, and bug fixes that can significantly improve their web applications.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of PHP on Linux Mint 22.

Prerequisites

  • A server running one of the following operating systems: Linux Mint 22.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • While we’ll guide you through the process, a basic understanding of the command line will be beneficial. If you’re new to the CLI, you might want to acquaint yourself with some fundamental commands.
  • A stable internet connection for downloading packages.
  • Administrative privileges are essential for installing and configuring software on your system. Ensure that you have superuser or sudo access.

Install PHP on Linux Mint 22

Step 1. Update Your Linux Mint System.

Before installing any new software, it’s good practice to update your system’s package index. Open a terminal and run the following command:

sudo apt update
sudo apt upgrade

This command refreshes the list of available packages and their versions, ensuring you have the most up-to-date information.

Step 2. Installing PHP.

The default repositories in Linux Mint 22 do not include PHP 8.3. Therefore, we need to add a Personal Package Archive (PPA) maintained by Ondřej Surý, which contains the latest PHP versions.

First, install the necessary dependencies:

sudo apt install software-properties-common ca-certificates lsb-release apt-transport-https

Next, add Ondřej Surý’s PPA to your system:

sudo add-apt-repository ppa:ondrej/php

Update the package list to include the new repository:

sudo apt update

Now that the repository is added, you can install PHP 8.3 using the following command:

sudo apt install php8.3

To confirm that PHP 8.3 has been installed successfully, check the PHP version:

php -v

You should see an output similar to:

PHP 8.3.0 (cli) (built: May 20 2024 08:50:08) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.0, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.0, Copyright (c), by Zend Technologies

Step 3. Installing Additional PHP Extensions.

Depending on your project requirements, you may need additional PHP extensions. Some commonly used extensions include:

  • php8.3-mysql
  • php8.3-xml
  • php8.3-curl
  • php8.3-mbstring
  • php8.3-zip

You can install multiple extensions simultaneously using the following command:

sudo apt install php8.3-{cli,pdo,mysql,zip,gd,mbstring,curl,xml,bcmath,common}

To verify that the extensions are installed and loaded correctly, use the following command:

php -m

Step 4. Configuring PHP 8.3

PHP configuration files are located in /etc/php/8.3/cli/php.ini. These files allow you to customize PHP settings according to your needs.

Edit the php.ini file to make common configuration changes, such as increasing the memory limit or upload file size:

For example, to increase the memory limit, find the line:

memory_limit = 128M

and change it to:

memory_limit = 256M

To apply the changes, restart your web server. If you are using Apache, use the following command:

sudo systemctl restart apache2

For Nginx, use:

sudo systemctl restart nginx

Step 5. Running PHP 8.3 Alongside Other Versions.

In some cases, you may need to run multiple versions of PHP on the same system. Linux Mint provides a convenient way to manage multiple PHP versions using the update-alternatives command. To configure PHP alternatives, run the following command:

sudo update-alternatives --config php

This command will display a list of available PHP versions on your system. Enter the number corresponding to the PHP version you want to use as the default.

To switch between PHP versions, you can use the following command, replacing /usr/bin/php8.3 with the path to the desired PHP version:

sudo update-alternatives --set php /usr/bin/php8.3

This command will set PHP 8.3 as the default PHP version on your system.

Congratulations! You have successfully installed PHP. Thanks for using this tutorial to install the latest version of the PHP on the Linux Mint system. For additional help or useful information, we recommend you check the official PHP website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button