4.2. Using the PHP scripting language with a web server


4.2.1. Using PHP with the Apache HTTP Server

In Red Hat Enterprise Linux 10, the Apache HTTP Server allows 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 10.

Prerequisites

  • The PHP scripting language is installed on your system.

Procedure

  • Configure the Apache HTTP Server and php-fpm to run PHP scripts.

    1. Install the httpd package:

      # dnf install httpd
    2. Start the Apache HTTP Server:

      # systemctl start httpd

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

      # systemctl restart httpd
    3. Start the php-fpm service:

      # systemctl start php-fpm
    4. Optional: Enable both services to start at boot time:

      # systemctl enable php-fpm httpd
    5. To obtain information about your PHP settings, create the index.php file with the following content in the /var/www/html/ directory:

      # echo '<?php phpinfo(); ?>' > /var/www/html/index.php
    6. To run the index.php file, point the browser to:

      http://<hostname>/
    7. Optional: Adjust configuration if you have specific requirements:

      • /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
  • Run the "Hello, World!" PHP script using the Apache HTTP Server.

    1. Create a hello directory for your project in the /var/www/html/ directory:

      # mkdir hello
    2. Create a hello.php file in the /var/www/html/hello/ directory with the following content:

      # <!DOCTYPE html>
      <html>
      <head>
      <title>Hello, World! Page</title>
      </head>
      <body>
      <?php
          echo 'Hello, World!';
      ?>
      </body>
      </html>
    3. Start the Apache HTTP Server:

      # systemctl start httpd
    4. To run the hello.php file, point the browser to:

      http://<hostname>/hello/hello.php

      As a result, a web page with the "Hello, World!" text is displayed.

      See httpd(8), httpd.conf(5), and php-fpm(8) man pages for more information.

4.2.2. Using PHP with the nginx web server

You can run PHP code through the nginx web server.

Prerequisites

  • The PHP scripting language is installed on your system.

Procedure

  • Configure the nginx web server and php-fpm to run PHP scripts.

    1. Install the nginx package:

      # dnf install nginx
    2. Start the nginx server:

      # systemctl start nginx

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

      # systemctl restart nginx
    3. Start the php-fpm service:

      # systemctl start php-fpm
    4. Optional: Enable both services to start at boot time:

      # systemctl enable php-fpm nginx
    5. To obtain information about your PHP settings, create the index.php file with the following content in the /usr/share/nginx/html/ directory:

      # echo '<?php phpinfo(); ?>' > /usr/share/nginx/html/index.php
    6. To run the index.php file, point the browser to:

      http://<hostname>/
    7. Optional: Adjust configuration if you have specific requirements:

      • /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
  • Run the "Hello, World!" PHP script using the nginx server.

    1. Create a hello directory for your project in the /usr/share/nginx/html/ directory:

      # mkdir hello
    2. Create a hello.php file in the /usr/share/nginx/html/hello/ directory with the following content:

      # <!DOCTYPE html>
      <html>
      <head>
      <title>Hello, World! Page</title>
      </head>
      <body>
      <?php
          echo 'Hello, World!';
      ?>
      </body>
      </html>
    3. Start the nginx server:

      # systemctl start nginx
    4. To run the hello.php file, point the browser to:

      http://<hostname>/hello/hello.php

      As a result, a web page with the "Hello, World!" text is displayed.

      See nginx(8) and php-fpm(8) man pages for more information.

Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 문서 정보

Legal Notice

Theme

© 2026 Red Hat
맨 위로 이동