In this tutorial, we will walk you through installing PHP 8.2 and some commonly used extensions on an Ubuntu Server 22.04. PHP is a server-side scripting language that is mainly used to develop web applications. With PHP, you can create dynamic web pages and manage databases.

Step 1: Update your system

Before we install PHP, we should make sure that our system is up to date. To do this, open the terminal and run the following commands:

sudo apt update
sudo apt upgrade

Step 2: Installing PHP 8.2

Now we are ready to install PHP 8.2. Run the following command:

sudo apt install php8.2

After the installation is complete, you can verify that PHP was installed successfully by running the following command:

php -v

You should see output showing the PHP version.

Step 3: Installing frequently used extensions

PHP extensions are additional modules that extend PHP functionality and allow it to perform various tasks. Here are some commonly used extensions and how to install them:

MySQL extension:

sudo apt install php8.2-mysql

SQLite extension:

sudo apt install php8.2-sqlite3

GD extension (for image processing):

sudo apt install php8.2-gd

JSON extension:

sudo apt install php8.2-json

XML extension:

sudo apt install php8.2-xml

You can add more extensions as needed. Here is a list of all available extensions: https://www.php.net/manual/de/extensions.alphabetical.php

Step 4: Adjust PHP configuration (optional)

Depending on your requirements, you may need to adjust the PHP configuration. The configuration file is usually located at /etc/php/8.2/apache2/php.ini for the Apache web server configuration. Use a text editor of your choice to open the file and adjust the settings accordingly.

Step 5: Secure PHP via the firewall

It is important to ensure the security of the server. We will use the pre-installed firewall (ufw) to restrict access to PHP. By default, HTTP port 80 is open for web traffic. Run the following commands to configure the firewall:

sudo ufw allow 80/tcp
sudo ufw enable

This will open the HTTP port and enable the firewall. Be sure to close any other ports you don't need.

Conclusion

In this tutorial, we installed PHP 8.2 and some commonly used extensions on an Ubuntu Server 22.04. PHP is a versatile scripting language that is essential for web development. Remember to keep an eye on your server security and only open necessary ports. You are now ready to use PHP for developing dynamic web applications. Happy coding!