centos 编译安装php7 centos怎么安装软件包
很多朋友对于centos 编译安装php7和centos怎么安装软件包不太懂,今天就由小编来为大家分享,希望可以帮助到大家,下面一起来看看吧!
debian8怎么安装php7
debian8编译安装 php7
目录(?)[-]
Please reinstall the libcurl distributionCannot find OpenSSL
configure error Unable to locate gmph
Can not find recodeh anywhere under usr usrlocal usr optCannot find pspell
Please reinstall the mysql distribution
mcrypth not found Please reinstall libmcryptxml2-config not found
安装编译器
apt-get install build-essential autoconf automake libtool bison re2c获取PHP安装包
wget 安装dev包
apt-get install libxml2-dev libssl-dev libbz2-dev libjpeg-dev libpng-dev libxpm-dev libfreetype6-dev libgmp-dev libgmp3-dev libmcrypt-dev libmysqlclient15-dev libpspell-dev librecode-dev进行编译安装
./buildconf//用来生成configure脚本
./configure\
--prefix=/usr\
--with-config-file-path=/etc\
--enable-mbstring\
--enable-zip\
--enable-bcmath\
--enable-pcntl\
--enable-ftp\
--enable-exif\
--enable-calendar\
--enable-sysvmsg\
--enable-sysvsem\
--enable-sysvshm\
--enable-wddx\
--with-curl\
--with-mcrypt\
--with-iconv\
--with-gmp\
--with-pspell\
--with-gd\
--with-jpeg-dir=/usr\
--with-png-dir=/usr\
--with-zlib-dir=/usr\
--with-xpm-dir=/usr\
--with-freetype-dir=/usr\
--with-t1lib=/usr\
--enable-gd-native-ttf\
--enable-gd-jis-conv\
--with-openssl\
--with-pdo-mysql=/usr\
--with-gettext=/usr\
--with-zlib=/usr\
--with-bz2=/usr\
--with-recode=/usr\
--with-mysqli=/usr/bin/mysql_config
备注:错误1:Cannot find OpenSSL's libraries解决:
确认已安装过 openssl、libssl-dev包,还是会提示该错误;解决办法:
root@test2:~/php-5.3.27# find/-name libssl.so输出结果为:/usr/lib/x86_64-Linux-gnu/libssl.so初步判断它可能只会在/usr/lib/下寻找 libssl.so文件,于是:
ln-s/usr/lib/x86_64-linux-gnu/libssl.so/usr/lib错误2:debian Please reinstall the libcurl distribution解决:
# RetHat CentOS or Fedora使用下面安装命令yum install curl curl-devel
# Debian or Ubuntu使用下面的安装命令
apt-get install curl
apt-get install libcurl4-gnutls-dev
错误3:Unable to locate gmp.h解决:
在下载 gmp源码包,接着./configure&& make&& make install编译安装
make&&make install
报错处理
Please reinstall the libcurl distributionaptitude search libcurl4
aptitude install libcurl4-gnutls-dev
Cannot find OpenSSL’
wget openssl-1.0.2j.tar.gz
cd openssl-1.0.2j
./config
make&& make install
configure: error: Unable to locate gmp.h
sudo apt-get install libgmp-dev libgmp3-devln-s/usr/include/x86_64-linux-gnu/gmp.h/usr/include/gmp.hCan not find recode.h anywhere under/usr/usr/local/usr/opt.
apt-get install librecode-dev
Cannot find pspell
apt-get install libpspell-dev
Please reinstall the mysql distribution
apt-get install libmysqlclient15-dev
mcrypt.h not found. Please reinstall libmcrypt.
apt-get install libmcrypt-dev
xml2-config not found
apt-get install libxml2-dev
Centos7如何安装PHP7最新版
方法一、简单安装(通过yum)
1.安装epel-release
rpm-ivh
2.安装PHP7的rpm源
rpm-Uvh
3.安装PHP7
yum install php70w
方法二、编译安装
1.下载php7
wget-O php7.tar.gz
2.解压php7
tar-xvf php7.tar.gz
3.进入php目录
cd php-7.0.4
4.安装依赖包
#直接复制下面一行(不包括本行)
yum install 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
5.编译配置(如果出现错误,基本都是上一步的依赖文件没有安装所致)
嫌麻烦的可以从这一步起参考PHP官方安装说明:
./configure\
--prefix=/usr/local/php\
--with-config-file-path=/etc\
--enable-fpm\
--with-fpm-user=nginx\
--with-fpm-group=nginx\
--enable-inline-optimization\
--disable-debug\
--disable-rpath\
--enable-shared\
--enable-soap\
--with-libxml-dir\
--with-xmlrpc\
--with-openssl\
--with-mcrypt\
--with-mhash\
--with-pcre-regex\
--with-sqlite3\
--with-zlib\
--enable-bcmath\
--with-iconv\
--with-bz2\
--enable-calendar\
--with-curl\
--with-cdb\
--enable-dom\
--enable-exif\
--enable-fileinfo\
--enable-filter\
--with-pcre-dir\
--enable-ftp\
--with-gd\
--with-openssl-dir\
--with-jpeg-dir\
--with-png-dir\
--with-zlib-dir\
--with-freetype-dir\
--enable-gd-native-ttf\
--enable-gd-jis-conv\
--with-gettext\
--with-gmp\
--with-mhash\
--enable-json\
--enable-mbstring\
--enable-mbregex\
--enable-mbregex-backtrack\
--with-libmbfl\
--with-onig\
--enable-pdo\
--with-mysqli=mysqlnd\
--with-pdo-mysql=mysqlnd\
--with-zlib-dir\
--with-pdo-sqlite\
--with-readline\
--enable-session\
--enable-shmop\
--enable-simplexml\
--enable-sockets\
--enable-sysvmsg\
--enable-sysvsem\
--enable-sysvshm\
--enable-wddx\
--with-libxml-dir\
--with-xsl\
--enable-zip\
--enable-mysqlnd-compression-support\
--with-pear\
--enable-opcache
6.正式安装
make make install
7.配置环境变量
vi/etc/profile
在末尾追加
PATH=$PATH:/usr/local/php/bin
export PATH
执行命令使得改动立即生效
source/etc/profile
8.配置php-fpm
cp php.ini-production/etc/php.ini
cp/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf
cp/usr/local/php/etc/php-fpm.d/www.conf.default/usr/local/php/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm/etc/init.d/php-fpm
chmod+x/etc/init.d/php-fpm
9.启动php-fpm
/etc/init.d/php-fpm start
centos7安装php8,实现php7和php8同时运行
在 CentOS7系统上安装 PHP8,实现与原有 PHP7并存运行的过程,确保系统稳定与程序兼容性。安装步骤如下:
1.进入目录,下载 PHP8.1.25源码。
2.解压源码,准备编译环境。
3.进入解压目录,启动编译过程。
在配置过程中遇到错误,通过先执行特定命令解决,完成编译。
经过一系列配置,最终完成 PHP8的安装。
4.配置 PHP-FPM服务。
5.使用 systemctl启动 PHP-FPM服务,并修改服务文件为 php8-fpm。
创建 php8-fpm.service文件于目录/usr/lib/systemd/system/。
配置文件内容并保存,运行命令启动服务。
6.在 php-fpm.conf中进行其他相关配置。
在网站 vhost配置中,如 nginx配置中,基于两种方式监听:基于 unix socket或基于 tcp。
基于 unix socket通信方式,设置 listen=/dev/shm/php8-cgi.sock,配置 fastcgi_pass unix:/dev/shm/php8-cgi.sock,实现应用层内部通信,速度较快。
基于 tcp监听方式,设置 listen= 127.0.0.1:9008,配置 fastcgi_pass 127.0.0.1:9008,端口需与 nginx配置相匹配。
7.启动 php8-fpm服务,重新运行 nginx,实现通信。
8.添加快捷方式到/usr/bin中,生成别名为 php8的快捷方式,便于使用。
9.添加对两种监听方式的说明与对比:
unix socket监听方式:优点在于速度快、资源消耗少;缺点为稳定性较低,存在数据传输问题。适合在同一台机器上的 nginx和 php-fpm服务。
tcp监听方式:优点为能保证数据的正确性,适合跨服务器场景;缺点为性能不如 unix socket。
通过上述步骤,成功在 CentOS7上安装并配置 PHP8,实现了与 PHP7的并存运行,满足了不同场景下的使用需求。