search
HomeOperation and MaintenanceCentOSHow to install and configure phpfpm on centos7

How to install phpfpm on centos7: First install Nginx through the command "yum install nginx"; then execute the command "yum install php php-fpm php-mysql" to install phpfpm; finally configure nginx to parse php.

How to install and configure phpfpm on centos7

The steps to configure Nginx in CentOS 7 are as follows:

First update yum, if you don’t have yum installed, install it yourself

yum update

1. Install Nginx

yum install nginx

Turn on Nginx and set it to start at boot

systemctl start nginx
systemctl enable nginx

After completion, enter localhost and the following page will be displayed, indicating that the installation is successful. The page will contain two pieces of information, one is the path to the configuration file, and the other is the path to the www directory

2. Install the latest version of PHP and PHP-FPM

Note The versions of PHP and PHP-FPM must be consistent

yum install php php-fpm php-mysql php-devel php-gd php-pecl-memcache php-pspell php-snmp php-xmlrpc php-xml php-pdo
php-pgsql php-pecl-redis php-soap

After successful installation, run the following command to view the php version

php -v

After the default php-fpm is successfully installed, /var/run/php-fpm There will be a file php-fpm.pid

3. Configure nginx to parse php

1) Modify the nginx configuration file

vim /etc/nginx/nginx.conf

in the server Insert the following code:

location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;

###Save user landing page to cookie: srcid for PHP files
##add_header Set-Cookie $srcid;
}

Use the following site configuration instructions to support URL beautification:

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

2) Modify the php-fpm configuration file

vim /etc/php-fpm.d/www.conf

Find the following three lines of code and Modify as follows

<span class="color">user = nginx <br/><span class="color">group = nginx <br/><span class="color">listen = /var/run/php-fpm/php-fpm.sock </span></span></span>
listen.owner ===

If this step is not configured, the browser will report an error when opening the php file

“The page you are looking for is temporarily unavailable. Please try again later”

3) Modify php.ini

vim /etc/php.ini

Find cgi.fix_pathinfo and modify it to 0

cgi.fix_pathinfo=0

After the above configuration is completed, restart nginx, php- fpm

systemctl restart php-fpm nginx

Test whether the configuration is successful

vim /usr/share/nginx/html/test.php
<?php  // test script for CentOS/RHEL 7+PHP 7.2+Nginx   phpinfo();?>

Open lcoalhost/test.php in the browser

## Recommended: "

centos system tutorial"

The above is the detailed content of How to install and configure phpfpm on centos7. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
CentOS: An Introduction to the Linux DistributionCentOS: An Introduction to the Linux DistributionApr 19, 2025 am 12:07 AM

CentOS is an open source distribution based on RedHatEnterpriseLinux, focusing on stability and long-term support, suitable for a variety of server environments. 1. The design philosophy of CentOS is stable and suitable for web, database and application servers. 2. Use YUM as the package manager to release security updates regularly. 3. Simple installation, you can build a web server with a few commands. 4. Advanced features include enhanced security using SELinux. 5. Frequently asked questions such as network configuration and software dependencies can be debugged through nmcli and yumdeplist commands. 6. Performance optimization suggestions include tuning kernel parameters and using a lightweight web server.

CentOS in Action: Server Management and Web HostingCentOS in Action: Server Management and Web HostingApr 18, 2025 am 12:09 AM

CentOS is widely used in server management and web hosting. Specific methods include: 1) using yum and systemctl to manage the server, 2) install and configure Nginx for web hosting, 3) use top and mpstat to optimize performance, 4) correctly configure the firewall and manage disk space to avoid common problems.

CentOS: A Community-Driven Linux DistributionCentOS: A Community-Driven Linux DistributionApr 17, 2025 am 12:03 AM

CentOS is a stable, enterprise-grade Linux distribution suitable for server and enterprise environments. 1) It is based on RedHatEnterpriseLinux and provides a free, open source and compatible operating system. 2) CentOS uses the Yum package management system to simplify software installation and updates. 3) Support advanced automation management, such as using Ansible. 4) Common errors include package dependency and service startup issues, which can be solved through log files. 5) Performance optimization suggestions include the use of lightweight software, regular cleaning of the system and optimization of kernel parameters.

What Comes After CentOS: The Road AheadWhat Comes After CentOS: The Road AheadApr 16, 2025 am 12:07 AM

Alternatives to CentOS include RockyLinux, AlmaLinux, OracleLinux, and SLES. 1) RockyLinux and AlmaLinux provide RHEL-compatible binary packages and long-term support. 2) OracleLinux provides enterprise-level support and Ksplice technology. 3) SLES provides long-term support and stability, but commercial licensing may increase costs.

CentOS: Exploring the AlternativesCentOS: Exploring the AlternativesApr 15, 2025 am 12:03 AM

Alternatives to CentOS include UbuntuServer, Debian, Fedora, RockyLinux, and AlmaLinux. 1) UbuntuServer is suitable for basic operations, such as updating software packages and configuring the network. 2) Debian is suitable for advanced usage, such as using LXC to manage containers. 3) RockyLinux can optimize performance by adjusting kernel parameters.

Centos shutdown command lineCentos shutdown command lineApr 14, 2025 pm 09:12 PM

The CentOS shutdown command is shutdown, and the syntax is shutdown [Options] Time [Information]. Options include: -h Stop the system immediately; -P Turn off the power after shutdown; -r restart; -t Waiting time. Times can be specified as immediate (now), minutes ( minutes), or a specific time (hh:mm). Added information can be displayed in system messages.

Difference between centos and ubuntuDifference between centos and ubuntuApr 14, 2025 pm 09:09 PM

The key differences between CentOS and Ubuntu are: origin (CentOS originates from Red Hat, for enterprises; Ubuntu originates from Debian, for individuals), package management (CentOS uses yum, focusing on stability; Ubuntu uses apt, for high update frequency), support cycle (CentOS provides 10 years of support, Ubuntu provides 5 years of LTS support), community support (CentOS focuses on stability, Ubuntu provides a wide range of tutorials and documents), uses (CentOS is biased towards servers, Ubuntu is suitable for servers and desktops), other differences include installation simplicity (CentOS is thin)

Centos configuration IP addressCentos configuration IP addressApr 14, 2025 pm 09:06 PM

Steps to configure IP address in CentOS: View the current network configuration: ip addr Edit the network configuration file: sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0 Change IP address: Edit IPADDR= Line changes the subnet mask and gateway (optional): Edit NETMASK= and GATEWAY= Lines Restart the network service: sudo systemctl restart network verification IP address: ip addr

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.