(下列php初始化的参数适用于nginx配置使用的)
php7版本安装
cd /usr/local/src 进入此目录下使用wget 将php安装包下载到这里
php包:
wget http://cn2.php.net/distributions/php-7.4.2.tar.bz2
编译php
1、cd php-7.4.2
2、./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl
(执行这一步时候一般会遇到很多错误,会缺少很多库,缺什么装什么)
大概的错误:
错误:
xml2-config not found. Please check your libxml2 installation.
解决方法:
yum install -y libxml2-devel
错误:
Cannot find OpenSSL's <evp.h>
解决方法:
yum install -y openssl openssl-devel
错误:
checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution
解决办法:
yum install -y bzip2 bzip2-devel
错误:
jpeglib.h not found
解决办法:
yum -y install libjpeg-devel
错误:
configure: error: png.h not found.
解决办法:
yum install -y libpng libpng-devel
错误:
configure: error: freetype.h not found.
解决办法:
yum install -y freetype freetype-devel
错误:
configure: error: Package requirements (oniguruma) were not met:
No package 'oniguruma' found
解决办法:
yum -y install https://rpms.remirepo.net/enterprise/8/remi/x86_64/oniguruma5php-6.9.7.1-1.el8.remi.x86_64.rpm
yum -y install https://rpms.remirepo.net/enterprise/8/remi/x86_64/oniguruma5php-devel-6.9.7.1-1.el8.remi.x86_64.rpm
错误:
configure: error: wrong mysql library version or lib not found
解决方法:下载一个低版本的MySQL/Mariadb
wget wget http://cdn.mysql.com//archives/mysql-5.6/mysql-5.6.12-linux-glibc2.5-x86_64.tar.gz
tar zxvf mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.6.39-linux-glibc2.12-x86_64 /usr/local/mysql5.6
改编译参数
./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql5.6 --with-mysqli=/usr/local/mysql5.6/bin/mysql_config --with-pdo-mysql=/usr/local/mysql5.6 --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl
错误:
ERROR: [pool www] cannot get uid for user 'php-fpm'
解决方法:useradd php-fpm
错误:
error: mcrypt.h not found. Please reinstall libmcrypt.
(碰见这个错误需要安装第三方扩展源)
方法一:
1、cd
2、 wget http://www.atomicorp.com/installers/atomic
3、sh ./atomic 然后输入 yes 确认
然后安装 yum install -y libmcrypt-devel
然后cd /usr/local/src/php.......进去继续编译
方法二:
方法2: 使用php mcrypt 前必须先安装Libmcrypt libmcrypt源码安装方法:
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz tar -zxvf libmcrypt-2.5.7.tar.gz cd libmcrypt-2.5.7 ./configure -prefix=/usr/local make make install
方法三 使用yum安装epel扩展源 yum -y install epel-release yum -y install libmcrypt-devel
大概的错误就这些
编译结束之后
make && make install
到这里就安装完了。
/usr/local/php/bin/php -m 可以列出php安装的模块
/usr/local/php/bin/php -i 可以查看php的参数
php脚本(写着测试完玩,可忽略)
列: vi 1.php 打开之后在里面写上
<?php
echo "123123";
echo "\n";
?>
/usr/local/php/bin/php 1.php 启动