开源项目-勾股OA办公系统

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

PHP官方下载地址


注意:请参考通过宝塔搭建勾股OA开源系统,此博客内容不完善且已不再更新!


服务器环境配置信息

PHP >= 8.0
Mysql >= 5.7.0 (需支持innodb引擎)
Apache 或 Nginx
PDO PHP Extension
MBstring PHP Extension
CURL PHP Extension
FileInfo PHP Extension
Composer (用于管理第三方扩展包)

PHP环境安装

安装依赖

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++

下载PHP

wget https://www.php.net/distributions/php-8.4.2.tar.gz

解压

tar -zxf php-8.4.2.tar.gz -C /usr/local/

编译

cd /usr/local/php-8.4.2/

编译命令

./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 \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-mysqlnd-compression-support \
--with-zlib \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--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-zip \
--enable-soap \
--with-gettext \
--disable-fileinfo \
--with-pear \
--with-ldap=shared \
--without-gdbm

安装

make && make install

报错,无法正常安装

通过yum方式安装php环境

【PHP】CentOS 7使用yum安装php8.0及以上版本

yum install php-cli php-common php-fpm php-json php-mysqlnd php-xml php-gd php-mbstring php-zip -y

配置PHP-FPM

ERROR: [pool www] please specify user and group other than root

CentOS系统下使用Yum安装PHP及启动配置详解

vi /etc/php-fpm.d/www.conf

如果你的系统中没有 nginx 用户,你可以使用 nobody 或创建一个新的用户专门用于运行 PHP 进程。

user = nobody
group = nobody
#listen = /var/run/php-fpm/php-fpm.sock
systemctl status php-fpm.service
systemctl start php-fpm.service
ps -ef|grep php-fpm
netstat -tnl | grep 9000

Composer安装

Composer 安装与使用

安装

php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
php composer-setup.php

配置全局调用

mv composer.phar /usr/local/bin/composer

安装office依赖

cd git clone https://gitee.com/gougucms/office.git的目录下

composer install  

错误记录

安装PHP环境报错

libxml-2.0 >= 2.9.4… no

报错信息:

checking for libxml-2.0 >= 2.9.4... no
configure: error: Package requirements (libxml-2.0 >= 2.9.4) were not met:

Requested 'libxml-2.0 >= 2.9.4' but version of libXML is 2.9.1

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables LIBXML_CFLAGS
and LIBXML_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.


官方地址libxml2

wget http://xmlsoft.org/sources/libxml2-2.9.12.tar.gz
tar -xzvf libxml2-2.9.12.tar.gz
cd libxml2-2.9.12
./configure
make
sudo make install
vim ~/.bashrc

设置 PKG_CONFIG_PATH 环境变量

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH

设置 LIBXML_CFLAGS 和 LIBXML_LIBS 环境变量

export LIBXML_CFLAGS=$(xml2-config --cflags)
export LIBXML_LIBS=$(xml2-config --libs)

应用环境变量

source ~/.bashrc

验证安装

pkg-config --modversion libxml-2.0

Python.h: No such file or directory

报错信息:

这个错误表明在编译 libxml2 时缺少 Python 开发头文件。你需要安装 Python 开发包。以下是在不同 Linux 发行版上安装 Python 开发包的方法

make[4]: Entering directory `/opt/php/libxml2-2.9.12/python'
CC libxml.lo
libxml.c:15:20: fatal error: Python.h: No such file or directory
#include <Python.h>
^
compilation terminated.
make[4]: *** [libxml.lo] Error 1
make[4]: Leaving directory `/opt/php/libxml2-2.9.12/python'
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/opt/php/libxml2-2.9.12/python'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/opt/php/libxml2-2.9.12/python'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/opt/php/libxml2-2.9.12'
make: *** [all] Error 2

CentOS/RHEL:

sudo yum install python-devel
sudo yum install python3-devel # 如果你使用的是 Python 3

Ubuntu/Debian:

sudo apt-get install python-dev
sudo apt-get install python3-dev # 如果你使用的是 Python 3

checking for openssl >= 1.1.1… no

checking for openssl >= 1.1.1... no
configure: error: Package requirements (openssl >= 1.1.1) were not met:

Requested 'openssl >= 1.1.1' but version of OpenSSL is 1.0.2k

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables OPENSSL_CFLAGS
and OPENSSL_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details

步骤1:

博客:Linux 下 OpenSSL1.x 版本升级 OpenSSL3.x 版本记录

步骤2:

升级后,在PHP目录下执行./configure依然报错!

vim ~/.bashrc
export PKG_CONFIG_PATH=/usr/local/openssl_3.3/lib64/pkgconfig:$PKG_CONFIG_PATH
source ~/.bashrc
pkg-config --modversion openssl

checking for sqlite3 >= 3.7.7… no

checking for sqlite3 >= 3.7.7... no
configure: error: Package requirements (sqlite3 >= 3.7.7) were not met:

No package 'sqlite3' 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 SQLITE_CFLAGS
and SQLITE_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

安装

yum install sqlite-devel

验证

pkg-config --modversion sqlite3

checking for zlib >= 1.2.11… no

checking for zlib >= 1.2.11... no
configure: error: Package requirements (zlib >= 1.2.11) were not met:

Requested 'zlib >= 1.2.11' but version of zlib is 1.2.7

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables ZLIB_CFLAGS
and ZLIB_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

重新安装

wget http://www.zlib.net/zlib-1.3.1.tar.gz
./configure
make
sudo make install
pkg-config --modversion zlib

checking for libcurl >= 7.61.0… no

checking for libcurl >= 7.61.0... no
configure: error: Package requirements (libcurl >= 7.61.0) were not met:

Requested 'libcurl >= 7.61.0' but version of libcurl is 7.29.0
You may find new versions of libcurl at http://curl.haxx.se/

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables CURL_CFLAGS
and CURL_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
wget https://curl.se/download/curl-7.61.0.tar.gz
tar -xzvf curl-7.61.0.tar.gz
cd curl-7.61.0
./configure
make
sudo make install
pkg-config --modversion libcurl

Cannot find ldap libraries in /usr/lib. 和 Cannot find ldap libraries in /usr/lib.

configure: error: c
configure: error: Cannot find ldap libraries in /usr/lib.
yum install openldap-devel

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

cp -frp /usr/lib64/libldap* /usr/lib/

checking for oniguruma… no

checking for oniguruma... no
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.

安装PHP7.4找不到 No package ‘oniguruma’ found解决

已安装 autoconf 还是提示 ./autogen.sh: autoreconf: not found

sudo yum install -y autoconf automake libtool
wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz 

tar -zxvf oniguruma-6.9.4.tar.gz

cd oniguruma-6.9.4/

./autogen.sh

./configure

make

sudo make install

libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0…

checking for libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0... no
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.

报错:Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met

wget https://libzip.org/download/libzip-1.3.2.tar.gz
tar xvf libzip-1.3.2.tar.gz
cd libzip-1.3.2
./configure
make
make install