Table of Contents
PHP installation configuration
Add epel source
Installation dependencies
About php configuration
Home Backend Development PHP Problem How to compile and install php5.6.31

How to compile and install php5.6.31

Nov 17, 2021 am 09:45 AM

How to compile and install php5.6.31: 1. Add epel source and download php-5.6.31; 2. Unzip the installation package and install it; 3. Modify php-fpm.conf; 4. Start php -fpm; 5. Edit the nginx configuration file and restart the nginx service.

How to compile and install php5.6.31

The operating environment of this article: CentOS 7 system, php5.6.31 version, DELL G3 computer

How to compile and install php5.6.31?

CentOS 7 Compile and install PHP5.6.31

There are already nginx and mysql on the server, so I decided to use PHP Nginx mysql Combination, I read a lot of information on the Internet. Since I don’t know much about Linux and PHP, I don’t know how PHP is related to nginx and mysql. I encountered various reasons (either PHP was installed incorrectly or the package was not installed). After spending a lot of time, I found out after the deployment that these three are installed separately (um~~can they be installed together). You only need to configure PHP after installation, and configure nginx (associated with PHP) to run directly. . As for mysql, as long as it is turned on and the connection database in the php project is configured, you can connect directly. So this article mainly focuses on the installation of php.

Regarding the installation of nginx and mysql, some development libraries for Linux need to be installed before starting the installation. I will not repeat them here. They are all in the reference link.

This article mainly refers to this link blog: https://www.cnblogs.com/flower-tree/p/7562101.html

php version: 5.6. 31

nginx version: 1.7.3

mysql version: 5.6.62

PHP installation configuration

nginx itself cannot handle PHP, it is just a WEB When the server receives the request, if it is a PHP request, it will be sent to the PHP interpreter for processing and the result will be returned to the client.

nginx generally sends the request to the fastcgi management process for processing. The fastcgi management process selects the cgi sub-process processing result and returns it to nginx.

What is PHP-FPM? PHP-FPM is a FASTCGI manager for PHP. It is only used for PHP. The new version has integrated php-fpm. php-fpm provides better php process management, can effectively control memory and processes, and can smoothly reload php configuration. . When configuring, you can enable php-fpm with the -enable-fpm parameter. Other parameters can be found here. As for what fastcgi is and its relationship with php-fpm, please refer to the link https://segmentfault.com/q/1010000000256516

Preparation before installation

Add epel source

rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
Copy after login

Installation dependencies

yum install gcc bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel openssl-devel libxml2-devel libcurl-devel bzip2-devel readline-devel libedit-devel sqlite-develyum -y install gcc gcc-c++ glibcyum -y install libmcrypt-devel mhash-devel libxslt-devel \
libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel \
zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel \
ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel \
krb5 krb5-devel libidn libidn-devel openssl openssl-devel
Copy after login

Downloadphp-5.6.31

1) Unzip the installation package to /usr/local/src

cd /usr/local/srctar -zvxf php-5.6.31.tar.gz
Copy after login

2) Enter the installation directory, Installation

cd php-5.6.31./configure --prefix=/usr/local/php --enable-fpm --with-mcrypt \--enable-mbstring --enable-pdo --with-curl --disable-debug  --disable-rpath \--enable-inline-optimization --with-bz2  --with-zlib --enable-sockets \--enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex \--with-mhash --enable-zip --with-pcre-regex --with-mysql --with-mysqli \--with-gd --with-jpeg-dir --with-freetype-dir --enable-calendarmake && make install
Copy after login
CentOS 中下载php: wget http://php.net/get/php-5.6.30.tar.gz/from/this/mirror
Copy after login

The above completes the installation of php-fpm. The installation process will take some time.

About php configuration

1. Provide configuration files for php

cp php.ini-production /usr/local/php/etc/php.ini
Copy after login

Note: php.ini-production is still in /usr/local/src/php-5.6. 31 directory

2. Provide configuration file for php-fpm

cd /usr/local/phpcp etc/php-fpm.conf.default etc/php-fpm.conf
vim etc/php-fpm.conf
Copy after login

Modify php-fpm.conf

user = www
group = www

If the www user does not exist, then add the www user first (default running user nobody)

groupadd www
useradd -g www www
Copy after login

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”

Modify

pm.max_children = 150
pm.start_servers = 8
pm.min_spare_servers = 5
pm.max_spare_servers = 10
pid = /usr/local/php/var/run/php-fpm.pid
Copy after login

3. Start php-fpm

Execution

/usr/local/php/sbin/php-fpm
Copy after login

Use the following command to verify (if there are several php-fpm processes in the output of this command, it means the startup is successful):

ps aux | grep php-fpm
Copy after login

The result is as shown below:

3. Integration of nginx and php-fpm

Edit nginx configuration file

vim /usr/local/nginx/conf/nginx.conf
Copy after login

The initial content is as follows:

# nginx运行的用户名
user nginx;
# nginx启动进程,通常设置成和cpu的数量相等,这里为自动
worker_processes auto;

# errorlog文件位置
error_log /var/log/nginx/error.log;
# pid文件地址,记录了nginx的pid,方便进程管理
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
# 用来加载其他动态模块的配置
include /usr/share/nginx/modules/*.conf;

# 工作模式和连接数上限
events {
    # 每个worker_processes的最大并发链接数
    # 并发总数:worker_processes*worker_connections
    worker_connections 1024;
}

# 与提供http服务相关的一些配置参数类似的还有mail
http {
    # 设置日志的格式
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    # access_log记录访问的用户、页面、浏览器、ip和其他的访问信息
    access_log  /var/log/nginx/access.log  main;

    # 这部分下面会单独解释
    # 设置nginx是否使用sendfile函数输出文件
    sendfile            on;
    # 数据包最大时发包(使用Nagle算法)
    tcp_nopush          on;
    # 立刻发送数据包(禁用Nagle算法)
    tcp_nodelay         on;
    # 链接超时时间
    keepalive_timeout   65;
    # 这个我也不清楚...
    types_hash_max_size 2048;

    # 引入文件扩展名与文件类型映射表
    include             /etc/nginx/mime.types;
    # 默认文件类型
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    # http服务上支持若干虚拟主机。
    # 每个虚拟主机一个对应的server配置项
    # 配置项里面包含该虚拟主机相关的配置。
    server {
        # 端口
        listen       80 default_server;
        listen       [::]:80 default_server;
        # 访问的域名
        server_name  _;
        # 默认网站根目录(www目录)
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.

        include /etc/nginx/default.d/*.conf;

        # 默认请求
        location / {
        }

        # 错误页(404)
        error_page 404 /404.html;
            location = /40x.html {
        }

        # 错误页(50X)
        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
}
Copy after login

We want to change the configuration Only the server part is needed. Enter vim editing mode, or use FlashFXP to share the configuration file to the desktop to make changes.

Only three changes are needed

server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        # 这里改动了,也可以写你的域名,我用的是IP地址
        server_name  192.168.0.222;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
            # 这里改动了 定义首页索引文件的名称
            index index.php index.html index.htm;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }

        # 这里新加的
        # PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI协议默认配置.
        # Fastcgi服务器和程序(PHP,Python)沟通的协议.
        location ~ \.php$ {
            # 设置监听端口
            fastcgi_pass   127.0.0.1:9000;
            # 设置脚本文件请求的路径
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            # 引入fastcgi的配置文件
            include        fastcgi_params;
        }
    }
Copy after login

Restart the nginx server

nginx -s reload
Copy after login

At this time, nginx and php have been jointly configured, but we do not know the actual configuration effect How about, at this time we can write a small test script to verify it.
As mentioned before, /usr/share/nginx/html is the root directory of Nginx website. We can create a php test script in this directory.

# phpinfo.php is the name of the file I want to create

vi /usr/share/nginx/html/phpinfo.php
Copy after login

After opening the editor, enter

<?php
phpinfo();// 测试信息?>
Copy after login

After saving and exiting, enter http in the browser: //192.168.0.222/phpinfo.php, my IP here is 192.168.0.222, you can change it to your own. As shown in the figure, an interface similar to the following appears:

Nginx and php have been configured.

4. Reasons for errors during installation

When I installed according to the process, an error occurred: mcrypt.h not found. Please reinstall libmcrypt

It is because the php-mcrypt libmcrypt libmcrypt-devel packages are not installed, and the errors that occur are generally missing. Library or package, just install it.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to compile and install php5.6.31. 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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

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 8 JIT (Just-In-Time) Compilation: How it improves performance. PHP 8 JIT (Just-In-Time) Compilation: How it improves performance. Mar 25, 2025 am 10:37 AM

PHP 8's JIT compilation enhances performance by compiling frequently executed code into machine code, benefiting applications with heavy computations and reducing execution times.

PHP Secure File Uploads: Preventing file-related vulnerabilities. PHP Secure File Uploads: Preventing file-related vulnerabilities. Mar 26, 2025 pm 04:18 PM

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

OWASP Top 10 PHP: Describe and mitigate common vulnerabilities. OWASP Top 10 PHP: Describe and mitigate common vulnerabilities. Mar 26, 2025 pm 04:13 PM

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

PHP Encryption: Symmetric vs. asymmetric encryption. PHP Encryption: Symmetric vs. asymmetric encryption. Mar 25, 2025 pm 03:12 PM

The article discusses symmetric and asymmetric encryption in PHP, comparing their suitability, performance, and security differences. Symmetric encryption is faster and suited for bulk data, while asymmetric is used for secure key exchange.

PHP Authentication & Authorization: Secure implementation. PHP Authentication & Authorization: Secure implementation. Mar 25, 2025 pm 03:06 PM

The article discusses implementing robust authentication and authorization in PHP to prevent unauthorized access, detailing best practices and recommending security-enhancing tools.

PHP API Rate Limiting: Implementation strategies. PHP API Rate Limiting: Implementation strategies. Mar 26, 2025 pm 04:16 PM

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

What is the purpose of prepared statements in PHP? What is the purpose of prepared statements in PHP? Mar 20, 2025 pm 04:47 PM

Prepared statements in PHP enhance database security and efficiency by preventing SQL injection and improving query performance through compilation and reuse.Character count: 159

How do you retrieve data from a database using PHP? How do you retrieve data from a database using PHP? Mar 20, 2025 pm 04:57 PM

Article discusses retrieving data from databases using PHP, covering steps, security measures, optimization techniques, and common errors with solutions.Character count: 159

See all articles