Red hat enterprise linux php

Chapter 41. Using the PHP scripting language

Hypertext Preprocessor (PHP) is a general-purpose scripting language mainly used for server-side scripting, which enables you to run the PHP code using a web server.

In RHEL 8, the PHP scripting language is provided by the php module, which is available in multiple streams (versions).

Depending on your use case, you can install a specific profile of the selected module stream:

  • common — The default profile for server-side scripting using a web server. It includes several widely used extensions.
  • minimal — This profile installs only the command-line interface for scripting with PHP without using a web server.
  • devel — This profile includes packages from the common profile and additional packages for development purposes.

41.1. Installing the PHP scripting language

This section describes how to install a selected version of the php module.

    To install a php module stream with the default profile, use:

# yum module install php:stream
# yum module install php:stream/profile

Replace stream with the desired version and profile with the name of the profile you wish to install. For example, to install PHP 8.0 for use without a web server:

# yum module install php:8.0/minimal

Additional resources

  • If you want to upgrade from an earlier version of PHP available in RHEL 8, see Switching to a later stream.
  • For more information about managing RHEL 8 modules and streams, see Installing, managing, and removing user-space components.

41.2. Using the PHP scripting language with a web server

41.2.1. Using PHP with the Apache HTTP Server

In Red Hat Enterprise Linux 8, the Apache HTTP Server enables you to run PHP as a FastCGI process server. FastCGI Process Manager (FPM) is an alternative PHP FastCGI daemon that allows a website to manage high loads. PHP uses FastCGI Process Manager by default in RHEL 8.

This section describes how to run the PHP code using the FastCGI process server.

Prerequisites

# yum module install httpd:2.4

Or, if the Apache HTTP Server is already running on your system, restart the httpd service after installing PHP:

# systemctl enable php-fpm httpd
echo '' > /var/www/html/index.php
  • /etc/httpd/conf/httpd.conf — generic httpd configuration
  • /etc/httpd/conf.d/php.conf — PHP-specific configuration for httpd
  • /usr/lib/systemd/system/httpd.service.d/php-fpm.conf — by default, the php-fpm service is started with httpd
  • /etc/php-fpm.conf — FPM main configuration
  • /etc/php-fpm.d/www.conf — default www pool configuration
Читайте также:  Process tree on linux

Example 41.1. Running a «Hello, World!» PHP script using the Apache HTTP Server

Additional resources

41.2.2. Using PHP with the nginx web server

This section describes how to run PHP code through the nginx web server.

Prerequisites

    Install an nginx module stream:

# yum module install nginx:stream

Replace stream with the version of nginx you wish to install. For example, to install nginx version 1.18:

# yum module install nginx:1.18

Or, if the nginx server is already running on your system, restart the nginx service after installing PHP:

# systemctl enable php-fpm nginx
echo '' > /usr/share/nginx/html/index.php
  • /etc/nginx/nginx.conf — nginx main configuration
  • /etc/nginx/conf.d/php-fpm.conf — FPM configuration for nginx
  • /etc/php-fpm.conf — FPM main configuration
  • /etc/php-fpm.d/www.conf — default www pool configuration

Example 41.2. Running a «Hello, World!» PHP script using the nginx server

Additional resources

41.3. Running a PHP script using the command-line interface

A PHP script is usually run using a web server, but also can be run using the command-line interface.

If you want to run php scripts using only command-line, install the minimal profile of a php module stream.

Prerequisites

  1. In a text editor, create a filename .php file Replace filename with the name of your file.
  2. Execute the created filename .php file from the command line:

Example 41.3. Running a «Hello, World!» PHP script using the command-line interface

41.4. Additional resources

  • httpd(8) — The manual page for the httpd service containing the complete list of its command-line options.
  • httpd.conf(5) — The manual page for httpd configuration, describing the structure and location of the httpd configuration files.
  • nginx(8) — The manual page for the nginx web server containing the complete list of its command-line options and list of signals.
  • php-fpm(8) — The manual page for PHP FPM describing the complete list of its command-line options and configuration files.

Источник

How to Install PHP 8 on CentOS/RHEL 8/7

PHP is a popular open-source server-side scripting language that is integral in developing dynamic web pages. PHP 8.0 is finally out and was released on November 26th, 2020. It promises lots of improvements and optimizations which are set to streamline how developers write and interact with PHP code.

In this guide, you will learn how to install PHP 8.0 on CentOS 8/7 and RHEL 8/7.

Step 1: Enable EPEL and Remi Repository on CentOS/RHEL

Right off the bat, you need to enable the EPEL repository on your system. EPEL, short for Extra Packages for Enterprise Linux, is an effort from the Fedora team that provides a set of additional packages that are not present by default on RHEL & CentOS.

$ sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm [On CentOS/RHEL 8] $ sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm [On CentOS/RHEL 7]

Remi repository is a third-party repository that provides a wide range of PHP versions for RedHat Enterprise Linux. To install the Remi repository, run the command:

$ sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm [On CentOS/RHEL 8] $ sudo yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm [On CentOS/RHEL 7]

Step 2: Install PHP 8 on CentOS/RHEL

Once the installation is complete, proceed and list the available php module streams as shown:

$ sudo dnf module list php [On RHEL 8]

Right at the bottom, be sure to notice the remi-8.0 php module.

List PHP 8 Modules

We need to enable this module before installing PHP 8.0. To enable php:remi-8.0, execute:

$ sudo dnf module enable php:remi-8.0 -y [On RHEL 8]

Enable PHP Remi Module

On CentOS 7, use the following commands.

$ sudo yum -y install yum-utils $ sudo yum-config-manager --disable 'remi-php*' $ sudo yum-config-manager --enable remi-php80

Once enabled, install PHP 8.0 for Apache or Nginx web server as shown:

Install PHP 8.0 for Apache

To install PHP 8 on the installed Apache web server, run:

$ sudo dnf install php php-cli php-common

Install PHP 8 for Apache

Install PHP 8.0 for Nginx

If you are using Nginx in your development stack, consider installing php-fpm as shown.

$ sudo dnf install php php-cli php-common php-fpm

Step 3: Verify PHP 8.0 on CentOS/RHEL

There are two ways that you can use to verify the PHP version. On command-line, issue the command.

Verify PHP 8 from Command-line

Additionally, you can create a sample php file in the /var/www/html folder as shown:

$ sudo vim /var/www/html/info.php

Then add the following PHP code which will populate the version of PHP alongside installed modules.

Save and exit. Be sure to restart the Apache or Nginx web server as shown.

$ sudo systemctl restart httpd $ sudo systemctl restart nginx

Next, head over to your browser and go to the address shown:

The webpage displays a wealth of information regarding the version of PHP installed such as build date, build system, Architecture, and a host of PHP extensions.

Check PHP 8 Info

Step 3: Install PHP 8.0 Extensions in CentOS/RHEL

PHP extensions are libraries that provide added functionality to PHP. To install a php extension, use the syntax:

For example, to enable PHP to seamlessly work with MySQL, you can install the MySQL extension as shown.

$ sudo yum install php-mysqlnd

Finally, you can verify the installed extensions using the command:

To verify if a specific extension is installed, execute:

$ php -m | grep extension-name

Verify PHP Extension

In the end, we hope that you can now comfortably install PHP 8.0 alongside various php extensions on CentOS/RHEL 8/7.

Источник

How to Install Latest PHP 8.1 on RHEL Linux

If you are an RHEL 8.5 user and a PHP enthusiast, this article guide is the right fit for you. PHP is a globally-renowned scripting language that has helped developers and users come up with impressive web-based applications.

If you are a current user of older PHP versions like 7.2/7.4 or just need a fresh install of PHP 8 on your RHEL 8.5 system, this article is the perfect reference point.

Since the current PHP version release is at 8.x, its many new features and optimizations include improved error handling, type system, & consistency, named JIT, match expression, attributes, arguments, nullsafe operator, constructor property promotion, and union types.

Other improvements include saner string to number comparison, consistent type errors for internal functions, just-in-time compilation, syntax tweaks, system, and error handling improvements.

Installing PHP 8 on RHEL Linux

The main prerequisite for this article is to ensure you are a root/sudoer user on the RHEL system you are using.

To determine the RHEL operating system version you are using, execute the following command on your terminal/command line:

$ cat /etc/redhat-release Red Hat Enterprise Linux release 8.5 (Ootpa) 

Your RHEL system needs to be up-to-date for it to be performant and get rid of security vulnerabilities like bugs through patch fixes and application upgrades.

Next, you need to enable EPEL and Remi repositories, which are responsible for creating, maintaining, and managing high-quality Enterprise Linux packages.

$ sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm -y

The Remi repository on the other hand will be useful in providing the PHP 8.x version you will install on your RHEL system. This repo hugely contributes to meeting the objectives/requirements of a LAMP/LEMP stack.

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

Your RHEL system is now ready to install and explore what PHP 8.x has to offer. To preview the PHP modules available for your RHEL system, execute the following command:

List PHP Modules

As you can see, the above command has revealed several PHP versions ranging from version 7.2 to 8.1 as per Remi’s Modular repository for Enterprise Linux 8 – x86_64.

If you are already using an older PHP version like 7.2, 7.3, or 7.4 and wish to upgrade to 8.0 or 8.1, the best course of action is to reset PHP to that preferred version.

$ sudo dnf module reset php

Reset PHP Yum Module

Afterward, you can now enable the PHP module you wish to install (8.0 or 8.1) from the Remi repository using the following command:

$ sudo dnf module enable php:remi-8.1

Enable PHP Yum Module

Next, the PHP install command should now showcase PHP 8.1 as the preferred installation package.

Install PHP in RHEL

After the installation process completes, confirm the PHP version you just installed.

Check PHP Version

If you wish to install other php modules like fpm, common, mysqlnd, etc., the command structure to use should look like the following:

Install PHP Modules in RHEL

This article has shown us to install/upgrade to PHP 8.x on an RHEL 8.5 system. You can now comfortably kick off or continue your LAMP/LEMP projects.

Источник

Оцените статью
Adblock
detector