Home // How to install PHP 8.1 on RHEL based systems

How to install PHP 8.1 on RHEL based systems

0 49 minutes read
| Published on: August 23, 2023 | Last updated on: May 20, 2024

Installing PHP 8.1 on Red Hat Enterprise Linux (RHEL) gives you access to the latest features of this popular web development language. This guide provides an easy step-by-step process for installing PHP 8.1 on RHEL-based systems, ensuring a smooth and efficient setup for your web applications.

Why Install PHP 8.1 on RHEL?

PHP is an open-source server-side scripting language used to create dynamic, interactive web pages and apps. Major sites like Facebook and Wikipedia leverage PHP’s capabilities. Upgrading to PHP 8.1, released in November 2021, introduces useful new capabilities that can streamline your web development workflow:

  • Enums for type-safe values: Enums provide a way to define sets of named constants, improving code readability and type safety.
  • Read-only properties for immutability: By declaring properties as read-only, you can ensure data integrity and prevent unintended modifications.
  • Fibers for simpler async programming: Fibers simplify the development of asynchronous applications, enabling more efficient resource utilization.
  • First-class callable syntax and more: PHP 8.1 also introduces first-class callable syntax, which enhances the language’s functional programming capabilities, among other improvements.

Installing PHP 8.1 on RHEL allows you to leverage these features for faster, more robust, and more maintainable web development projects.

Prerequisites for Installing PHP 8.1 on RHEL

Before installing PHP 8.1, ensure your RHEL-based system meets the following prerequisites:

  • Running CentOS, Fedora, or RHEL
  • Root or sudo access
  • Stable internet connection
  • Backed up critical data

Meeting these prerequisites ensures a smooth PHP 8.1 installation process and minimizes potential issues.

Step-by-Step Guide to Install PHP 8.1 on RHEL

Follow these key steps to install PHP 8.1 on your RHEL system:

1. Update System Packages

Use either DNF or YUM to update packages:

Bash
sudo dnf update -y

or

Bash
sudo yum update -y

This step ensures you have the latest system updates before installing PHP, reducing the risk of compatibility issues.

2. Enable Remi Repository

Remi’s repository provides the latest PHP versions. Enable it with:

Bash
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y

or

Bash
sudo yum install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y

This gives you access to PHP 8.1 for installation.

3. Install PHP 8.1

Install PHP 8.1 using the DNF or YUM module commands:

Bash
sudo dnf module reset php -y
sudo dnf module enable php:remi-8.1 -y
sudo dnf install php -y

or

Bash
sudo yum module reset php -y
sudo yum module enable php:remi-8.1 -y
sudo yum install php -y

4. Verify PHP 8.1 Installation

Check the installed version with:

Bash
php -v

This should display PHP 8.1, indicating a successful installation.

Optimizing PHP 8.1 Performance on RHEL

After installing PHP 8.1 on your RHEL system, proper configuration is key to maximizing performance and security. This section covers optimizing PHP settings, installing extensions, troubleshooting issues, and best practices.

Configure php.ini for PHP 8.1

The php.ini file, located in /etc, controls PHP settings and behavior. Tune php.ini directives based on your app’s needs:

  • Memory Usage: For memory-intensive apps, increase limits:
PHP
  memory_limit = 256M

Set higher for CMS or e-commerce sites. Lower for lean APIs.

  • File Size Limits: Allow larger file uploads by adjusting size limits:
PHP
  upload_max_filesize = 64M
  post_max_size = 128M

Increase as needed for your use case.

  • Error Handling: Improve debugging with verbose error reporting:
PHP
  display_errors = On
  error_reporting = E_ALL

Disable in production for security.

  • Request Timeouts: Avoid app timeouts by setting an appropriate limit:
PHP
  max_execution_time = 60

Adjust higher or lower as necessary.

There are many other php.ini directives to optimize for performance, security, and your specific application requirements.

Install PHP Extensions on RHEL

Extensions add functionality like databases, image handling, PDFs, and more. Use DNF or YUM to install. For example:

Bash
sudo dnf install php-gd php-curl php-zip

Some useful extensions:

  • php-gd: Image manipulation with the GD library
  • php-curl: Make HTTP requests with cURL
  • php-bcmath: Arithmetic with arbitrary precision

Only enable required extensions. Too many can impact performance.

Troubleshoot Issues

Fix common PHP installation problems:

  • Missing Dependencies: Install the EPEL repository if needed packages are missing:
Bash
  sudo dnf install epel-release
  • Error Logs: Carefully read through full error messages and check log files such as the web server error log or PHP error log for more details.
  • Online Resources: Search online for the specific error message, PHP version, and OS combination for solutions. Post details on forums or sites like Stack Overflow for help if unable to resolve.

Conclusion

Optimally configuring PHP 8.1 allows you to utilize the full potential of the latest PHP on your RHEL environment. Adjust settings to match your application needs, enable required extensions, and troubleshoot issues for maximum performance and stability. Proper PHP configuration is key for production-ready deployments.

Frequently Asked Questions

What should I do if I encounter errors not covered in this guide?

Carefully read through the full error message and try to identify the cause. Errors often provide clues about the issue. Check log files such as the web server error log or PHP error log for more details. Search online for the specific error message, PHP version, and OS combination for solutions. Try simplifying the PHP code or configuration to isolate the problem. Post details on forums or sites like Stack Overflow for help if unable to resolve.

Is it possible to install multiple PHP versions on a single server?

Yes, you can install multiple PHP versions on the same server using techniques like:

  • The Ondřej Surý PPA for Ubuntu provides multiple PHP packages that can be installed in parallel.
  • Software collections like SCL allow installing newer PHP builds alongside the system PHP.
  • Compiling PHP from source with --prefix set allows side-by-side versions.
  • Using virtual environments with Docker or Vagrant can isolate different PHP environments.

However, running multiple versions adds complexity, so plan the architecture carefully.

How can I update PHP to a newer version?

If using default OS packages, update through the package manager once the new version is available in the repositories. For manual source installs, you’ll need to recompile PHP from source. Best practice is to install the new version in parallel and gradually migrate apps over. If installed via PPA, it provides seamless updates to new PHP point releases. Major version updates may need PPA changes.

What other system configurations should I consider after installing PHP?

Some configurations to consider for optimizing PHP:

  • Tune OPcache settings for faster performance.
  • Adjust open file/process limits for high-traffic sites.
  • Enable APCu for local caching if using legacy PHP versions.
  • Configure proper logging and log rotation.
  • Secure the installation by following best practices.
  • Monitor key metrics like memory usage and traffic.

Why is data backup essential before installing PHP?

Backups provide the ability to restore the system if issues arise during installation. Specific scenarios where backups help:

  • Rolling back if the PHP upgrade causes compatibility issues.
  • Recovering from accidental deletion or corruption of files.
  • Comparing configs to assist in migration to a new PHP version.
  • Diagnosing the cause if the new PHP installation introduces problems.
  • Quickly restoring the system if OS or hardware failure occurs.

Having reliable backups before major upgrades like PHP installations is highly recommended.

IF YOU ARE HAVING PROBLEMS WITH THIS GUIDE, EMAIL US AT:

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

Copyright @2022-2024 All Right Reserved – PCPlanet

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. You understand and give your consent that your IP address and browser information might be processed by the security plugins installed on this site. By clicking “Accept”, you consent to the use of ALL the cookies.
.
Accept Read More

Privacy & Cookies Policy