Skip to content

PHP

安装

RHEL

1. 更新系统,确保系统是最新的。

bash
sudo clean all
sudo dnf update
sudo dnf install dnf-utils
sudo clean all
sudo dnf update
sudo dnf install dnf-utils

2. 安装

EL8
bash
# EL8
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm
# 查询可用的版本
sudo dnf module list php
# 重置并启用最新的PHP模块
sudo dnf module enable php:remi-8.2
sudo dnf module reset php
sudo dnf module install php:remi-8.2
#
sudo dnf install php php-cli php-common php-fpm
# 检查是否安装成功
php -v
# 安装扩展
# 格式 - sudo dnf install php-(extension_name)
sudo dnf install php-mysql
sudo dnf install php-sodium
#
yum install php-xml -y
sudo dnf install -y php-{common,mysql,xml,xmlrpc,curl,gd,imagick,cli,fpm,mbstring,opcache,zip,sodium}
# EL8
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm
# 查询可用的版本
sudo dnf module list php
# 重置并启用最新的PHP模块
sudo dnf module enable php:remi-8.2
sudo dnf module reset php
sudo dnf module install php:remi-8.2
#
sudo dnf install php php-cli php-common php-fpm
# 检查是否安装成功
php -v
# 安装扩展
# 格式 - sudo dnf install php-(extension_name)
sudo dnf install php-mysql
sudo dnf install php-sodium
#
yum install php-xml -y
sudo dnf install -y php-{common,mysql,xml,xmlrpc,curl,gd,imagick,cli,fpm,mbstring,opcache,zip,sodium}
EL7
bash
## EL7
sudo yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum -y install yum-utils
sudo yum-config-manager --disable 'remi-php*'
sudo yum-config-manager --enable remi-php81
sudo yum -y install php php-{cli,fpm,mysqlnd,zip,devel,gd,mbstring,curl,xml,pear,bcmath,json}
## EL7
sudo yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum -y install yum-utils
sudo yum-config-manager --disable 'remi-php*'
sudo yum-config-manager --enable remi-php81
sudo yum -y install php php-{cli,fpm,mysqlnd,zip,devel,gd,mbstring,curl,xml,pear,bcmath,json}

3. php-fpm

配置

bash
# vi /etc/php-fpm.d/www.conf
user = nginx
group = nginx
#
listen = /run/php-fpm/www.sock
# vi /etc/php-fpm.d/www.conf
user = nginx
group = nginx
#
listen = /run/php-fpm/www.sock

4. 启动

bash
# 随系统启动
systemctl enable php-fpm
# 取消系统启动
systemctl disable php-fpm
# 启动服务
systemctl start php-fpm
# 重启服务
systemctl restart php-fpm
# 重新加载
systemctl reload php-fpm
# 停止服务
systemctl stop php-fpm
# 查看状态
systemctl status php-fpm
# 随系统启动
systemctl enable php-fpm
# 取消系统启动
systemctl disable php-fpm
# 启动服务
systemctl start php-fpm
# 重启服务
systemctl restart php-fpm
# 重新加载
systemctl reload php-fpm
# 停止服务
systemctl stop php-fpm
# 查看状态
systemctl status php-fpm

4. Nginx

nginx
server {
    listen 80;
    server_name localhost;
    location / {
        root   /var/www/html;
        index  index.html index.htm;
        if (!-e $request_filename) {
            rewrite  ^(.*)$  /index.php?s=/$1  last;
            break;
        }
    }
    location ~ \.php$ {
        root           /var/www/html;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}
server {
    listen 80;
    server_name localhost;
    location / {
        root   /var/www/html;
        index  index.html index.htm;
        if (!-e $request_filename) {
            rewrite  ^(.*)$  /index.php?s=/$1  last;
            break;
        }
    }
    location ~ \.php$ {
        root           /var/www/html;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

Composer

镜像设置

bash
# 更新
composer self-update
# 清空缓存
composer clear
# 全局设置
composer config -g repos.packagist composer https://mirrors.cloud.tencent.com/composer/
composer config -g repos.packagist composer https://mirrors.aliyun.com/composer/
# 项目项目
composer config repos.packagist composer https://mirrors.aliyun.com/composer/
composer config repos.packagist composer https://mirrors.cloud.tencent.com/composer/
# 恢复官方镜像
composer config -g --unset repos.packagist
composer config -g repos.packagist composer https://packagist.org
# 更新
composer self-update
# 清空缓存
composer clear
# 全局设置
composer config -g repos.packagist composer https://mirrors.cloud.tencent.com/composer/
composer config -g repos.packagist composer https://mirrors.aliyun.com/composer/
# 项目项目
composer config repos.packagist composer https://mirrors.aliyun.com/composer/
composer config repos.packagist composer https://mirrors.cloud.tencent.com/composer/
# 恢复官方镜像
composer config -g --unset repos.packagist
composer config -g repos.packagist composer https://packagist.org

XDebug

MacOS

编译安装

bash
#
brew install autoconf
#
sudo xcode-select -switch /Applications/Xcode.app
#
/Applications/XAMPP/xamppfiles/bin/phpize-7.4.8
#
./configure --enable-xdebug --with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config-7.4.8
#
make
#
sudo cp modules/* /Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20190902/
#
brew install autoconf
#
sudo xcode-select -switch /Applications/Xcode.app
#
/Applications/XAMPP/xamppfiles/bin/phpize-7.4.8
#
./configure --enable-xdebug --with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config-7.4.8
#
make
#
sudo cp modules/* /Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20190902/

PECL 安装

bash
# Intel
arch -x86_64 sudo pecl install xdebug
# M1
arch -arm64e sudo pecl install xdebug
# Intel
arch -x86_64 sudo pecl install xdebug
# M1
arch -arm64e sudo pecl install xdebug

配置 - MacOS

bash
[xdebug]
zend_extension="xdebug.so"
xdebug.mode=debug
xdebug.idekey=XDebugIDE
xdebug.start_with_request=trigger
[xdebug]
zend_extension="xdebug.so"
xdebug.mode=debug
xdebug.idekey=XDebugIDE
xdebug.start_with_request=trigger

配置 - Windows

bash
[xdebug]
zend_extension="php_xdebug.dll"
zend_extension="D:\Dev\php\xampp\php\ext\php_xdebug.dll"
xdebug.mode=debug
xdebug.idekey=XDebugIDE
xdebug.start_with_request=trigger
[xdebug]
zend_extension="php_xdebug.dll"
zend_extension="D:\Dev\php\xampp\php\ext\php_xdebug.dll"
xdebug.mode=debug
xdebug.idekey=XDebugIDE
xdebug.start_with_request=trigger