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