
PHP (Hypertext Preprocessor) is an open-source server-side scripting language that enables the development of dynamic web applications.PHP-FPM (FastCGI Process Manager) is an implementation of PHP FastCGI that enables processing of PHP requests using pools configurations with optimized performance and faster response times.
This article explains how to install PHP and PHP-FPM on Rocky Linux 9, configure the default pool to enable integrations with other applications such as web servers and run sample dynamic web applications.
Before you begin:
PHP is available in the default repositories on Rocky Linux 9 with the latest version information. Follow the steps below to install PHP and PHP-FPM using the default DNF package manager on your server.
Update the server packages index.
Install PHP.
View the installed PHP on your server.
Output:
View the installed PHP-FPM version and verify that it matches your PHP version.
Output:
PHP extensions enable additional functionalities and integration of dynamic features required by modern web applications. Follow the steps below to install common PHP extensions required by most web applications.
Install common PHP extensions.
The above command installs the following PHP extensions:
View the installed PHP modules on your server.
Output:
PHP-FPM is available and included in the PHP package during installation. PHP-FPM acts as a gateway to the PHP processes and handles multiple PHP requests depending on your pool configurations. Follow the steps below to configure the default PHP-FPM pool to process requests depending on your server performance.
Switch to the PHP-FPM configuration files directory.
Open the default PHP-FPM pool configuration www.conf.
www.apache to nginx when using the Nginx web server and vice versa.listen directive and verify the PHP-FPM UNIX socket path to use when connecting to the pool.pm.max_children directive and set the value depending on your available server memory. A higher value enables processing of multiple workers while a lower value may enforce queueing.pm.max_requests directive to set the number of processes each child process can run before it's terminated.Save and close the file.
Enable the PHP-FPM service to start automatically start at boot time.
Start the PHP-FPM service.
View the PHP-FPM service status and verify that it's running.
Output:
PHP includes a default web server package that lets you run applications by specifying a specific listen address. Follow the steps below to set up a sample PHP application and use the built-in PHP web server utility to run the application.
Create a new directory to store your PHP application files. For example, /var/www/php-test.
Create a new sample PHP application file info.php.
Add the following contents to the file.
Save and close the file.
The above application code displays full information about your PHP installation including the version, and installed modules on the server.
Run the application directory using the built-in PHP web server utility on the HTTP port 80.
Output:
Allow connections to the HTTP port 80 through the default firewalld utility.
Reload the firewall configuration to apply changes.
Access your server IP using a web browser such as Chrome and load the /info.php path to access your PHP application.
Running multiple PHP projects requires specific package versions depending on your deployment environment. You can run multiple PHP versions on your server that include specific features or functionalities available in a specific PHP version required by your application. Follow the steps below to install the phpbrew utility and manage multiple PHP versions on your server.
Update your server's package index.
Install the EPEL repository on your server.s
Enable the CRB (CodeReady Builder) repository.
Install all required dependencies packages.
Download the latest phpbrew binary file to install on your server.
Enable execution privileges on the file.
Move the binary file to the /usr/local/bin directory to enable phpbrew as a system-wide command.
View the installed phpbrew version to verify access to the utility.
Output:
Initialize phpbrew to work in your user environment.
Output:
Run the following command to add your local phpbrew directory to the .bashrc file and enable your configurations to work in multiple terminal sessions. Replace exampleuser with your actual user.
Reload the .bashrc file to apply changes.
Install one or more PHP versions on your server. For example:
+default and +mysql extensions.+default and +mysql extensions.+default and +mysql extensions.View all installed versions on your server.
Output:
View the active PHP version on your server.
Output:
Switch to a specific PHP version available on your phpbrew list.
View the active PHP version in your user environment.
Output:
Based on the above output, the PHP version 8.3.8 is active in your user's environment. When using multiple PHP versions on your server, ensure to create independent PHP-FPM pools to define specific resource limits for each PHP version depending on your project requirements.
You have installed PHP and PHP-FPM on your Rocky Linux 9 server to efficiently process dynamic web applications. In addition, you installed common PHP extensions to enable additional application functionalities and switched between multiple versions to match your project needs. For more information and PHP-FPM configuration options, visit the official PHP documentation.
0 Comments
Be the first to comment and share your perspective with the community.