CentOS 7安装php7.4

打印 上一主题 下一主题

主题 695|帖子 695|积分 2085

1、yum安装

  1. #安装依赖
  2. yum install epel-release
  3. #启用PHP 7.4 Remi存储库并在CentOS 7上安装PHP 7.4
  4. #配置安装源
  5. yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
  6. yum -y install yum-utils
  7. #设置安装版本
  8. yum-config-manager --enable remi-php74
  9. #安装php及拓展包
  10. 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
  11. #查看php版本
  12. php -v
  13. #启动php
  14. systemctl start php-fpm
  15. #php配置文件
  16. vi /etc/php.ini
  17. #修改php上传限制,默认为2M
  18. upload_max_filesize = 500M
复制代码
2、编译安装

1、安装依赖包

  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、安装编译工具

  1. yum groupinstall 'Development Tools'
复制代码
3、下载解压

  1. wget http://mirrors.sohu.com/php/php-7.4.9.tar.gz
  2. #此处目录为root
  3. tar -zxvf php-7.4.9.tar.gz
  4. cd php-7.4.9
  5. #编译
  6. ./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
  7. #make
  8. make&make install
  9. #设置环境变量
  10. vi /etc/profile
  11. #添加以下内容
  12. export PATH=$PATH:/usr/local/php74/bin
  13. source /etc/profile
  14. cp php.ini-production /usr/local/php74/etc/php.ini
  15. cd /usr/local/php74/etc
  16. cp php-fpm.conf.default php-fpm.conf
  17. cp php-fpm.d/www.conf.default php-fpm.d/www.conf
  18. ln -s /usr/local/php74/sbin/php-fpm /usr/sbin/
  19. # 启动 php-fpm
  20. php-fpm
  21. # 查看进程
  22. ps -ef | grep php-fpm
  23. ps -aux | grep php-fpm
  24. # 查看相关进程数量
  25. ps -ef | grep php-fpm | grep -v grep | wc -l
  26. # 查看端口
  27. netstat -tnl | grep 9000
  28. # 将源码目录 sapi/fpm 下的 init.d.php-fpm 复制到 /etc/init.d 目录下并改名为 php-fpm
  29. cp /root/php-7.4.9/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
  30. #添加可执行权限
  31. chmod u+x /etc/init.d/php-fpm
  32. # 添加系统服务
  33. chkconfig --add php-fpm
  34. # 开启服务
  35. chkconfig php-fpm on
  36. # 查看是否添加成功
  37. chkconfig --list php-fpm
  38. vi /usr/lib/systemd/system/php-fpm.service
  39. [Unit]
  40. Description=php-fpm server daemon
  41. After=network.target sshd-keygen.target
  42. [Service]
  43. Type=forking
  44. ExecStart=/etc/init.d/php-fpm start
  45. ExecStop=/etc/init.d/php-fpm stop
  46. ExecReload=/bin/kill -HUP $MAINPID
  47. [Install]
  48. WantedBy=multi-user.target
  49. systemctl daemon-reload
复制代码
编译碰到以下问题解决办法
  1. #configure: error: Package requirements (libxml-2.0 >= 2.7.6) were not met:
  2. #Package ‘libxml-2.0’, required by ‘virtual:world’, not found
  3. yum install libxml2-devel -y
  4. #configure: error: Package requirements (krb5-gssapi krb5) were not met:
  5. #Package 'krb5-gssapi', required by 'virtual:world', not found
  6. #Package 'krb5', required by 'virtual:world', not found
  7. yum install krb5-devel -y
  8. #configure: error: Package requirements (openssl >= 1.0.1) were not met:
  9. #Package 'openssl', required by 'virtual:world', not found
  10. yum install openssl-devel -y
  11. #configure: error: Package requirements (sqlite3 > 3.7.4) were not met:
  12. #Package 'sqlite3', required by 'virtual:world', not found
  13. yum install sqlite-devel -y
  14. #configure: error: Please reinstall the BZip2 distribution
  15. yum -y install bzip2-devel
  16. #configure: error: Package requirements (libcurl >= 7.15.5) were not met:
  17. #Package 'libcurl', required by 'virtual:world', not found
  18. yum install libcurl-devel -y
  19. #configure: error: Package requirements (oniguruma) were not met:
  20. #Package 'oniguruma', required by 'virtual:world', not found
  21. yum config-manager --set-enabled PowerTools
  22. yum -y install oniguruma oniguruma-devel
  23. #configure: error: Package requirements (libxslt >= 1.1.0) were not met:
  24. #Package 'libxslt', required by 'virtual:world', not found
  25. yum install libxslt-devel -y
  26. #configure: error: Package requirements (libpng) were not met:
  27. #Package 'libpng', required by 'virtual:world', not found
  28. yum install libpng-devel -y
  29. #configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:
  30. #Package 'libzip', required by 'virtual:world', not found
  31. #Package 'libzip', required by 'virtual:world', not found
  32. #Package 'libzip', required by 'virtual:world', not found
  33. yum install libzip-devel -y
复制代码


3、编译安装拓展包

  1. #进入源代码中ext文件夹下需要编译的拓展的文件夹中,比如编译gd,则进入源代码ext文件夹下的gd
  2. #编译好后的php安装目录下的phpize,执行后生成configure文件
  3. /usr/local/php74/bin/phpize
  4. #进行配置
  5. ./configure --with-php-config=/usr/local/php74/bin/php-config
  6. #编译
  7. make&make install
  8. #make中可能报以下错误
  9. #PHP编译安装报错,make:*libtool: link: `ext/libxml/libxml.lo‘ is not a valid libtool object
  10. #把 php的源代码目录(你make过的)删掉, 再解压, 然后再 make 应该就 ok 了
  11. #编译安装完成后会显示一个目录
  12. Installing shared extensions:     /usr/local/php74/lib/php/extensions/no-debug-non-zts-20190902/
  13. #编辑php.ini,编译的php一般都是在其安装目录下有一个etc文件夹,里面有一个php.ini
  14. #此处为/usr/local/php74/etc/php.ini
  15. #将/usr/local/php74/lib/php/extensions/no-debug-non-zts-20190902/目录添加到php.ini,大概有一个extension_dir=xxx,在其下面添加一行,把编译好后的路径添加上
  16. extension_dir=/usr/local/php74/lib/php/extensions/no-debug-non-zts-20190902/
  17. #再找到对应的模块启用
  18. #对应模块显示类似为为;extension=gd,去掉前面的分号保存,如果没有则手动添加
  19. extension=gd
  20. #重新启动php
复制代码









免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

正序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

麻花痒

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表