首先下载一个php源码包
wget https://www.php.net/distributions/php-7.4.13.tar.gz
安装依赖
yum -y install gcc gcc-c++ libxml2-devel openssl-devel sqlite-devel libcurl libcurl-devel gmp-devel oniguruma-devel gdbm-devel net-snmp-devel
创建一个要安装到的目录
mkdir /srv/php
进入编译
[root@localhost ~]# tar xf php-7.4.13.tar.gz
[root@localhost ~]# cd php-7.4.13/
开始编译指定路径
[root@localhost php-7.4.13]# ./configure --prefix=/srv/php --with-config-file-path=/srv/php/etc --with-mysql=mysqlnd --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-snmp --with-zlib --with-curl --with-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mhash
常见的一些编译报错
-
configure: error: Please reinstall the BZip2 distribution
解决:yum -y install bzip2 bzip2-devel -
configure: error: Package requirements (libcurl >= 7.15.5) were not met:No package ‘libcurl’ found
解决:yum -y install libcurl libcurl-devel
3.you may set the environment variables SQLITE_CFLAGS and SQLITE_LIBS to avoid the need to call pkg-config.
解决:yum -y install libxslt pkg-devel
4.configure: error: Package requirements (sqlite3 > 3.7.4) were not met:
解决:yum -y install sqlite-devel
5.configure: error: GNU MP Library version 4.2 or greater required.
解决:yum -y install gmp-devel
6.configure: error: Package requirements (oniguruma) were not met: No package ‘oniguruma’ found
解决:yum -y install oniguruma-devel
7.configure: error: Please reinstall readline - I cannot find readline.h
解决:yum -y install readline-devel
8.configure: error: Package requirements (libpcre2-8 >= 10.30) were not met: No package ‘libpcre2-8’ found
解决:https://www.jianshu.com/p/89646111a1ce
9.configure: error: DBA: Could not find necessary header file(s).
解决:yum -y install gdbm-devel
10.configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:No package ‘libzip’ found
解决:https://www.jianshu.com/p/6cbd25addc29
11 configure: error: Could not find net-snmp-config binary. Please check your net-snmp installation.
解决
yum -y install net-snmp-devel
没有报错后编译
make && make install
生成标准配置
cp php.ini-development /srv/php/etc/php.ini
mv /srv/php/etc/php-fpm.conf.default /srv/php/etc/php-fpm.conf
改名配置文件
[root@localhost ~]# cd /srv/php/etc/php-fpm.d/
[root@localhost php-fpm.d]# ls
www.conf.default
[root@localhost php-fpm.d]# mv www.conf.default www.conf
创建一个nginx用户因为我们安装时规定的用户是nginx
useradd -s /sbin/nologin nginx
启动即可
/srv/php/sbin/php-fpm
然后打包
上传到一个没安装php的机子上测试
scp php1.tar.gz root@192.168.124.178:/srv
这台机子没有nginx用户添加一个
useradd -s /sbin/nologin nginx
然后解压启动
报错是少些依赖插件解决方法
yum -y install epel-release
yum -y install oniguruma
接着报错
安装
yum -y install net-snmp
完事之后启动即可