Skip to content

PHP安装

linux安装PHP

下载PHP 7.4.22

shell
wget https://www.php.net/distributions/php-7.4.22.tar.bz2

解压

shell
tar -xjvf php-7.4.22.tar.bz2
cd php-7.4.22

新增用户组,用户

编译前,新增用户组,用户,用于编译使用

shell
groupadd www
useradd -g www www

配置

./configure --help 查看编译参数

开始编译(根据自己需要增减),如果全都默认,直接执行: ./configure 即可

shell
./configure \ 
--prefix=/usr/local/php \ 
--with-config-file-path=/etc \ 
--with-fpm-user=www \ 
--with-fpm-group=www \  
--with-curl \ 
--with-freetype-dir \ 
--enable-gd \ 
--with-gettext \  
--with-iconv-dir \ 
--with-kerberos \ 
--with-libdir=lib64 \ 
--with-libxml-dir \ 
--with-mysqli \ 
--with-openssl \ 
--with-pcre-regex \ 
--with-pdo-mysql \ 
--with-pdo-sqlite \ 
--with-pear \ 
--with-png-dir \ 
--with-jpeg-dir \ 
--with-xmlrpc \ 
--with-xsl \ 
--with-zlib \ 
--with-bz2 \ 
--with-mhash \ 
--enable-fpm \ 
--enable-bcmath \ 
--enable-libxml \ 
--enable-inline-optimization \ 
--enable-mbregex \ 
--enable-mbstring \ 
--enable-opcache \ 
--enable-pcntl \ 
--enable-shmop \ 
--enable-soap \ 
--enable-sockets \ 
--enable-sysvsem \ 
--enable-sysvshm \ 
--enable-xml \  
--enable-zip \ 
--enable-fpm

编译

shell
make && make install

添加php安装目录到系统环境变量

  • 创建并打开文件php.sh
shell
vi /etc/profile.d/php.sh
  • 添加内容如下:
shell
export PATH=$PATH:/usr/local/php/bin/
  • 保存并退出
shell
:wq!
  • 更新环境变量
shell
source /etc/profile

查看版本

shell
php -v

查看php已安装模块

shell
php -m

通过命令行确定php.ini文件的位置

shell
php -r "phpinfo();" | grep 'php.ini'

Windows安装PHP

下载对应版本的安装包

例如:

解压到要安装的目录

这里解压 PHP7.4.33D:\Soft\php\7.4.33 目录

添加环境变量

text
// 在Path中添加
D:\Soft\php\7.4.33

终端验证是否安装成功

shell
php -v

安装 pecl

下载 go-pear 文件

访问 https://pear.php.net/go-pear.phar,下载后将其保存到 PHP 安装目录下。

运行 go-pear.phar

shell
php go-pear.phar

回答安装向导的问题

shell
Are you installing a system-wide PEAR or a local copy?
(system|local) [system] :local
// 连续回车

终端验证是否安装成功

shell
pecl -v

官方安装教程:https://pear.php.net/manual/en/installation.getting.php

安装xdebug

xdebug安装引导

https://xdebug.org/wizard

最近更新