Sign In
Sign In

How to Install and Use Composer on Ubuntu

How to Install and Use Composer on Ubuntu
Hostman Team
Technical writer
Ubuntu PHP
14.02.2025
Reading time: 10 min

Composer is a cross-platform tool for managing dependencies in projects written in PHP.

With Composer, you can manage numerous libraries and frameworks, known as "packages." Installing the required packages allows you to extend the standard PHP functionality, speeding up and simplifying development. All installed packages become project dependencies.

Thus, Composer can be considered a full-fledged dependency manager, similar to those used in many programming languages.

Additionally, Composer has a comprehensive package repository called Packagist, where you can search for, download, and install the required packages.

This guide provides detailed instructions on installing Composer on an Ubuntu server and using it for PHP projects.

Prerequisites

In this tutorial, we use:

  • A VPS server running Ubuntu 22.04
  • PHP interpreter version 8.1.2
  • Composer dependency manager version 2.8.2

Installing Composer

First, update the list of existing APT repositories:

sudo apt update

Next, install the packages required to download and use Composer:

sudo apt install curl php-cli unzip -y

These packages include:

  • curl: A tool for making HTTP requests.
  • php-cli: An interpreter to run PHP scripts.
  • unzip: A utility to extract ZIP archives.

The -y flag answers "yes" to all installation prompts.

Composer installation is automated using a PHP script provided by its developers.

Download the installation script from the official Composer website using an HTTP request:

curl -sS https://getcomposer.org/installer -o composerInstall.php
  • The -sS flag runs curl in silent mode, suppressing all output except for errors.
  • The -o flag specifies the filename and the directory where the file will be placed.

To ensure the file has been downloaded, check the contents of the current directory:

ls

You should see the following output in the terminal, including the installation script:

composerInstall.php  resize.log  snap

This guide covers the global installation of Composer, meaning it can be run from any directory without specifying the absolute path.

To perform a global installation, execute the downloaded PHP script with additional parameters:

php composerInstall.php --install-dir=/usr/local/bin --filename=composer
  • The --install-dir flag specifies the directory where Composer will be installed.
  • The --filename flag defines the name of the binary file accessible from the terminal.

In this case, Composer is installed in the system's binary directory: /usr/local/bin.

After running the script, you'll see the following output in the terminal:

All settings correct for using Composer  
Downloading...  

Composer (version 2.8.2) successfully installed to: /usr/local/bin/composer  
Use it: php /usr/local/bin/composer

Since the installation script is no longer needed, you can delete it:

rm composerInstall.php

To launch Composer for the first time, run:

composer

You may see the following message in the terminal:

Do not run Composer as root/super user! See https://getcomposer.org/root for details  
Continue as root/super user [yes]?

Composer warns against running it as the root user due to potential risks but allows you to proceed.

For this guide, we will continue using Composer as-is by confirming with yes.

Afterward, you will see a welcome message along with a list of available options and commands with brief descriptions.

Composer is now fully installed.

Configuring Composer

The main file used to manage dependencies is composer.json, which describes the packages required for the proper functioning of a project.

Composer follows the Infrastructure as Code (IaC) approach, describing the local project infrastructure through a configuration file rather than manual settings adjustments in a graphical interface.

However, Composer allows configuration management not only by manually editing the file in a text editor but also through console commands, providing a more interactive way to handle configurations.

Basic Commands

Using Composer involves several fundamental commands that interact with the composer.json configuration file:

  • init: Initializes a project.
  • require: Adds a package.
  • install: Installs dependencies.
  • update: Updates packages.

Although Composer offers many more commands, these are the most frequently used.

Creating a Directory

Create a separate directory for the PHP project:

mkdir phptest

Then navigate to the directory:

cd phptest

This directory will store both the project’s source code and the required dependency files.

Searching for a Library

Suppose we are working on a small project that performs various string transformations. As a dependency, we need a specific library that provides functions for manipulating string content.

In this guide, we will implement a common programming function called slugify, which converts a sequence of words into a single long word containing only lowercase ASCII characters and hyphens.

The slugify function is often used to transform arbitrary headings into URL-friendly formats without spaces.

Rather than writing this function ourselves, we will use Composer to find a suitable library in the official package registry, add it as a dependency, and let Composer handle its download, installation, and integration into the project.

To find the necessary library, follow these steps:

  1. Open the Composer's official package registry in a browser.
  2. Enter "slugify" in the search bar.
  3. Look for the most suitable package based on its parameters and description.

The search results display key metrics for each available package:

  • The number of installations via Composer (top right)
  • The number of GitHub stars (bottom right)

Image1

In general, popular packages tend to be more stable since they are used by a larger number of developers.

Selecting a Package

In this guide, we will use the package cocur/slugify.

The package name, similar to a GitHub repository, contains the author (provider) and the library name separated by a forward slash (/).

We can navigate to the package's page by clicking its name to see more details about the library’s implementation, such as dependency lists, descriptions with code examples, test coverage badges, license type, and more.

Additionally, pay attention to the available package versions, as you need to specify the version during dependency installation.

By following this process, you can search for and select suitable packages for a PHP project, which can later be used as dependencies to provide specific functions.

Installing a Dependency

To install the required package, use the require command. This either records the dependency in the composer.json configuration file or creates it if it does not exist:

composer require cocur/slugify:4.6

In this guide, we are using cocur/slugify version 4.6.0.

After running the command, you might encounter an error indicating missing system libraries:

./composer.json has been created
Running composer update cocur/slugify
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Root composer.json requires cocur/slugify 4.1 -> satisfiable by cocur/slugify[v4.1.0].
- cocur/slugify v4.1.0 requires ext-mbstring * -> it is missing from your system. Install or enable PHP's mbstring extension.

This console output informs us that the ext-mbstring system library is missing, which is necessary for cocur/slugify to work correctly.

You can manually search for the library using the APT package manager:

sudo apt search mbstring

The search results will show:

Sorting... Done
Full Text Search... Done
php-mbstring/jammy 2:8.1+92ubuntu1 all
  MBSTRING module for PHP [default]

php-patchwork-utf8/jammy 1.3.1-1 all
  UTF-8 strings handling for PHP

php-symfony-polyfill-mbstring/jammy 1.24.0-1ubuntu2 all
  Symfony polyfill for the Mbstring extension

php-symfony-polyfill-util/jammy 1.24.0-1ubuntu2 all
  Symfony utilities for portability of PHP codes

php8.1-mbstring/jammy-updates,jammy-security 8.1.2-1ubuntu2.19 amd64
  MBSTRING module for PHP

The first result is the library we need. Install it with:

sudo apt install php-mbstring -y

Once the missing library is installed, rerun the command to install the package:

composer require cocur/slugify:4.6

This time, the console output should confirm a successful installation:

./composer.json has been created
Running composer update cocur/slugify
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 0 updates, 0 removals
  - Locking cocur/slugify (v4.6.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Downloading cocur/slugify (v4.6.0)
  - Installing cocur/slugify (v4.6.0): Extracting archive
Generating autoload files
No security vulnerability advisories found.

Check the directory contents with:

ls

You will see new files generated by Composer:

composer.json  composer.lock  vendor

Each file and directory serves a specific purpose:

  • composer.json — Contains information about the required dependencies
  • composer.lock — Records details about installed dependencies
  • vendor — Stores the project’s installed dependencies

If you use a version control system like Git, exclude the vendor directory from the repository.

Take a look inside composer.json:

cat composer.json

It should look like this:

{
    "require": {
        "cocur/slugify": "4.6"
    }
}

You’ll notice the require block specifying the package cocur/slugify version 4.6. You can find more detailed information about possible version values in the official Composer documentation.

Using Composer

Including Dependencies

Once you have installed a dependency, you can include it in the project code using the automatically generated autoload.php script, located in the vendor directory.

When this script is included in the PHP application, the functions and classes of the installed dependencies become available for use.

Let's create the main file of our application:

sudo nano main.php

Then, fill it with the following content:

<?php
require __DIR__ . '/vendor/autoload.php';

use Cocur\Slugify\Slugify;

$slugify = new Slugify();

// PHP_EOL is needed for line breaks in the console

echo '[english]: ' . $slugify->slugify('How to deal with composer') . PHP_EOL;
?>

Now, you can run the script:

php main.php

The output in the console terminal should look like this:

[english]: how-to-use-composer

Updating Dependencies

Composer allows you to check for new versions of libraries based on version ranges defined in the composer.json configuration file:

composer update

Alternatively, you can update a specific package by specifying its name:

composer update cocur/slugify

Installing Dependencies

If your PHP project contains a composer.json file, but the specified dependencies are not yet installed, you need to install them.

Let’s first remove all existing packages and related information:

rm -R vendor composer.lock

The -R flag is necessary for recursive deletion of files and directories.

After that, try running the script:

php main.php

You will see the expected error message in the console because the dependencies are missing:

PHP Warning:  require(/root/phptest/vendor/autoload.php): Failed to open stream: No such file or directory in /root/phptest/main.php on line 2
PHP Fatal error:  Uncaught Error: Failed opening required '/root/phptest/vendor/autoload.php' (include_path='.:/usr/share/php') in /root/phptest/main.php:2
Stack trace:
#0 {main}
  thrown in /root/phptest/main.php on line 2

Now, let's reinstall the dependencies based on the data from the configuration file:

composer install

After that, run the script again:

php main.php

The console should display the expected result without any errors:

[english]: how-to-install-and-use-composer

Conclusion

You can install Composer on Ubuntu 22.04 automatically using an installation script from the official Composer website.

Although Composer has many commands to manage the composer.json configuration file, in practice, only a few basic ones are commonly used:

  • composer init
  • composer require
  • composer install
  • composer update

You can find comprehensive information on how to use Composer in the official documentation.

Ubuntu PHP
14.02.2025
Reading time: 10 min

Similar

Java

Switching between Java Versions on Ubuntu

Managing multiple Java versions on Ubuntu is essential for developers working on diverse projects. Different applications often require different versions of the Java Development Kit (JDK) or Java Runtime Environment (JRE), making it crucial to switch between these versions efficiently. Ubuntu provides powerful tools to handle this, and one of the most effective methods is using the update-java-alternatives command. Switching Between Java Versions In this article, the process of switching between Java versions using updata-java-alternatives will be shown. This specialized tool simplifies the management of Java environments by updating all associated commands (such as java, javac, javaws, etc.) in one go.  Overview of Java version management A crucial component of development is Java version control, especially when working on many projects with different Java Runtime Environment (JRE) or Java Development Kit (JDK) needs. In order to prevent compatibility problems and ensure efficient development workflows, proper management ensures that the right Java version is utilized for every project. Importance of using specific Java versions You must check that the Java version to be used is compatible with the application, program, or software running on the system. Using the appropriate Java version ensures that the product runs smoothly and without any compatibility issues. Newer versions of Java usually come with updates and security fixes, which helps protect the system from vulnerabilities. Using an out-of-date Java version may expose the system to security vulnerabilities. Performance enhancements and optimizations are introduced with every Java version. For maximum performance, use a Java version that is specific to the application. Checking the current Java version It is important to know which versions are installed on the system before switching to other Java versions.  To check the current Java version, the java-common package has to be installed. This package contains common tools for the Java runtimes including the update-java-alternatives method. This method allows you to list the installed Java versions and facilitates switching between them. Use the following command to install the java-common package: sudo apt-get install java-common Upon completing the installation, verify all installed Java versions on the system using the command provided below: sudo update-java-alternatives --list The report above shows that Java versions 8 and 11 are installed on the system. Use the command below to determine which version is being used at the moment. java -version The displayed output indicates that the currently active version is Java version 11. Installing multiple Java versions Technically speaking, as long as there is sufficient disk space and the package repositories support it, the administrator of Ubuntu is free to install as many Java versions as they choose. Follow the instructions below for installing multiple Java versions. Begin by updating the system using the following command:   sudo apt-get update -y && sudo apt-get upgrade -y To add another version of Java, run the command below. sudo apt-get install <java version package name> In this example, installing Java version 17 can be done by running:  sudo apt-get install openjdk-17-jdk openjdk-17-jre Upon completing the installation, use the following command to confirm the correct and successful installation of the Java version: sudo update-java-alternatives --list Switching and setting the default Java version To switch between Java versions and set a default version on Ubuntu Linux, you can use the update-java-alternatives command.  sudo update-java-alternatives --set <java_version> In this case, the Java version 17 will be set as default: sudo update-java-alternatives --set java-1.17.0-openjdk-amd64 To check if Java version 17 is the default version, run the command:  java -version The output shows that the default version of Java is version 17. Managing and Switching Java Versions in Ubuntu Conclusion In conclusion, managing multiple Java versions on Ubuntu Linux using update-java-alternatives is a simple yet effective process. By following the steps outlined in this article, users can seamlessly switch between different Java environments, ensuring compatibility with various projects and taking advantage of the latest features and optimizations offered by different Java versions. Because Java version management is flexible, developers may design reliable and effective Java apps without sacrificing system performance or stability.
22 August 2025 · 4 min to read
Ubuntu

How to Install and Configure SSH on Ubuntu 22.04

A secure connection between a client and a server is made possible via the SSH network protocol. Since all communications are encrypted, distant network attacks and data theft across the network are avoided. Let’s say you have ordered a cloud server from Hostman. You will need SSH installed and configured to connect to and administer the server. The guide below will describe how to install SSH on Ubuntu 22.04 and configure it. SSH Key configuration is pretty simple on Ubuntu Prerequisites Before proceeding with the installation and configuration of the Secure Shell service, ensure the following requirements are met: Linux Command Line Skills for Configuration Having a solid grasp of basic Linux commands like sudo, apt, nano, and systemctl is essential when setting up the service. These commands will be frequently used during the installation and configuration process. It's crucial to be comfortable working within the command line environment to manage the service effectively. Root or Sudo Access for Setup To install and configure the server, administrative (root) privileges are required. Users must either have sudo access or be logged in as root. Without these privileges, the setup process cannot proceed. Internet Connection for Package Download A stable internet connection is necessary to install the OpenSSH server and any additional related packages. Without a functional connection, the system cannot retrieve the required software components. Configuring Firewall for Access If a firewall, like ufw, is enabled on the system, it may block remote access by default. It is essential to configure your firewall to allow incoming connections. Use ufw or another firewall tool to ensure port 22 is open and accessible. Access to the System (Local or Remote) To configure the service locally, you must have physical access to your computer; otherwise, it must be remotely accessible through its IP address. To connect, make sure the system is correctly linked to the network. Don't forget, that you can deploy your cloud server fast and cheap by choosing our VPS Server Hosting Step 1: Prepare Ubuntu The first thing you need to do before you start installing SSH on Ubuntu is to update all apt packages to the latest versions. To do this, use the following command: sudo apt update && sudo apt upgrade Step 2: Install SSH on Ubuntu OpenSSH is not pre-installed on the system, so let's install it manually. To do this, type in the terminal: sudo apt install openssh-server The installation of all the necessary components will begin. Answer "Yes" to all the system prompts.  After the installation is complete, go to the next step to start the service. Step 3: Start SSH Now you need to enable the service you just installed using the command below: sudo systemctl enable --now ssh On successful startup, you will see the following system message. The --now key helps you launch the service and simultaneously set it to start when the system boots. To verify that the service is enabled and running successfully, type: sudo systemctl status ssh The output should contain the Active: active (running) line, which indicates that the service is successfully running. If you want to disable the service, execute:  sudo systemctl disable ssh It disables the service and prevents it from starting at boot. Step 4: Configure the firewall Before connecting to the server via SSH, check the firewall to ensure it is configured correctly. In our case, we have the UFW installed, so we will use the following command: sudo ufw status In the output, you should see that SSH traffic is allowed. If you don't have it listed, you need to allow incoming SSH connections. This command will help with this: sudo ufw allow ssh Step 5: Connect to the server Once you complete all the previous steps, you can log into the server using the SSH protocol. You will need the IP address or domain name of the server as well as the name of a user that was created on the server in order to complete this step. In the terminal line, enter the command: ssh username@IP_address Or:  ssh username@domain Important: To successfully connect to a remote server, SSH must be installed and configured on the remote server and the user's computer from which you make the connection.  - Step 6 (optional): Create Key Pair for Secure Authentication For enhanced security, consider configuring a key pair instead of relying on password authentication. To generate one, use the following command: ssh-keygen Step 7: Configure SSH Having completed the previous five steps, you can already connect to the server remotely. However, you can further increase the connection's security by changing the default connection port to another or changing the password authentication to key authentication. These and other changes require editing the SSH configuration file. The main OpenSSH server settings are stored in the main configuration file sshd_config (location: /etc/ssh). Before you start editing, you should create a backup of this file:  sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.initial If you get any errors after editing the configuration file, you can restore the original file without problems. After creating the backup, you can proceed to edit the configuration file. To do this, open it using the nano editor: sudo nano /etc/ssh/sshd_config In the file, change the port to a more secure one. It is best to set values from the dynamic range of ports (49152 - 65535) and use different numbers for additional security. For example, let's change the port value to 49532. To do this, we uncomment the corresponding line in the file and change the port as shown in the screenshot below. SSH Key Configuration Description in Linux Terminal In addition to this setting, we recommend changing the password authentication mode to a more secure key authentication mode. To do this, uncomment the corresponding line and make sure the value is "Yes", as shown in the screenshot. Authentication Key should be Enabled Now, let's prohibit logging on to the server as a superuser by changing the corresponding line as shown in the picture below. Don't Forget to Close Access to Root Login There are other settings you can configure to increase the server security:  UseDNS checks if the hostname matches its IP address. The value "Yes" enables this parameter. PermitEmptyPasswords prohibits using empty passwords for authentication if the value is "No." MaxAuthTries limits the number of unsuccessful attempts to connect to the server within one communication session.  AllowUsers and AllowGroups are responsible for the list of users and groups allowed to access the server: # AllowUsers User1, User2, User3# AllowGroups Group1, Group2, Group3 Login GraceTime sets the time provided for successful authorization. We recommend reducing the value of this parameter by four times. ClientAliveInterval limits the time of user inactivity. After exceeding the specified limit, the user is disconnected. After making all the changes in the main configuration file, save them and close the editor.  Restart the service to make the changes take effect: sudo systemctl restart ssh If you have changed the port in the configuration file, you should connect using the new port:  ssh -p port_number username@IP_address Or: ssh -p port_number_port_username@domain Troubleshooting Connection Issues Ensure the service is running with: sudo systemctl status ssh Restart it if necessary: sudo systemctl restart ssh Check firewall settings to allow traffic on port 22: sudo ufw allow 22 Confirm the system is reachable by running: ping <server-ip-address> Disabling the Service If you need to disable remote access for any reason, follow these steps: Stop the Service To temporarily stop accepting connections: sudo systemctl stop ssh Prevent Automatic Startup To disable it from starting on reboot: sudo systemctl disable ssh Confirm Inactive Status Verify that the service is no longer running: sudo systemctl status ssh Uninstall the Server If the service is no longer needed, remove it and its associated configuration files: sudo apt remove openssh-server Conclusion This article presents a step-by-step guide on installing and configuring SSH in Ubuntu 22.04 and describes how to edit the main configuration file to improve security. We hope this guide helps you to set up a secure remote connection to your Ubuntu server.To see more about SSH keys click here.
21 August 2025 · 7 min to read
PHP

How to Install PHP and PHP-FPM on Ubuntu 24.04

We are going to show you how to install PHP and PHP-FPM on Ubuntu 24.04. PHP, or Hypertext Preprocessor, is a popular open-source programming language used mostly for online development. The only PHP implementation of PHP FastCGI that is really helpful for websites with a lot of traffic is PHP. At the end of this guide, you should be ready to go with PHP running on your server.  Before that, check our instruction on how to set up a server on Ubuntu. PHP working scheme Prerequisites Before we start, please confirm you have the following: Ubuntu 24.04 LTS installed on the server A user account with the sudo access An essential command-line operation understanding A reliable internet connection for downloading software packages To ensure that your system is up to date, run the following commands: sudo apt updatesudo apt upgrade Install Apache Launch the Apache web server using the following command: sudo apt install apache2 Install PHP Let's begin with installing the PHP package in Ubuntu 24.04 server. First, open a terminal on your Ubuntu system. PHP and common modules are included in the installation action: sudo apt install php That command installs the core PHP package, the command-line interface, and common libraries. Make sure the installation works: php -v Start with PHP Installation Install PHP Extensions PHP extensions are the way to go to extending PHP installation with certain functions. Start by installing extensions: sudo apt install php-curl php-mbstring php-xml Short description: php-mysql: Allows MySQL database connection php-gd: Adds ability to manipulate images php-curl: Makes possible to communicate with servers php-mbstring: Provides multibyte string support php-xml: Enables XML support php-zip: Enables ZIP support Additional extensions can be installed as you see fit for your projects. You can search them using: apt-cache search php- Install and Configure PHP-FPM PHP-FPM is essential when dealing with high-traffic websites. To install and configure it: Install the package: sudo apt install php-fpm Launch PHP-FPM service. Depending on the installation, version number may differ. sudo systemctl start php8.3-fpm Tell PHP-FPM to go on boot: sudo systemctl enable php8.3-fpm Verify PHP-FPM is working: systemctl status php8.3-fpm This will output a response that says "Active (Running)" if everything is working as expected. Test PHP and PHP-FPM To ensure that PHP and PHP-FPM are both running with no problems, create a test file then serve it via the website's server. Let's say it uses Apache in this example: Generate PHP Info File. To show PHP settings using the phpinfo() function, do the following: mkdir -p /var/www/htmlecho "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php Set Up Apache for PHP-FPM. Ensure Apache is made compatible for PHP-FPM, by first finding Apache configuration file (usually /etc/apache2/sites-available/000-default.conf) then inserting: <FilesMatch \.php$>   SetHandler "proxy:unix:/var/run/php/php8.3-fpm.sock|fcgi://localhost/"</FilesMatch> Remember we must alter specific PHP version and socket path to suit individual settings of the server. Activate PHP and PHP-FPM. Enable PHP and PHP-FPM following these instructions: sudo apt install libapache2-mod-phpsudo a2enmod proxy_fcgi setenvif Reboot Apache. Apply changes by restarting Apache server: sudo systemctl restart apache2 Access PHP Info Page. First open your web browser and go to: http://your_server_ip/info.php Replace [server_ip] with the server IP address or domain. You can see details of your PHP installation. This is Where You Can Check Your PHP Current Status Install Multiple PHP Versions You may need to run different programs for specific projects, and each one may need a distinct set of features. Here's how to handle and work with different PHP versions on Ubuntu 24.04. First, add PHP repository: sudo apt install software-properties-commonsudo add-apt-repository ppa:ondrej/php && sudo apt update Install PHP versions you need: sudo apt install php8.1 php8.1-fpm Deselect one PHP version and select the other: sudo update-alternatives --set php /usr/bin/php8.1 If you are using multiple PHP versions, ensure that your web server is pointing to the appropriate PHP-FPM socket. Securing PHP and PHP-FPM: Best Practices As a web developer, you are aware of how crucial it is to use both PHP and PHP-FPM in secure and reliable web applications. We'll go over some security measures in this part that you should use when utilizing PHP and PHP-FPM. 1. Keep PHP and PHP-FPM Updated PHP and PHP-FPM should be up to date. Doing regular updates will eliminate known security breaches and provide overall security improvements. You need to check for updates as often as possible then update the system as soon as the updates are available. 2. Configure PHP Securely To configure PHP securely, start by disabling unnecessary and potentially dangerous functions, such as exec, shell_exec, and eval, in the PHP configuration file (php.ini). Use open_basedir directive to restrict PHP’s access to specific directories, preventing unauthorized access to sensitive files. Set display_errors to Off in production to avoid exposing error messages that could provide insights to attackers. Limit file upload sizes and execution times to reduce the risk of resource exhaustion attacks. Besides, ensure that PHP runs under a dedicated, restricted user account with minimal permissions to prevent privilege escalation. Regularly update PHP to the latest stable version to patch vulnerabilities and improve security. 3. Use Safe Error Reporting To ensure an error-free application, it is quite handy locating and correcting code bugs in a development environment. In production environment, you have the possibility to hide the PHP errors by setting the display_errors directive to be off, and you should also set the log_errors directive to be On, thus this will help you prevent PHP from showing errors to the users whereas your server will log it in a safe location without problems to users. 4. Implement Input Validation Being aware of the input validations is quite crucial during the programming of your software. Make sure that all deficiencies are tested and only SQL statements containing their SQL equivalent that can produce outwardly neutral queries via prepared statements is considered safe. 5. Secure PHP-FPM Configuration PHP-FPM is required to run using a non-usual user account with minium rights. Furthermore, access to the PHP-FPM socket or port should be very limited to the web application. 6. Enable open_basedir You need to bind open_basedir directive in order to restrict access files within the given directory. In this case, if you attempt to visit a forbidden directory and the request is accidentally transmitted to the server, PHP will prevent you from doing so. 7. Use HTTPS We need to secure web calls by making apps HTTPS-only, which is the only prominent way to block all the known hacking tricks. Installing PHP on Ubuntu 24.04 is Rewarded Conclusion With this guide, you've successfully set up PHP and PHP-FPM on Ubuntu 24.04. Your server is now configured for dynamic web applications. To maintain security and performance, remember to keep the system and packages regularly updated. If you liked this instruction, please check our Cloud Servers to boost your cloud workflow!
21 August 2025 · 6 min to read

Do you have questions,
comments, or concerns?

Our professionals are available to assist you at any moment,
whether you need help or are just unsure of where to start.
Email us
Hostman's Support