Php fpm httpd conf

Configure Apache php-fpm with SSL virtual Host on Centos7

Apache is a most widely used web server in Linux platforms and is one of the best stacks to host PHP applications. With the release of Apache httpd 2.4, there is a Apache proxy module (mod_proxy_fcgi.) introduced and integrated by default with Apache. Also From release 5.3.3 onward, PHP now includes the fastCGI process manager (php-fpm) in the stock source code.

So in short we can install and enable those php and Apache related packages in a Linux server and setup to run Apache with PHP-FPM. In this setup Apache will send all the PHP files for processing to PHP-FPM and PHP-FPM will return the rendered output to the browser. using this stack, a website can load faster and handle more concurrent connections while using fewer resources. Using PHP-FPM we can run each PHP application on a separate process and can assign resource limitations.

In this blog article we configure Apache with php-fpm on Centos7. After that we can run php code using only stock Apache and php binaries. No need to configure anything like suphp, mod_php or suexec. You can also refer this article if you have the newer Centos 8. So lets get started.

Читайте также:  background-color

Section 1. Prerequisites

In this section we are preparing our CentOS 7 server for the setting up Apache php-fpm. For that the first thing is we need a domain name in which your DNS configured to point to your CentOS 7 server IP. Creating DNS A record depends on our domain DNS. So do it as per your environment.

After that Disable SELinux in the server by issuing below command.

Next is Allow ports 80,443 on firewalld or Iptables. We can use below commands for that.

Next is Updating system packages by using below command.

Next is Install epel repository by using below command. This is necessary for getting latest packages.

Now Install the “Development Tools” group and the “yum-utils” packages using below commands.

Section 2. Install Apache

With the prerequisites completed, we are now proceeding with the installation of Apache web service in this section. For that issue below command.

Section 3. Install PHP

In this section we are installing the php 7.4 packages along with php-fpm.

Section 4. Configure Apache

In this section we are preparing our Apache web service to work with php-fpm. For that first create two directories using below command.

After that create a file Named training.conf using below command.

Add below content in above training.conf file. In that we are using our website name as training.supporthost.in. Replace that name with your own domain name. Save the file content.

After that Create Below Directories and files.

Now allow Apache to read the conf files from the “/etc/httpd/sites-enabled” folder. For that we are going to add following line at the end of Apache configuration file “/etc/httpd/conf/httpd.conf”.

Section 5. Issue SSL certificate.

In this section we are issuing SSL certificate for our website using let’s Encrypt certbot client. For that first install the certbot client package using below command.

Now issue the SSL for our website using below command. The command we followed are certbot with standalone option.

Section 6. Configure php-fpm

In this section we are configuring our php-fpm service to work with our website.

For that go the folder named /etc/php-fpm.d and create a file named training.conf .

Now Add below content in training.conf file.

Now Execute Below commands and create necessary files, website user and folders.

Finally restart the Apache and php-fpm service using below two commands.

Conclusion.

This concludes the installation and configuration Apache with php-fpm. Now create a phpinfo page under our website document root and visit the phpinfo page url in the browser , we can see FPM/FastCGI in the ServerAPI field. Take a look at the below screenshot. This means that right now our Apache is configured to use with php-fpm. I hope this article is informative. Leave your thoughts at the comment box.

Источник

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

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.

Источник

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