Linux安装PHP7.4

Linux 系统快速安装PHP环境(新手版)

1、下载安装包,这里安装php-7.4.22.tar.gz。PHP安装包下载

2、上传到local并解压

复制代码
 cd php-7.4.22

3、安装必备依赖

(如果yum源需要更新可以运行 yum -y update)

复制代码
yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel libzip gcc-c++

4、进行预编译

复制代码
cd  /usr/local/php-7.4.22
 
./configure  \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/lib \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-fpm \
--enable-opcache \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-mysqlnd-compression-support \
--with-iconv-dir \
--with-zlib \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--enable-intl \
--enable-ftp \
--enable-gd \
--enable-gd-jis-conv \
--with-jpeg   \
--with-freetype  \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--with-zip \
--enable-soap \
--with-gettext \
--disable-fileinfo \
--with-pear \
--enable-maintainer-zts \
--with-ldap=shared \
--without-gdbm 

注意:可能会遇到报错,如果报错就可以看一下,如果没有直接跳过就可以,可以通过目录直接跳到第五步:

1.找不到sqlit3库,就使用一下命令安装

复制代码
sudo yum install sqlite-devel

# 安装完之后可以验证一下
rpm -qa | grep sqlite

如果还找不到就手动设置环境变量
export SQLITE_CFLAGS="-I/usr/include"
export SQLITE_LIBS="-L/usr/lib64 -lsqlite3"

2.configure: error: Cannot find ldap.h

复制代码
sudo yum install openldap-devel


# 还是一样先检查
find /usr -name ldap.h

# 不行就手动设置
export CPPFLAGS="-I/usr/include"

3.configure: error: Cannot find ldap libraries in /usr/lib.

复制代码
# 检查
ls /usr/lib | grep ldap
ls /usr/lib64 | grep ldap


# 如果存在可以在编译中添加以下命令
--with-libdir=lib64 \

# 也可以试试下边两条手动设置(随便一条命令即可,不需要两条都同时设置,一条一条试)
export LDFLAGS="-L/usr/lib64"
export LDAP_LIBS="-L/usr/lib64 -lldap -llber"

4.configure: error: Package requirements (oniguruma) were not met: No package 'oniguruma' found Consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a non-standard prefix. Alternatively, you may set the environment variables ONIG_CFLAGS and ONIG_LIBS to avoid the need to call pkg-config. See the pkg-config man page for more details.

复制代码
# 安装依赖包
yum install autoconf automake libtool -y

下载源码
wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz 

解压
tar xf oniguruma-6.9.4.tar.gz 

编译
cd oniguruma-6.9.4/
./autogen.sh && ./configure --prefix=/usr
make && make install

# 检查
ls /usr/lib | grep onig
ls /usr/include | grep oniguruma.h

# 如果还是找不到,手动配置
export ONIG_CFLAGS="-I/usr/include"
export ONIG_LIBS="-L/usr/lib -lonig"

5.configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met: No package 'libzip' found No package 'libzip' found No package 'libzip' found Consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a non-standard prefix. Alternatively, you may set the environment variables LIBZIP_CFLAGS and LIBZIP_LIBS to avoid the need to call pkg-config. See the pkg-config man page for more details.

如果出现缺少libzip或者是版本小于都可以使用以下方案

复制代码
# 下载最新版本的 libzip:
wget https://libzip.org/download/libzip-1.9.2.tar.gz

# 解压并进入目录:
tar -xvzf libzip-1.9.2.tar.gz
cd libzip-1.9.2

# 配置、编译并安装:
./configure
make && make install

# 如果没有configure编译文件,就使用cmake方式编译
# 先安装cmake
cd /opt
wget https://github.com/Kitware/CMake/releases/download/v3.27.0/cmake-3.27.0.tar.gz
tar -zxvf cmake-3.27.0.tar.gz
cd cmake-3.27.0
./bootstrap
make && make install

# 安装完成可以使用以下命令查看
cmake --version


# 如果出现-bash: /usr/bin/cmake: 没有那个文件或目录可以使用全路径试试
/usr/local/bin/cmake --version
# 如果可以就更新以下环境变量
# 打开或编辑你的 .bashrc 文件
vim ~/.bashrc
# 在文件末尾添加以下行
export PATH=/usr/local/bin:$PATH
# 重新加载 .bashrc 文件
source ~/.bashrc

然后应该就可以了,继续进行预编译就可以了

5、编译&&安装

复制代码
make && make install

6、配置并启动

复制代码
cd /usr/local/php/  #先进入安装目录
cp ./etc/php-fpm.conf.default ./etc/php-fpm.conf    #配置文件
vim /usr/local/php/etc/php-fpm.conf
将;pid = run/php-fpm.pid 前面的;分号删掉
 
 #配置文件
cp /usr/local/php/etc/php-fpm.d/www.conf.default  /usr/local/php/etc/php-fpm.d/www.conf
cp /usr/local/php-7.4.22/php.ini-production /usr/local/php/lib/php.ini
 
修改php.ini配置文件
max_execution_time = 300
max_input_time = 600
post_max_size = 80M
max_file_uploads = 20
date.timezone = Asia/Shanghai
相关推荐
C_心欲无痕6 分钟前
nginx - 实现域名跳转的几种方式
运维·前端·nginx
suijishengchengde28 分钟前
****LINUX时间同步配置*****
linux·运维
willhuo1 小时前
基于xray的匿名、授权、IP白名单代理访问研究
服务器·网络·tcp/ip
幻云20101 小时前
AI自动化编排:从入门到精通(基于Dify构建AI智能系统)
运维·人工智能·自动化
qiuqyue1 小时前
基于虹软Linux Pro SDK的多路RTSP流并发接入、解码与帧级处理实践
linux·运维·网络
切糕师学AI1 小时前
Linux 操作系统简介
linux
南烟斋..1 小时前
GDB调试核心指南
linux·服务器
爱跑马的程序员2 小时前
Linux 如何查看文件夹的大小(du、df、ls、find)
linux·运维·ubuntu
catchadmin2 小时前
Laravel12 + Vue3 的免费可商用商业级管理后台 CatchAdmin V5 正式发布
开发语言·php
亚历山大海3 小时前
PHPword支持导出富文本网络图片,支持SVG导出
php