阿里云轻量应用服务器wordpress升级php步骤

1.首先更新依赖包。

yum -y update


2.安装依赖包

yum -y 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 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 libzip gcc-c++

yum -y install sqlit3-devel
configure时检测时如果遇到缺少包,一般是缺少对应的devel包,如上安装sqlite-devel一样处理。

3.转到 /usr/local/src 目录,下载php7.3.5

cd /usr/local/src
wget https://www.php.net/distributions/php-7.3.5.tar.gz

4.解压安装包,并进入目录

tar -zxvf php-7.3.5.tar.gz
cd php-7.3.5

5.添加用户和组

groupadd www
useradd -g www www

6.开始编译

./configure --prefix=/usr/local/php --with-fpm-user=www --with-fpm-group=www --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-pdo-sqlite --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

这里会提示 configure: error: Please reinstall the libzip distribution,我们需要移除libzip,手动安装最新版本

7.安装libzip

(1)先安装cmake(在阿里云centos不需要这一步)

cd /usr/local/src
wget https://github.com/Kitware/CMake/releases/download/v3.14.3/cmake-3.14.3.tar.gz
tar -zxvf cmake-3.14.3.tar.gz
cd cmake-3.14.3
./bootstrap
make && make install

(2)再编译安装libzip(在阿里云centos不需要这一步)

yum remove libzip -y
cd /usr/local/src
wget https://libzip.org/download/libzip-1.5.2.tar.gz
tar -zxvf libzip-1.5.2.tar.gz
cd libzip-1.5.2
mkdir build
cd build
cmake ..
make && make install

(3)执行以下命令

vi /etc/ld.so.conf

添加如下几行

/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64

保存退出

ldconfig -v # 使之生效
  1. 再次编译PHP7.3
make && make install

9.编译完成后,添加环境变量

vi /etc/profile
PATH=$PATH:/usr/local/php/bin
export PATH

刷新环境变量

source /etc/profile

10.配置文件

将启动脚本复制到init.d中。

cp /usr/local/src/php-7.3.5/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm73

给启动脚本加上执行权限

chmod +x /etc/init.d/php-fpm73

将默认配置文件复制为.conf文件

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

添加pool的配置

cat << EOF > /usr/local/php/etc/php-fpm.d/www.conf
[www]
listen = /home/www/logs/php73-fpm.sock
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 128
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 15
pm.max_requests = 300
rlimit_files = 1024
slowlog = /home/www/logs/php73-fpm-slow.log
EOF


11.修改apache

镜像中默认是用的php-fpm,使用的是socket方式的监听,Apache对应配置文件/usr/local/apache/conf/httpd.conf

修改指定位置为:

ProxyPassMatch ^/(..php(/.)?)$ unix:/home/www/logs/php73-fpm.sock|fcgi://127.0.0.1/home/www/htdocs

12.重启服务

停止旧版本的PHP(实际不停止也不影响,停止可以减少一些系统资源占用)

/etc/init.d/php-fpm stop

启动新版PHP-FPM

/etc/init.d/php-fpm73 start

启动报错请修改文件名

修改/usr/local/php/etc/php-fpm.conf.default为php-fpm.conf

重启apache

/etc/init.d/apachectl restart

修改自启动

chkconfig --del php-fpm
chkconfig --add php73-fpm

参考https://blog.csdn.net/qq_43701912/article/details/107020920,中间根据个人情况进行修改。

virtual memory exhausted: Cannot allocate memory

一、问题
       当安装虚拟机时系统时没有设置swap大小或设置内存太小,编译程序会出现virtual memory exhausted: Cannot allocate memory的问题,可以用swap扩展内存的方法。

二、解决方法
在执行free -m的是时候提示Cannot allocate memory:(swap文件可以放在自己喜欢的位置如/var/swap)

[root@Byrd byrd]# free -m
total used free shared buffers cached
Mem: 512 108 403 0 0 28
-/+ buffers/cache: 79 432
Swap: 0 0 0
[root@Byrd ~]# mkdir /opt/images/
[root@Byrd ~]# rm -rf /opt/images/swap
[root@Byrd ~]# dd if=/dev/zero of=/opt/images/swap bs=1024 count=2048000
2048000+0 records in
2048000+0 records out
2097152000 bytes (2.1 GB) copied, 82.7509 s, 25.3 MB/s
[root@Byrd ~]# mkswap /opt/images/swap
mkswap: /opt/images/swap: warning: don't erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 2047996 KiB
no label, UUID=59daeabb-d0c5-46b6-bf52-465e6b05eb0b
[root@hz mnt]# swapon /opt/images/swap
[root@hz mnt]# free -m
total used free shared buffers cached
Mem: 488 481 7 0 6 417
-/+ buffers/cache: 57 431
Swap: 999 0 999

内存太小,增加内存可以解决。
使用完毕后可以关掉swap:

[root@hz mnt]# swapoff swap
[root@hz mnt]# rm -f /opt/images/swap


swap文件也可以不删除,留着以后使用,关键是你的虚拟机硬盘够用。

原文链接:https://blog.csdn.net/taiyang1987912/article/details/41695895/