CentOS下安装PHP7.3.7
本文只做简单的命令记录展示
cd /software/
wget https://www.php.net/distributions/php-7.3.7.tar.gz
yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel automake libtool pcre-devel sqlite-devel
tar zxvf php-7.3.7.tar.gz
cd php-7.3.7
./configure --prefix=/usr/local/php7.3.7 --exec-prefix=/usr/local/php7.3.7 --bindir=/usr/local/php7.3.7/bin --sbindir=/usr/local/php7.3.7/sbin --includedir=/usr/local/php7.3.7/include --libdir=/usr/local/php7.3.7/lib/php --mandir=/usr/local/php7.3.7/php/man --with-config-file-path=/usr/local/php7.3.7/etc --with-mysql-sock=/var/lib/mysql/mysql.sock --with-mcrypt=/usr/include --with-mhash --with-openssl --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --with-gd --with-iconv --with-zlib --enable-zip --enable-inline-optimization --enable-shared --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --enable-gd-native-ttf --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache --enable-redis --enable-fpm --enable-fastcgi --with-fpm-user=root --with-fpm-group=root --without-gdbm --disable-debug --disable-rpath
make && make install
创建php用的用户和用户组
groupadd -r www && useradd -r -g www -s /bin/false -d /usr/local/php7.3.7 -M php
cp /usr/local/php7.3.7/etc/php-fpm.conf.default /usr/local/php7.3.7/etc/php-fpm.conf
cp /usr/local/php7.3.7/etc/php-fpm.d/www.conf.default /usr/local/php7.3.7/etc/php-fpm.d/www.conf
修改运行PHP的用户
;user = root
;group = root
user = nobody
group = www
修改监听的方式
;listen = 127.0.0.1:9000
listen = /tmp/php-fpm7.3.7.sock
修改监听的用户
;listen.owner = root
;listen.group = root
listen.owner = nobody
listen.group = root
保存退出
:wq
查看php.ini应该放在哪里
/usr/local/php7.3.7/bin/php -i|grep ini
Configuration File (php.ini) Path => /usr/local/php7.3.7/etc
Scan this dir for additional .ini files => (none)
Additional .ini files parsed => (none)
user_ini.cache_ttl => 300 => 300
user_ini.filename => .user.ini => .user.ini
init_command_executed_count => 0
init_command_failed_count => 0
com_init_db => 0
需要放在/usr/local/php7.3.7/etc目录中,复制建立PHP的配置文件,源码目录中是有的
cp /software/php-7.3.7/php.ini-production /usr/local/php7.3.7/etc/php.ini
如果源码中没有就从其它项目中拷贝过来,再不行就问朋友要一个或者网上搜索下载一下php.ini
vim /usr/local/php7.3.7/etc/php.ini
尝试启动php7通过报错信息看还需要修改些什么
/usr/local/php7.3.7/sbin/php-fpm
创建PHP7的脚本,我是从原来的项目复制一份做
cp /etc/init.d/php-fpm /etc/init.d/php-fpm7
修改php的路径
vim /etc/init.d/php-fpm7
修改这里prefix=/usr/local/php7.3.7
chkconfig --add php-fpm7
chkconfig php-fpm7 on
增加环境变量
vim /etc/profile
修改这里PATH=$PATH:/usr/local/php/bin:/usr/local/php7.3.7/bin:/usr/local/mongodb/bin
source /etc/profile
service php-fpm7 restart
出现意外用到的:
configure: error: off_t
undefined; check your library configuration
vim /etc/ld.so.conf
#添加如下几行
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64
#保存退出
:wq
ldconfig -v # 使之生效
yum -y install pcre-devel
configure: error: Please
reinstall the libzip distribution
cd /software/
wget https://nih.at/libzip/libzip-1.2.0.tar.gz
tar -zxvf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure
make -j4 && make install
configure: WARNING:
unrecognized options: --with-mcrypt, --with-mysql, --enable-gd-native-ttf,
--enable-redis, --enable-fastcgi
忽略它
/usr/local/include/zip.h:59:21:
fatal error: zipconf.h: No such file or directory
手动复制一下 cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
缺少fileinfo扩展
cd /software/php-7.3.7/ext/fileinfo
/usr/local/php7.3.7/bin/phpize
./configure --with-php-config=/usr/local/php7.3.7/bin/php-config
make && make install
vim /usr/local/php7.3.7/etc/php.ini
添加配置extension=fileinfo.so
service php-fpm7 restart
缺少pdo_mysql扩展
cd /software/php-7.3.7/ext/pdo_mysql/
/usr/local/php7.3.7/bin/phpize
./configure --with-php-config=/usr/local/php7.3.7/bin/php-config
vim /usr/local/php7.3.7/etc/php.ini
添加配置extension=pdo_mysql.so
service php-fpm7 restart
安装sodium扩展
cd /software/php-7.3.7/ext/sodium
/usr/local/php7.3.7/bin/phpize
./configure --with-php-config=/usr/local/php7.3.7/bin/php-config
make && make install
vim /usr/local/php7.3.7/etc/php.ini
添加配置extension=sodium.so
service php-fpm7 restart
安装PHP8.0.1的时候步骤与PHP7.37是一样的,只是出现了以下特殊的错误:
configure: error: Package requirements (sqlite3 > 3.7.4) were not met:
No package 'sqlite3' found
执行以下命令安装:
yum install sqlite-devel
elp2man: can't get `--help' info from automake-1.16
直接修改
vi Makefile
在3694行的末尾加上--no-discard-stderr
doc/aclocal-$(APIVERSION).1: $(aclocal_script) lib/Automake/Config.pm
$(update_mans) aclocal-$(APIVERSION)
doc/automake-$(APIVERSION).1: $(automake_script) lib/Automake/Config.pm
$(update_mans) automake-$(APIVERSION) --no-discard-stderr
make && make install
No package 'oniguruma' found
oniguruma是一个处理正则表达式的库,安装它。
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 --prefix=/usr --libdir=/lib64 //64位的系统一定要标识 --libdir=/lib64 否则还是不行
make && make install