1、yum安装
- #安装依赖
- yum install epel-release
- #启用PHP 7.4 Remi存储库并在CentOS 7上安装PHP 7.4
- #配置安装源
- yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
- yum -y install yum-utils
- #设置安装版本
- yum-config-manager --enable remi-php74
- #安装php及拓展包
- yum install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-redis
- #查看php版本
- php -v
- #启动php
- systemctl start php-fpm
- #php配置文件
- vi /etc/php.ini
- #修改php上传限制,默认为2M
- upload_max_filesize = 500M
复制代码 2、编译安装
1、安装依赖包
- yum install -y 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 libsqlite3x-devel oniguruma-devel
复制代码 2、安装编译工具
- yum groupinstall 'Development Tools'
复制代码 3、下载解压
- wget http://mirrors.sohu.com/php/php-7.4.9.tar.gz
- #此处目录为root
- tar -zxvf php-7.4.9.tar.gz
- cd php-7.4.9
- #编译
- ./configure --prefix=/usr/local/php74 --with-config-file-path=/usr/local/php74/etc --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip --enable-fpm
- #make
- make&make install
- #设置环境变量
- vi /etc/profile
- #添加以下内容
- export PATH=$PATH:/usr/local/php74/bin
- source /etc/profile
- cp php.ini-production /usr/local/php74/etc/php.ini
- cd /usr/local/php74/etc
- cp php-fpm.conf.default php-fpm.conf
- cp php-fpm.d/www.conf.default php-fpm.d/www.conf
- ln -s /usr/local/php74/sbin/php-fpm /usr/sbin/
- # 启动 php-fpm
- php-fpm
- # 查看进程
- ps -ef | grep php-fpm
- ps -aux | grep php-fpm
- # 查看相关进程数量
- ps -ef | grep php-fpm | grep -v grep | wc -l
- # 查看端口
- netstat -tnl | grep 9000
- # 将源码目录 sapi/fpm 下的 init.d.php-fpm 复制到 /etc/init.d 目录下并改名为 php-fpm
- cp /root/php-7.4.9/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
- #添加可执行权限
- chmod u+x /etc/init.d/php-fpm
- # 添加系统服务
- chkconfig --add php-fpm
- # 开启服务
- chkconfig php-fpm on
- # 查看是否添加成功
- chkconfig --list php-fpm
- vi /usr/lib/systemd/system/php-fpm.service
- [Unit]
- Description=php-fpm server daemon
- After=network.target sshd-keygen.target
- [Service]
- Type=forking
- ExecStart=/etc/init.d/php-fpm start
- ExecStop=/etc/init.d/php-fpm stop
- ExecReload=/bin/kill -HUP $MAINPID
- [Install]
- WantedBy=multi-user.target
- systemctl daemon-reload
复制代码 编译碰到以下问题解决办法
- #configure: error: Package requirements (libxml-2.0 >= 2.7.6) were not met:
- #Package ‘libxml-2.0’, required by ‘virtual:world’, not found
- yum install libxml2-devel -y
- #configure: error: Package requirements (krb5-gssapi krb5) were not met:
- #Package 'krb5-gssapi', required by 'virtual:world', not found
- #Package 'krb5', required by 'virtual:world', not found
- yum install krb5-devel -y
- #configure: error: Package requirements (openssl >= 1.0.1) were not met:
- #Package 'openssl', required by 'virtual:world', not found
- yum install openssl-devel -y
- #configure: error: Package requirements (sqlite3 > 3.7.4) were not met:
- #Package 'sqlite3', required by 'virtual:world', not found
- yum install sqlite-devel -y
- #configure: error: Please reinstall the BZip2 distribution
- yum -y install bzip2-devel
- #configure: error: Package requirements (libcurl >= 7.15.5) were not met:
- #Package 'libcurl', required by 'virtual:world', not found
- yum install libcurl-devel -y
- #configure: error: Package requirements (oniguruma) were not met:
- #Package 'oniguruma', required by 'virtual:world', not found
- yum config-manager --set-enabled PowerTools
- yum -y install oniguruma oniguruma-devel
- #configure: error: Package requirements (libxslt >= 1.1.0) were not met:
- #Package 'libxslt', required by 'virtual:world', not found
- yum install libxslt-devel -y
- #configure: error: Package requirements (libpng) were not met:
- #Package 'libpng', required by 'virtual:world', not found
- yum install libpng-devel -y
- #configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:
- #Package 'libzip', required by 'virtual:world', not found
- #Package 'libzip', required by 'virtual:world', not found
- #Package 'libzip', required by 'virtual:world', not found
- yum install libzip-devel -y
复制代码
3、编译安装拓展包
- #进入源代码中ext文件夹下需要编译的拓展的文件夹中,比如编译gd,则进入源代码ext文件夹下的gd
- #编译好后的php安装目录下的phpize,执行后生成configure文件
- /usr/local/php74/bin/phpize
- #进行配置
- ./configure --with-php-config=/usr/local/php74/bin/php-config
- #编译
- make&make install
- #make中可能报以下错误
- #PHP编译安装报错,make:*libtool: link: `ext/libxml/libxml.lo‘ is not a valid libtool object
- #把 php的源代码目录(你make过的)删掉, 再解压, 然后再 make 应该就 ok 了
- #编译安装完成后会显示一个目录
- Installing shared extensions: /usr/local/php74/lib/php/extensions/no-debug-non-zts-20190902/
- #编辑php.ini,编译的php一般都是在其安装目录下有一个etc文件夹,里面有一个php.ini
- #此处为/usr/local/php74/etc/php.ini
- #将/usr/local/php74/lib/php/extensions/no-debug-non-zts-20190902/目录添加到php.ini,大概有一个extension_dir=xxx,在其下面添加一行,把编译好后的路径添加上
- extension_dir=/usr/local/php74/lib/php/extensions/no-debug-non-zts-20190902/
- #再找到对应的模块启用
- #对应模块显示类似为为;extension=gd,去掉前面的分号保存,如果没有则手动添加
- extension=gd
- #重新启动php
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |