【PHP】PHP 安装

PHP 安装

1、下载

各版本下载地址

# 下载 php-7.4.33
wget https://www.php.net/distributions/php-7.4.33.tar.gz

2、编译

# 下载扩展源
yum install epel-release

# 安装依赖
yum install gcc gcc-c++
yum install libxml2-devel.x86_64 sqlite-devel.x86_64 openssl-devel.x86_64 libcurl-devel.x86_64 libpng-devel.x86_64 oniguruma-devel.x86_64

# 解压到 /opt/src 目录
tar -zxvf php-7.4.33.tar.gz -C /opt/src/

cd /opt/src/php-7.4.33
# 配置并检查缺少哪些依赖
./configure --prefix=/usr/local/php --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-fpm --with-curl --with-json --with-gd --with-mbstring --with-openssl --with-zlib --enable-pdo --enable-mysqli --enable-fpm --enable-mbstring --enable-json --enable-gd --enable-curl --enable-mysqlnd --enable-openssl --enable-zip --enable-soap --enable-xml --enable-session --with-php-config=/opt/php/bin/php-config  

 # 编译
 make && make install

通过检测后,就会自动生成相应的文件;如果没有通过,缺少什么就安装什么。

creating libtool
appending configuration tag "CXX" to libtool

Generating files
configure: patching main/php_config.h.in
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/www.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating sapi/phpdbg/phpdbg.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands

+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE. By continuing this installation  |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

3、配置

3.1、环境变量

vim /etc/profile

# 在 profile 文件中,添加 PHP 环境变量
PHP_HOME=/usr/local/php
PATH=$PHP_HOME/bin:$PATH
export PHP_HOME

# 生效
source /etc/profile

# 验证
php -v

# 提示
PHP 7.4.33 (cli) (built: Jun  31 2024 11:53:42) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

3.2、权限配置

创建 fpm 用户和 fpm 用户组,并对 php 脚本和所在的目录更改权限,php 脚本所在的目录最好是公共目录(例如:/opt),非用户目录。

# 对当前目录下所有目录和文件,级联修改权限
chmod -R 755 *
# 对当前目录下所有目录和文件,级联修改所属权
chown -R fpm:fpm *

3.3、php-fpg.conf

vim /usr/local/php/etc/php-fpm.conf

# 在 php-fpg.conf 声明绑定 ip 与 port
listen = 192.168.186.130:9000

3.4、www.conf

# 编辑 www.conf 文件
vim /usr/local/php/etc/php-fpm.d/www.conf

# 修改以下配置,无法声明 root
user = fpm
group = fpm

4、启动 php-fpm

php-fpm 用于解析并运行 php 脚本。

# 启动,端口默认 9000
/usr/local/php/sbin/php-fpm

使用 root 用户启动 php-fpm,启动之后就会出现 “master process” 和 “www pool” 两种进程。

进程 说明
master process 主进程,root 用户。负责管理所有工作进程,不处理 php 请求。
www pool 工作进程,fpm 用户,负责处理 php 的请求并解析 php 脚本。
如果 fpm 用户没有 php 脚本的读和执行权限,那么将无法正常处理 php 请求。
创作不易,转载请注明出处: 【PHP】PHP 安装
上一篇
下一篇