Home Backend Development PHP Problem What should I do if php-fpm fails to start after installing PHP on centOS?

What should I do if php-fpm fails to start after installing PHP on centOS?

May 17, 2021 pm 05:58 PM
centos php php-fpm

本篇文章给大家介绍一下centOS安装PHP后,php-fpm启动失败的解决方法。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。

What should I do if php-fpm fails to start after installing PHP on centOS?

在centOS6.8上安装php,出各种问题,光是gcc的版本太低,升级gcc这个,就让我气了两天,翻遍了几乎所有相关博客总算解决了。还有mysql安装也没少踩坑,所以大家还是尽量用centOS7吧,少生气能多活几年呢。。。

现在说一下centOS6.8上编译安装php7.2.1吧。

1,安装扩展包并更新系统(我在根目录下开始的):

yum install epel-release -y
yum update
Copy after login

2,安装php依赖组件(一段全复制上去,其实掠过也可能没关系):

yum -y install wget vim pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel

3,下载php安装包并解压:

wget http://am1.php.net/distributions/php-7.2.1.tar.gz
tar xvf php-7.2.1.tar.gz
Copy after login

4,进入解压目录并开始编译(编译千万不能省,运行出错了就不能make了,这是我选出来的最靠谱可行的编译了):

cd /php-7.2.1
Copy after login

./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-mcrypt=/usr/include --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gd --with-iconv --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache

5,为了安全保险的给make出来,先更新依赖库以防万一:

yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel mysql pcre-devel
Copy after login

6,安装:

make
make install
Copy after login

7,关于配置:

cp php.ini-development /usr/local/php7/etc/php.ini
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
Copy after login

8,加个权限:

chmod +x /etc/init.d/php-fpm
Copy after login

现在试一下,/etc/init.d/php-fpm start

如果php启动成功了,那你很幸福;如果失败了,接着往下看。

大概出现的是下图这个情况吧?

再试一下运行提示的命令,出的问题是ERROR:FPM initialization failed.如下图:

所以出问题的是php-fpm,机智如我,把我另一个虚拟机(centOS7)上的php-fpm给换上去了,只需要把php的安装根目录按照自己的情况改一下就成了(就是这一行:prefix=/usr/local/php)。现在我就无私的把我的php-fpm文件奉献出来。

#! /bin/sh
### BEGIN INIT INFO 
# Provides:          php-fpm 
# Required-Start:    $remote_fs $network 
# Required-Stop:     $remote_fs $network 
# Default-Start:     2 3 4 5 
# Default-Stop:      0 1 6 
# Short-Description: starts php-fpm 
# Description:       starts the PHP FastCGI Process Manager daemon 
### END INIT INFO
prefix=/usr/local/php 
exec_prefix=${prefix}
php_fpm_BIN=${exec_prefix}/sbin/php-fpm 
php_fpm_CONF=${prefix}/etc/php-fpm.conf 
php_fpm_PID=${prefix}/var/run/php-fpm.pid

php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"
wait_for_pid () {     
try=0
    while test $try -lt 35 ; do
        case "$1" in             
        'created')             
        if [ -f "$2" ] ; then                 
        try=''                 
        break             
        fi             
        ;;
            'removed')             
            if [ ! -f "$2" ] ; then                 
            try=''                 
            break             
            fi             
            ;;         
            esac
        echo -n .         
        try=`expr $try + 1`         
        sleep 1
    done
}
case "$1" in     
start)         
echo -n "Starting php-fpm "
        $php_fpm_BIN --daemonize $php_opts
        if [ "$?" != 0 ] ; then             
        echo " failed"             
        exit 1         fi
        wait_for_pid created $php_fpm_PID
        if [ -n "$try" ] ; then             
        echo " failed"             
        exit 1         
        else             
        echo " done"         
        fi     
        ;;
    stop)         
    echo -n "Gracefully shutting down php-fpm "
        if [ ! -r $php_fpm_PID ] ; then             
        echo "warning, no pid file found - php-fpm is not running ?"             
        exit 1         
        fi
        kill -QUIT `cat $php_fpm_PID`
        wait_for_pid removed $php_fpm_PID
        if [ -n "$try" ] ; then             
        echo " failed. Use force-quit"             
        exit 1         
        else             
        echo " done"         
        fi     
        ;;
    status)         
    if [ ! -r $php_fpm_PID ] ; then             
    echo "php-fpm is stopped"             
    exit 0         
    fi
        PID=`cat $php_fpm_PID`         
        if ps -p $PID | grep -q $PID; then             
        echo "php-fpm (pid $PID) is running..."         
        else             
        echo "php-fpm dead but pid file exists"         
        fi     
        ;;
    force-quit)         
    echo -n "Terminating php-fpm "
        if [ ! -r $php_fpm_PID ] ; then             
        echo "warning, no pid file found - php-fpm is not running ?"             
        exit 1         fi
        kill -TERM `cat $php_fpm_PID`
        wait_for_pid removed $php_fpm_PID
        if [ -n "$try" ] ; then             
        echo " failed"             
        exit 1         
        else             
        echo " done"         
        fi     
        ;;
    restart)         
    $0 stop         
    $0 start     
    ;;
    reload)
        echo -n "Reload service php-fpm "
        if [ ! -r $php_fpm_PID ] ; then             
        echo "warning, no pid file found - php-fpm is not running ?"             
        exit 1         fi
        kill -USR2 `cat $php_fpm_PID`
        echo " done"     
        ;;
    configtest)         
    $php_fpm_BIN -t     
    ;;
    *)         
    echo "Usage: $0 {start|stop|force-quit|restart|reload|status|configtest}"         
    exit 1     
    ;;
esac
Copy after login


 

The above is the detailed content of What should I do if php-fpm fails to start after installing PHP on centOS?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP's Purpose: Building Dynamic Websites PHP's Purpose: Building Dynamic Websites Apr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP: Handling Databases and Server-Side Logic PHP: Handling Databases and Server-Side Logic Apr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

Why Use PHP? Advantages and Benefits Explained Why Use PHP? Advantages and Benefits Explained Apr 16, 2025 am 12:16 AM

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

How to optimize CentOS HDFS configuration How to optimize CentOS HDFS configuration Apr 14, 2025 pm 07:15 PM

Improve HDFS performance on CentOS: A comprehensive optimization guide to optimize HDFS (Hadoop distributed file system) on CentOS requires comprehensive consideration of hardware, system configuration and network settings. This article provides a series of optimization strategies to help you improve HDFS performance. 1. Hardware upgrade and selection resource expansion: Increase the CPU, memory and storage capacity of the server as much as possible. High-performance hardware: adopts high-performance network cards and switches to improve network throughput. 2. System configuration fine-tuning kernel parameter adjustment: Modify /etc/sysctl.conf file to optimize kernel parameters such as TCP connection number, file handle number and memory management. For example, adjust TCP connection status and buffer size

Centos shutdown command line Centos shutdown command line Apr 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.

See all articles