Chapter 16. Installing and using dynamic programming languages
Red Hat provides different programming languages, such as Python, PHP, and Tcl/TK. Use them to develop own applications and services.
16.1. Introduction to Python Copiar enlaceEnlace copiado en el portapapeles!
Python is a high-level programming language that supports multiple programming paradigms, such as object-oriented, imperative, functional, and procedural paradigms. Python has dynamic semantics and can be used for general-purpose programming.
With Red Hat Enterprise Linux, many packages that are installed on the system, such as packages providing system tools, tools for data analysis, or web applications, are written in Python. To use these packages, you must have the python* packages installed.
16.1.1. Python versions Copiar enlaceEnlace copiado en el portapapeles!
Two incompatible versions of Python are widely used, Python 2.x and Python 3.x. RHEL 8 provides the following versions of Python.
| Version | Package to install | Command examples | Available since | Life cycle |
|---|---|---|---|---|
| Python 3.6 |
|
| RHEL 8.0 | full RHEL 8 |
| Python 2.7 |
|
| RHEL 8.0 | shorter |
| Python 3.8 |
|
| RHEL 8.2 | shorter |
| Python 3.9 |
|
| RHEL 8.4 | shorter |
| Python 3.11 |
|
| RHEL 8.8 | shorter |
| Python 3.12 |
|
| RHEL 8.10 | shorter |
For details about the length of support, see Red Hat Enterprise Linux Life Cycle and Red Hat Enterprise Linux Application Streams Life Cycle.
Each of the Python versions up to 3.9 is distributed in a separate module. Python 3.11 and Python 3.12 are distributed as suites of non-modular RPM packages, including the python3.11 and python3.12 packages.
You can install multiple Python versions in parallel on the same RHEL 8 system.
Always specify the version of Python when installing it, invoking it, or otherwise interacting with it. For example, use python3 instead of python in package and command names. All Python-related commands must also include the version, for example, pip3, pip2, pip3.8, pip3.9, pip3.11, or pip3.12.
The unversioned python command (/usr/bin/python) is not available by default in RHEL 8. You can configure it using the alternatives command; for instructions, see Configuring the unversioned Python
Any manual changes to /usr/bin/python, except changes made using the alternatives command, might be overwritten upon an update.
As a system administrator, use Python 3 for the following reasons:
- Python 3 represents the main development direction of the Python project.
- Support for Python 2 in the upstream community ended in 2020.
- Popular Python libraries are discontinuing Python 2 support in upstream.
-
Python 2 in Red Hat Enterprise Linux 8 will have a shorter life cycle and aims to facilitate a smoother transition to
Python 3for customers.
For developers, Python 3 has the following advantages over Python 2:
- Python 3 enables you to write expressive, maintainable, and correct code more easily.
- Code written in Python 3 will have greater longevity.
-
Python 3 has new features, including
asyncio, f-strings, advanced unpacking, keyword-only arguments, and chained exceptions.
However, legacy software might require /usr/bin/python to be configured to Python 2. For this reason, no default python package is distributed with Red Hat Enterprise Linux 8, and you can choose between using Python 2 and 3 as /usr/bin/python, as described in Configuring the unversioned Python.
System tools in Red Hat Enterprise Linux 8 use Python version 3.6 provided by the internal platform-python package, which is not intended to be used directly by customers. It is recommended to use the python3 or python3.6 command from the python36 package for Python 3.6, or to use later Python versions.
Do not remove the platform-python package from RHEL 8 because other packages require it.
16.1.2. Notable differences between Python versions Copiar enlaceEnlace copiado en el portapapeles!
Python versions included in RHEL 8 differ in various aspects.
Python bindings
The python38 and python39 modules and the python3.11 and python3.12 package suites do not include the same bindings to system tools (RPM, DNF, SELinux, and others) that are provided for the python36 module. Therefore, use python36 in instances where the greatest compatibility with the base operating system or binary compatibility is necessary. In unique instances where system bindings are necessary together with later versions of various Python modules, use the python36 module in combination with third-party upstream Python modules installed through pip into Python’s venv or virtualenv environments.
Python 3.11 and Python 3.12 virtual environments must be created using venv instead of virtualenv
The virtualenv utility in RHEL 8, provided by the python3-virtualenv package, is not compatible with Python 3.11 and Python 3.12. An attempt to create a virtual environment by using virtualenv will fail with an error message, for example:
virtualenv -p python3.11 venv3.11
$ virtualenv -p python3.11 venv3.11
Running virtualenv with interpreter /usr/bin/python3.11
ERROR: Virtual environments created by virtualenv < 20 are not compatible with Python 3.11.
ERROR: Use python3.11 -m venv instead.
To create Python 3.11 or Python 3.12 virtual environments, use the python3.11 -m venv or python3.12 -m venv commands instead, which use the venv module from the standard library.
16.2. Installing and using Python Copiar enlaceEnlace copiado en el portapapeles!
In Red Hat Enterprise Linux 8, Python 3 is distributed in versions 3.6, 3.8, and 3.9, provided by the python36, python38, and python39 modules, and the python3.11 and python3.12 package suites in the AppStream repository.
Using the unversioned python command to install or run Python does not work by default due to ambiguity. Always specify the version of Python, or configure the system default version by using the alternatives command.
16.2.1. Installing Python 3 Copiar enlaceEnlace copiado en el portapapeles!
By design, you can install RHEL 8 modules in parallel, including the python27, python36, python38, and python39 modules, and the python3.11 and python3.12 package suites.
You can install Python 3.8, Python 3.9, Python 3.11, and Python 3.12, including packages built for each version, in parallel with Python 3.6 on the same system, with the exception of the mod_wsgi module. Due to a limitation of the Apache HTTP Server, only one of the python3-mod_wsgi, python38-mod_wsgi, python39-mod_wsgi, python3.11-mod_wsgi, or python3.12-mod_wsgi packages can be installed on a system.
Procedure
To install Python 3.6 from the
python36module, use:yum install python3
# yum install python3Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
python36:3.6module stream is enabled automatically.To install Python 3.8 from the
python38module, use:yum install python38
# yum install python38Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
python38:3.8module stream is enabled automatically.To install Python 3.9 from the
python39module, use:yum install python39
# yum install python39Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
python39:3.9module stream is enabled automatically.To install Python 3.11 from the
python3.11RPM package, use:yum install python3.11
# yum install python3.11Copy to Clipboard Copied! Toggle word wrap Toggle overflow To install Python 3.12 from the
python3.12RPM package, use:yum install python3.12
# yum install python3.12Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
To verify the Python version installed on your system, use the
--versionoption with thepythoncommand specific for your required version of Python.For Python 3.6:
python3 --version
$ python3 --versionCopy to Clipboard Copied! Toggle word wrap Toggle overflow For Python 3.8:
python3.8 --version
$ python3.8 --versionCopy to Clipboard Copied! Toggle word wrap Toggle overflow For Python 3.9:
python3.9 --version
$ python3.9 --versionCopy to Clipboard Copied! Toggle word wrap Toggle overflow For Python 3.11:
python3.11 --version
$ python3.11 --versionCopy to Clipboard Copied! Toggle word wrap Toggle overflow For Python 3.12:
python3.12 --version
$ python3.12 --versionCopy to Clipboard Copied! Toggle word wrap Toggle overflow
16.2.2. Installing additional Python 3 packages Copiar enlaceEnlace copiado en el portapapeles!
Packages with add-on modules for Python 3.6 generally use the python3- prefix, packages for Python 3.8 include the python38- prefix, packages for Python 3.9 include the python39- prefix, packages for Python 3.11 include the python3.11- prefix, and packages for Python 3.12 include the python3.12- prefix. Always include the prefix when installing additional Python packages, as shown in the examples below.
Procedure
To install the
Requestsmodule for Python 3.6, use:yum install python3-requests
# yum install python3-requestsCopy to Clipboard Copied! Toggle word wrap Toggle overflow To install the
Cythonextension to Python 3.8, use:yum install python38-Cython
# yum install python38-CythonCopy to Clipboard Copied! Toggle word wrap Toggle overflow To install the
pippackage installer from Python 3.9, use:yum install python39-pip
# yum install python39-pipCopy to Clipboard Copied! Toggle word wrap Toggle overflow To install the
pippackage installer from Python 3.11, use:yum install python3.11-pip
# yum install python3.11-pipCopy to Clipboard Copied! Toggle word wrap Toggle overflow To install the
pippackage installer from Python 3.12, use:yum install python3.12-pip
# yum install python3.12-pipCopy to Clipboard Copied! Toggle word wrap Toggle overflow
16.2.3. Installing additional Python 3 tools for developers Copiar enlaceEnlace copiado en el portapapeles!
Additional Python tools for developers are distributed mostly through the CodeReady Linux Builder (CRB) repository in the respective python38-devel or python39-devel module, or the python3.11-* or python3.12-* packages.
The python3-pytest package (for Python 3.6) and its dependencies are available in the AppStream repository.
The CRB repository provides:
-
The
python38-develmodule, which contains thepython38-pytestpackage and its dependencies. -
The
python39-develmodule, which contains thepython39-pytestpackage and its dependencies, and thepython39-debugandpython39-Cythonpackages. The
python3.11-*packages, which include:-
python3.11-pytestand its dependencies -
python3.11-idle -
python3.11-debug -
python3.11-Cython
-
-
The
python3.12-*packages, which include a similar set of packages aspython3.11-*.
The content in the CodeReady Linux Builder repository is unsupported by Red Hat.
Not all upstream Python-related packages are available in RHEL.
To install the python3*-pytest package, use the following procedure.
Procedure
For Python 3.8 and later, enable the CodeReady Linux Builder repository:
subscription-manager repos --enable codeready-builder-for-rhel-8-x86_64-rpms
# subscription-manager repos --enable codeready-builder-for-rhel-8-x86_64-rpmsCopy to Clipboard Copied! Toggle word wrap Toggle overflow For Python 3.8 or 3.9, enable the respective
python3*-develmodule, for example:yum module enable python39-devel
# yum module enable python39-develCopy to Clipboard Copied! Toggle word wrap Toggle overflow Install the
python3*-pytestpackage:For Python 3.6:
yum install python3-pytest
# yum install python3-pytestCopy to Clipboard Copied! Toggle word wrap Toggle overflow For Python 3.8:
yum install python38-pytest
# yum install python38-pytestCopy to Clipboard Copied! Toggle word wrap Toggle overflow For Python 3.9:
yum install python39-pytest
# yum install python39-pytestCopy to Clipboard Copied! Toggle word wrap Toggle overflow For Python 3.11:
yum install python3.11-pytest
# yum install python3.11-pytestCopy to Clipboard Copied! Toggle word wrap Toggle overflow For Python 3.12:
yum install python3.12-pytest
# yum install python3.12-pytestCopy to Clipboard Copied! Toggle word wrap Toggle overflow
16.2.4. Installing Python 2 Copiar enlaceEnlace copiado en el portapapeles!
Some applications and scripts have not yet been fully ported to Python 3 and require Python 2 to run. Red Hat Enterprise Linux 8 allows parallel installation of Python 3 and Python 2. If you need the Python 2 functionality, install the python27 module, which is available in the AppStream repository.
Note that Python 3 is the main development direction of the Python project. Support for Python 2 is being phased out. The python27 module has a shorter support period than Red Hat Enterprise Linux 8.
Procedure
To install Python 2.7 from the
python27module, use:yum install python2
# yum install python2Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
python27:2.7module stream is enabled automatically.
Packages with add-on modules for Python 2 generally use the python2- prefix. Always include the prefix when installing additional Python packages, as shown in the examples below.
To install the
Requestsmodule for Python 2, use:yum install python2-requests
# yum install python2-requestsCopy to Clipboard Copied! Toggle word wrap Toggle overflow To install the
Cythonextension to Python 2, use:yum install python2-Cython
# yum install python2-CythonCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
To verify the Python version installed on your system, use:
python2 --version
$ python2 --versionCopy to Clipboard Copied! Toggle word wrap Toggle overflow
By design, you can install RHEL 8 modules in parallel, including the python27, python36, python38, and python39 modules.
16.2.5. Migrating from Python 2 to Python 3 Copiar enlaceEnlace copiado en el portapapeles!
As a developer, you may want to migrate your former code that is written in Python 2 to Python 3.
For more information about how to migrate large code bases to Python 3, see The Conservative Python 3 Porting Guide.
Note that after this migration, the original Python 2 code becomes interpretable by the Python 3 interpreter and stays interpretable for the Python 2 interpreter as well.
16.2.6. Using Python Copiar enlaceEnlace copiado en el portapapeles!
When running the Python interpreter or Python-related commands, always specify the version.
Prerequisites
- Ensure that the required version of Python is installed.
If you want to download and install third-party applications for Python 3.11 or Python 3.12, install the
python3.11-piporpython3.12-pippackage.WarningInstalling Python packages with
pipas the root user places files in system locations. This can override RHEL libraries and might cause system instability or conflicts with supported packages. Red Hat does not support software installed by usingpipat the system level. To avoid these issues, usepipwithin a virtual environment or install packages as a non-root user with the--useroption.
Procedure
To run the Python 3.6 interpreter or related commands, use, for example:
python3 python3 -m venv --help python3 -m pip install package pip3 install package
$ python3 $ python3 -m venv --help $ python3 -m pip install package $ pip3 install packageCopy to Clipboard Copied! Toggle word wrap Toggle overflow To run the Python 3.8 interpreter or related commands, use, for example:
python3.8 python3.8 -m venv --help python3.8 -m pip install package pip3.8 install package
$ python3.8 $ python3.8 -m venv --help $ python3.8 -m pip install package $ pip3.8 install packageCopy to Clipboard Copied! Toggle word wrap Toggle overflow To run the Python 3.9 interpreter or related commands, use, for example:
python3.9 python3.9 -m venv --help python3.9 -m pip install package pip3.9 install package
$ python3.9 $ python3.9 -m venv --help $ python3.9 -m pip install package $ pip3.9 install packageCopy to Clipboard Copied! Toggle word wrap Toggle overflow To run the Python 3.11 interpreter or related commands, use, for example:
python3.11 python3.11 -m venv --help python3.11 -m pip install package pip3.11 install package
$ python3.11 $ python3.11 -m venv --help $ python3.11 -m pip install package $ pip3.11 install packageCopy to Clipboard Copied! Toggle word wrap Toggle overflow To run the Python 3.12 interpreter or related commands, use, for example:
python3.12 python3.12 -m venv --help python3.12 -m pip install package pip3.12 install package
$ python3.12 $ python3.12 -m venv --help $ python3.12 -m pip install package $ pip3.12 install packageCopy to Clipboard Copied! Toggle word wrap Toggle overflow To run the Python 2 interpreter or related commands, use, for example:
python2 python2 -m pip install package pip2 install package
$ python2 $ python2 -m pip install package $ pip2 install packageCopy to Clipboard Copied! Toggle word wrap Toggle overflow
16.3. Configuring the unversioned Python Copiar enlaceEnlace copiado en el portapapeles!
System administrators can configure the unversioned python command, located at /usr/bin/python, using the alternatives command. Note that the required package, python3, python38, python39, python3.11, python3.12, or python2, must be installed before configuring the unversioned command to the respective version.
The /usr/bin/python executable is controlled by the alternatives system. Any manual changes may be overwritten upon an update.
Additional Python-related commands, such as pip3, do not have configurable unversioned variants.
16.3.1. Configuring the unversioned python command directly Copiar enlaceEnlace copiado en el portapapeles!
You can configure the unversioned python command directly to a selected version of Python.
Prerequisites
- Ensure that the required version of Python is installed.
Procedure
To configure the unversioned
pythoncommand to Python 3.6, use:alternatives --set python /usr/bin/python3
# alternatives --set python /usr/bin/python3Copy to Clipboard Copied! Toggle word wrap Toggle overflow To configure the unversioned
pythoncommand to Python 3.8, use:alternatives --set python /usr/bin/python3.8
# alternatives --set python /usr/bin/python3.8Copy to Clipboard Copied! Toggle word wrap Toggle overflow To configure the unversioned
pythoncommand to Python 3.9, use:alternatives --set python /usr/bin/python3.9
# alternatives --set python /usr/bin/python3.9Copy to Clipboard Copied! Toggle word wrap Toggle overflow To configure the unversioned
pythoncommand to Python 3.11, use:alternatives --set python /usr/bin/python3.11
# alternatives --set python /usr/bin/python3.11Copy to Clipboard Copied! Toggle word wrap Toggle overflow To configure the unversioned
pythoncommand to Python 3.12, use:alternatives --set python /usr/bin/python3.12
# alternatives --set python /usr/bin/python3.12Copy to Clipboard Copied! Toggle word wrap Toggle overflow To configure the unversioned
pythoncommand to Python 2, use:alternatives --set python /usr/bin/python2
# alternatives --set python /usr/bin/python2Copy to Clipboard Copied! Toggle word wrap Toggle overflow
16.3.2. Configuring the unversioned python command to the required Python version interactively Copiar enlaceEnlace copiado en el portapapeles!
You can configure the unversioned python command to the required Python version interactively.
Prerequisites
- Ensure that the required version of Python is installed.
Procedure
To configure the unversioned
pythoncommand interactively, use:alternatives --config python
# alternatives --config pythonCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Select the required version from the provided list.
To reset this configuration and remove the unversioned
pythoncommand, use:alternatives --auto python
# alternatives --auto pythonCopy to Clipboard Copied! Toggle word wrap Toggle overflow
16.4. Packaging Python 3 RPMs Copiar enlaceEnlace copiado en el portapapeles!
Most Python projects use Setuptools for packaging, and define package information in the setup.py file. For more information about Setuptools packaging, see the Setuptools documentation.
You can also package your Python project into an RPM package, which provides the following advantages compared to Setuptools packaging:
- Specification of dependencies of a package on other RPMs (even non-Python)
Cryptographic signing
With cryptographic signing, content of RPM packages can be verified, integrated, and tested with the rest of the operating system.
16.4.1. The spec file description for a Python package Copiar enlaceEnlace copiado en el portapapeles!
A spec file contains instructions that the rpmbuild utility uses to build an RPM. The instructions are included in a series of sections. A spec file has two main parts in which the sections are defined:
- Preamble (contains a series of metadata items that are used in the Body)
- Body (contains the main part of the instructions)
An RPM SPEC file for Python projects has some specifics compared to non-Python RPM SPEC files. Most notably, a name of any RPM package of a Python library must always include the prefix determining the version, for example, python3 for Python 3.6, python38 for Python 3.8, python39 for Python 3.9, python3.11 for Python 3.11, or python3.12 for Python 3.12.
Other specifics are shown in the following spec file example for the python3-detox package. For description of such specifics, see the notes below the example.
- 1
- The modname macro contains the name of the Python project. In this example it is
detox. - 2
- When packaging a Python project into RPM, the
python3prefix always needs to be added to the original name of the project. The original name here isdetoxand the name of the RPM ispython3-detox. - 3
- BuildRequires specifies what packages are required to build and test this package. In BuildRequires, always include items providing tools necessary for building Python packages:
python36-develandpython3-setuptools. Thepython36-rpm-macrospackage is required so that files with/usr/bin/python3interpreter directives are automatically changed to/usr/bin/python3.6. - 4
- Every Python package requires some other packages to work correctly. Such packages need to be specified in the
specfile as well. To specify the dependencies, you can use the %python_enable_dependency_generator macro to automatically use dependencies defined in thesetup.pyfile. If a package has dependencies that are not specified using Setuptools, specify them within additionalRequiresdirectives. - 5
- The %py3_build and %py3_install macros run the
setup.py buildandsetup.py installcommands, respectively, with additional arguments to specify installation locations, the interpreter to use, and other details. - 6
- The check section provides a macro that runs the correct version of Python. The %{__python3} macro contains a path for the Python 3 interpreter, for example
/usr/bin/python3. We recommend to always use the macro rather than a literal path.
16.4.2. Common macros for Python 3 RPMs Copiar enlaceEnlace copiado en el portapapeles!
In a spec file, always use the macros that are described in the following Macros for Python 3 RPMs table rather than hardcoding their values.
In macro names, always use python3 or python2 instead of unversioned python. Configure the particular Python 3 version in the BuildRequires section of the SPEC file to python36-rpm-macros, python38-rpm-macros, python39-rpm-macros, python3.11-rpm-macros, or python3.12-rpm-macros.
| Macro | Normal Definition | Description |
|---|---|---|
| %{__python3} | /usr/bin/python3 | Python 3 interpreter |
| %{python3_version} | 3.6 | The full version of the Python 3 interpreter. |
| %{python3_sitelib} | /usr/lib/python3.6/site-packages | Where pure-Python modules are installed. |
| %{python3_sitearch} | /usr/lib64/python3.6/site-packages | Where modules containing architecture-specific extensions are installed. |
| %py3_build |
Runs the | |
| %py3_install |
Runs the |
16.4.3. Automatic provides for Python RPMs Copiar enlaceEnlace copiado en el portapapeles!
When packaging a Python project, make sure that the following directories are included in the resulting RPM if these directories are present:
-
.dist-info -
.egg-info -
.egg-link
From these directories, the RPM build process automatically generates virtual pythonX.Ydist provides, for example, python3.6dist(detox). These virtual provides are used by packages that are specified by the %python_enable_dependency_generator macro.
16.5. Handling interpreter directives in Python scripts Copiar enlaceEnlace copiado en el portapapeles!
In Red Hat Enterprise Linux 8, executable Python scripts are expected to use interpreter directives (also known as hashbangs or shebangs) that explicitly specify at a minimum the major Python version. For example:
The /usr/lib/rpm/redhat/brp-mangle-shebangs buildroot policy (BRP) script is run automatically when building any RPM package, and attempts to correct interpreter directives in all executable files.
The BRP script generates errors when encountering a Python script with an ambiguous interpreter directive, such as:
#!/usr/bin/python
#!/usr/bin/python
or
#!/usr/bin/env python
#!/usr/bin/env python
16.5.1. Modifying interpreter directives in Python scripts Copiar enlaceEnlace copiado en el portapapeles!
Modify interpreter directives in the Python scripts that cause the build errors at RPM build time.
Prerequisites
- Some of the interpreter directives in your Python scripts cause a build error.
Procedure
To modify interpreter directives, complete one of the following tasks:
Apply the
pathfix.pyscript from theplatform-python-develpackage:pathfix.py -pn -i %{__python3} PATH …# pathfix.py -pn -i %{__python3} PATH …Copy to Clipboard Copied! Toggle word wrap Toggle overflow Note that multiple
PATHscan be specified. If aPATHis a directory,pathfix.pyrecursively scans for any Python scripts matching the pattern^[a-zA-Z0-9_]+\.py$, not only those with an ambiguous interpreter directive. Add this command to the%prepsection or at the end of the%installsection.-
Modify the packaged Python scripts so that they conform to the expected format. For this purpose,
pathfix.pycan be used outside the RPM build process, too. When runningpathfix.pyoutside an RPM build, replace%{__python3}from the example above with a path for the interpreter directive, such as/usr/bin/python3.
If the packaged Python scripts require a version other than Python 3.6, adjust the preceding commands to include the required version.
16.5.2. Changing /usr/bin/python3 interpreter directives in your custom packages Copiar enlaceEnlace copiado en el portapapeles!
By default, interpreter directives in the form of /usr/bin/python3 are replaced with interpreter directives pointing to Python from the platform-python package, which is used for system tools with Red Hat Enterprise Linux. You can change the /usr/bin/python3 interpreter directives in your custom packages to point to a specific version of Python that you have installed from the AppStream repository.
Procedure
To build your package for a specific version of Python, add the
python*-rpm-macrossubpackage of the respectivepythonpackage to the BuildRequires section of thespecfile. For example, for Python 3.6, include the following line:BuildRequires: python36-rpm-macros
BuildRequires: python36-rpm-macrosCopy to Clipboard Copied! Toggle word wrap Toggle overflow As a result, the
/usr/bin/python3interpreter directives in your custom package are automatically converted to/usr/bin/python3.6.
To prevent the BRP script from checking and modifying interpreter directives, use the following RPM directive:
%undefine __brp_mangle_shebangs
%undefine __brp_mangle_shebangs
16.6. Using the PHP scripting language Copiar enlaceEnlace copiado en el portapapeles!
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 for scripting with PHP without using a web server. -
devel- This profile includes packages from thecommonprofile and additional packages for development purposes.
16.6.1. Installing the PHP scripting language Copiar enlaceEnlace copiado en el portapapeles!
You can install a selected version of the php module.
Procedure
To install a
phpmodule stream with the default profile, use:yum module install php:stream
# yum module install php:streamCopy to Clipboard Copied! Toggle word wrap Toggle overflow Replace stream with the version of PHP you wish to install.
For example, to install PHP 8.0:
yum module install php:8.0
# yum module install php:8.0Copy to Clipboard Copied! Toggle word wrap Toggle overflow The default
commonprofile installs also thephp-fpmpackage, and preconfigures PHP for use with theApache HTTP Serverornginx.To install a specific profile of a
phpmodule stream, use:yum module install php:stream/profile
# yum module install php:stream/profileCopy to Clipboard Copied! Toggle word wrap Toggle overflow 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
# yum module install php:8.0/minimalCopy to Clipboard Copied! Toggle word wrap Toggle overflow
16.6.2. Using the PHP scripting language with a web server Copiar enlaceEnlace copiado en el portapapeles!
16.6.2.1. Using PHP with the Apache HTTP Server Copiar enlaceEnlace copiado en el portapapeles!
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.
You can run the PHP code using the FastCGI process server.
Prerequisites
The PHP scripting language is installed on your system.
Procedure
Install the
httpdmodule:yum module install httpd:2.4
# yum module install httpd:2.4Copy to Clipboard Copied! Toggle word wrap Toggle overflow Start the
Apache HTTP Server:systemctl start httpd
# systemctl start httpdCopy to Clipboard Copied! Toggle word wrap Toggle overflow Or, if the
Apache HTTP Serveris already running on your system, restart thehttpdservice after installing PHP:systemctl restart httpd
# systemctl restart httpdCopy to Clipboard Copied! Toggle word wrap Toggle overflow Start the
php-fpmservice:systemctl start php-fpm
# systemctl start php-fpmCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: Enable both services to start at boot time:
systemctl enable php-fpm httpd
# systemctl enable php-fpm httpdCopy to Clipboard Copied! Toggle word wrap Toggle overflow To obtain information about your PHP settings, create the
index.phpfile with the following content in the/var/www/html/directory:echo '<?php phpinfo(); ?>' > /var/www/html/index.php
# echo '<?php phpinfo(); ?>' > /var/www/html/index.phpCopy to Clipboard Copied! Toggle word wrap Toggle overflow To run the
index.phpfile, point the browser to:http://<hostname>/
http://<hostname>/Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: Adjust configuration if you have specific requirements:
-
/etc/httpd/conf/httpd.conf- generichttpdconfiguration -
/etc/httpd/conf.d/php.conf- PHP-specific configuration forhttpd -
/usr/lib/systemd/system/httpd.service.d/php-fpm.conf- by default, thephp-fpmservice is started withhttpd -
/etc/php-fpm.conf- FPM main configuration -
/etc/php-fpm.d/www.conf- defaultwwwpool configuration
-
Example 16.1. Running a "Hello, World!" PHP script using the Apache HTTP Server
Create a
hellodirectory for your project in the/var/www/html/directory:mkdir hello
# mkdir helloCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a
hello.phpfile in the/var/www/html/hello/directory with the following content:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Start the
Apache HTTP Server:systemctl start httpd
# systemctl start httpdCopy to Clipboard Copied! Toggle word wrap Toggle overflow To run the
hello.phpfile, point the browser to:http://<hostname>/hello/hello.php
http://<hostname>/hello/hello.phpCopy to Clipboard Copied! Toggle word wrap Toggle overflow As a result, a web page with the “Hello, World!” text is displayed.
16.6.2.2. Using PHP with the nginx web server Copiar enlaceEnlace copiado en el portapapeles!
You can run PHP code through the nginx web server.
Prerequisites
The PHP scripting language is installed on your system.
Procedure
Install an
nginxmodule stream:yum module install nginx:stream
# yum module install nginx:streamCopy to Clipboard Copied! Toggle word wrap Toggle overflow Replace stream with the version of
nginxyou wish to install.For example, to install
nginxversion 1.18:yum module install nginx:1.18
# yum module install nginx:1.18Copy to Clipboard Copied! Toggle word wrap Toggle overflow Start the
nginxserver:systemctl start nginx
# systemctl start nginxCopy to Clipboard Copied! Toggle word wrap Toggle overflow Or, if the
nginxserver is already running on your system, restart thenginxservice after installing PHP:systemctl restart nginx
# systemctl restart nginxCopy to Clipboard Copied! Toggle word wrap Toggle overflow Start the
php-fpmservice:systemctl start php-fpm
# systemctl start php-fpmCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: Enable both services to start at boot time:
systemctl enable php-fpm nginx
# systemctl enable php-fpm nginxCopy to Clipboard Copied! Toggle word wrap Toggle overflow To obtain information about your PHP settings, create the
index.phpfile with the following content in the/usr/share/nginx/html/directory:echo '<?php phpinfo(); ?>' > /usr/share/nginx/html/index.php
# echo '<?php phpinfo(); ?>' > /usr/share/nginx/html/index.phpCopy to Clipboard Copied! Toggle word wrap Toggle overflow To run the
index.phpfile, point the browser to:http://<hostname>/
http://<hostname>/Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: Adjust configuration if you have specific requirements:
-
/etc/nginx/nginx.conf-nginxmain configuration -
/etc/nginx/conf.d/php-fpm.conf- FPM configuration fornginx -
/etc/php-fpm.conf- FPM main configuration -
/etc/php-fpm.d/www.conf- defaultwwwpool configuration
-
Example 16.2. Running a "Hello, World!" PHP script using the nginx server
Create a
hellodirectory for your project in the/usr/share/nginx/html/directory:mkdir hello
# mkdir helloCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a
hello.phpfile in the/usr/share/nginx/html/hello/directory with the following content:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Start the
nginxserver:systemctl start nginx
# systemctl start nginxCopy to Clipboard Copied! Toggle word wrap Toggle overflow To run the
hello.phpfile, point the browser to:http://<hostname>/hello/hello.php
http://<hostname>/hello/hello.phpCopy to Clipboard Copied! Toggle word wrap Toggle overflow As a result, a web page with the “Hello, World!” text is displayed.
16.6.3. Running a PHP script using the command line Copiar enlaceEnlace copiado en el portapapeles!
A PHP script is usually run using a web server, but also can be run using the command line.
If you want to run php scripts using only command-line, install the minimal profile of a php module stream.
See Installing the PHP scripting language.
Prerequisites
The PHP scripting language is installed on your system.
Procedure
In a text editor, create a
filename.phpfileReplace filename with the name of your file.
Execute the created
filename.phpfile from the command line:php filename.php
# php filename.phpCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Example 16.3. Running a "Hello, World!" PHP script using the command line
Create a
hello.phpfile with the following content using a text editor:<?php echo 'Hello, World!'; ?><?php echo 'Hello, World!'; ?>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Execute the
hello.phpfile from the command line:php hello.php
# php hello.phpCopy to Clipboard Copied! Toggle word wrap Toggle overflow As a result, “Hello, World!” is printed.
16.7. Getting started with Tcl/Tk Copiar enlaceEnlace copiado en el portapapeles!
16.7.1. Introduction to Tcl/Tk Copiar enlaceEnlace copiado en el portapapeles!
Tool command language (Tcl) is a dynamic programming language. The interpreter for this language, together with the C library, is provided by the tcl package.
Using Tcl paired with Tk (Tcl/Tk) enables creating cross-platform GUI applications. Tk is provided by the tk package.
Note that Tk can refer to any of the following:
- A programming toolkit for multiple languages
- A Tk C library bindings available for multiple languages, such as C, Ruby, Perl and Python
- A wish interpreter that instantiates a Tk console
- A Tk extension that adds a number of new commands to a particular Tcl interpreter
For more information about Tcl/Tk, see the Tcl/Tk manual or Tcl/Tk documentation web page.
16.7.2. Notable changes in Tcl/Tk 8.6 Copiar enlaceEnlace copiado en el portapapeles!
Red Hat Enterprise Linux 7 used Tcl/Tk 8.5. With Red Hat Enterprise Linux 8, Tcl/Tk version 8.6 is provided in the Base OS repository.
Major changes in Tcl/Tk 8.6 compared to Tcl/Tk 8.5 are:
- Object-oriented programming support
- Stackless evaluation implementation
- Enhanced exceptions handling
- Collection of third-party packages built and installed with Tcl
- Multi-thread operations enabled
- SQL database-powered scripts support
- IPv6 networking support
- Built-in Zlib compression
List processing
Two new commands,
lmapanddict mapare available, which allow the expression of transformations over Tcl containers.Stacked channels by script
Two new commands,
chan pushandchan popare available, which allow to add or remove transformations to or from I/O channels.
Major changes in Tk include:
- Built-in PNG image support
Busy windows
A new command,
tk busyis available, which disables user interaction for a window or a widget and shows the busy cursor.- New font selection dialog interface
- Angled text support
- Moving things on a canvas support
For the detailed list of changes between Tcl 8.5 and Tcl 8.6, see Changes in Tcl/Tk 8.6.
16.7.3. Migrating to Tcl/Tk 8.6 Copiar enlaceEnlace copiado en el portapapeles!
Red Hat Enterprise Linux 7 used Tcl/Tk 8.5. With Red Hat Enterprise Linux 8, Tcl/Tk version 8.6 is provided in the Base OS repository.
This section describes migration path to Tcl/Tk 8.6 for:
- Developers writing Tcl extensions or embedding Tcl interpreter into their applications
- Users scripting tasks with Tcl/Tk
16.7.3.1. Migration path for developers of Tcl extensions Copiar enlaceEnlace copiado en el portapapeles!
To make your code compatible with Tcl 8.6, use the following procedure.
Procedure
Rewrite the code to use the
interpstructure. For example, if your code readsinterp→errorLine, rewrite it to use the following function:Tcl_GetErrorLine(interp)
Tcl_GetErrorLine(interp)Copy to Clipboard Copied! Toggle word wrap Toggle overflow This is necessary because Tcl 8.6 limits direct access to members of the
interpstructure.To make your code compatible with both Tcl 8.5 and Tcl 8.6, use the following code snippet in a header file of your C or C++ application or extension that includes the Tcl library:
include <tcl.h> if !defined(Tcl_GetErrorLine) define Tcl_GetErrorLine(interp) (interp→errorLine) endif
# include <tcl.h> # if !defined(Tcl_GetErrorLine) # define Tcl_GetErrorLine(interp) (interp→errorLine) # endifCopy to Clipboard Copied! Toggle word wrap Toggle overflow
16.7.3.2. Migration path for users scripting their tasks with Tcl/Tk Copiar enlaceEnlace copiado en el portapapeles!
In Tcl 8.6, most scripts work the same way as with the previous version of Tcl.
To migrate you code into Tcl 8.6, use this procedure.
Procedure
When writing a portable code, make sure to not use the commands that are no longer supported in Tk 8.6:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Note that you can check the list of unsupported commands also in the
/usr/share/tk8.6/unsupported.tclfile.