因为特殊需要,今天要把centos 7里面的php换成到php 7的版本,为了不影响已经安装的其他php版本和程序,这次准备手动编译安装。
第一步:下载php源码
wget https://www.php.net/distributions/php-7.4.33.tar.gz
第二步:安装依赖
如果是第一次安装,可以把需要的依赖都先装一遍,例如下面几个可以先装上。
yum -y install gcc gcc-c++ yum -y install libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel libicu-devel freetype-devel openldap-devel openldap openldap-devel oniguruma-devel libxslt-devel
第三步:编译
编译安装的参数有很多,常用的已经添加,如果需要其他扩展具体可以参考这篇文章:https://www.cnblogs.com/jimmycan/articles/12495557.html,一般按照我这个编译大多数程序都能正常运行。
./configure \ --prefix=/usr/local/php74 \ --with-config-file-path=/usr/local/php74/etc \ --with-config-file-scan-dir=/usr/local/php74/conf.d \ --enable-fpm \ --with-fpm-user=www \ --with-fpm-group=www \ --enable-mysqlnd \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-iconv-dir \ --with-freetype=/usr/local/freetype \ --with-jpeg \ --with-zlib \ --enable-xml \ --disable-rpath \ --enable-bcmath \ --enable-shmop \ --enable-sysvsem \ --enable-inline-optimization \ --with-curl \ --enable-mbregex \ --enable-mbstring \ --enable-intl \ --enable-pcntl \ --enable-ftp \ --enable-gd \ --with-openssl \ --with-mhash \ --enable-pcntl \ --enable-sockets \ --with-xmlrpc \ --with-zip \ --enable-soap \ --with-gettext \ --enable-opcache \ --with-xsl \ --with-pear \ --with-webp
因为我是跳过第二步,直接编译,碰到一个依赖出错就安装哪个。
sqlite扩展依赖安装
yum install sqlite-devel
webp扩展依赖安装
yum install libwebp-devel
mbstring 扩展依赖安装
yum install oniguruma-devel
大概就是缺少什么依赖就安装哪个。
安装
make ZEND_EXTRA_LIBS='-liconv'
make install
这个过程需要一段时间,比较慢。
第四步:配置文件
复制php.ini配置文件并修改。
cp php.ini-production /usr/local/php74/etc/php.ini sed -i 's/post_max_size =.*/post_max_size = 50M/g' /usr/local/php74/etc/php.ini sed -i 's/upload_max_filesize =.*/upload_max_filesize = 50M/g' /usr/local/php74/etc/php.ini sed -i 's/;date.timezone =.*/date.timezone = PRC/g' /usr/local/php74/etc/php.ini sed -i 's/short_open_tag =.*/short_open_tag = On/g' /usr/local/php74/etc/php.ini sed -i 's/;cgi.fix_pathinfo=.*/cgi.fix_pathinfo=0/g' /usr/local/php74/etc/php.ini sed -i 's/max_execution_time =.*/max_execution_time = 300/g' /usr/local/php74/etc/php.ini
添加php-fpm.conf配置
cat >/usr/local/php74/etc/php-fpm.conf<<EOF [global] pid = /usr/local/php74/var/run/php-fpm.pid error_log = /usr/local/php74/var/log/php-fpm.log log_level = notice [www] listen = /usr/local/php74/var/run/php-cgi.sock listen.backlog = -1 listen.allowed_clients = 127.0.0.1 listen.owner = www listen.group = www listen.mode = 0666 user = www group = www pm = dynamic pm.max_children = 10 pm.start_servers = 2 pm.min_spare_servers = 1 pm.max_spare_servers = 6 pm.max_requests = 1024 pm.process_idle_timeout = 10s request_terminate_timeout = 100 request_slowlog_timeout = 0 slowlog = var/log/slow.log EOF
第五步:启动
cp sapi/fpm/init.d.php-fpm /etc/init.d/php74-fpm chmod +x /etc/init.d/php74-fpm chkconfig php74-fpm on /etc/init.d/php74-fpm start
centos 7中编译安装php 7已经安装完成。