升级LNMP(Linux, Nginx, MySQL/MariaDB, PHP)服务器涉及多个组件,每个组件的升级步骤都有所不同。以下是通用的升级步骤和具体组件的升级指南:
通用升级步骤
- 备份数据:在进行任何升级之前,务必备份所有重要数据,包括数据库、配置文件和网站文件。
- 更新系统软件包列表:
sudo apt update
- 查看可用的软件版本:
sudo apt list --upgradable | grep php
- 安装新的软件版本:例如,升级到PHP 7.4:
sudo apt install php7.4 php7.4-mysql php7.4-fpm
- 配置Nginx以使用新的PHP版本:编辑Nginx配置文件以使用新的PHP版本。
sudo nano /etc/nginx/conf.d/your_site.conf
- 重启服务:
sudo systemctl restart nginx sudo systemctl restart php7.4-fpm
- 验证升级:
nginx -v php -v
具体组件的升级指南
Nginx升级
- 备份当前配置文件:
sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup
- 下载新版本并解压:
wget http://nginx.org/download/nginx-1.20.1.tar.gz tar -zxvf nginx-1.20.1.tar.gz cd nginx-1.20.1
- 配置并安装:
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_v2_module make && make install
- 配置并启动Nginx:
cp /usr/local/nginx/conf/nginx.conf /etc/nginx/nginx.conf systemctl restart nginx
MySQL/MariaDB升级
- 备份数据库:
mysqldump -u root -p all > all_databases.sql
- 下载新版本并解压:
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.26.tar.gz tar -zxvf mysql-8.0.26.tar.gz cd mysql-8.0.26
- 配置并安装:
mkdir mysql-files cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_unicode_ci make install
- 配置并启动MySQL:
cp support-files/mysql.server /etc/init.d/mysqlsystemctl start mysqlsystemctl enable mysql
PHP升级
- 备份当前配置文件:
sudo cp /usr/local/php/etc/php.ini /usr/local/php/etc/php.ini.backup
- 下载新版本并解压:
wget http://cn2.php.net/distributions/php-7.4.26.tar.gz tar -zxvf php-7.4.26.tar.gz cd php-7.4.26
- 配置并安装:
./configure --prefix=/usr/local/php --with-mysqlnd --with-openssl --with-curl --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-zlib --with-iconv --with-mcrypt --with-xmlrpc --with-mbstring --with-zip --enable-mbstring --enable-sockets --enable-soap --enable-bcmath --enable-pcntl --enable-ftp --enable-exif --enable-calendar --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-gettext --with-xsl --with-xmlrpc --enable-json make install
- 配置并启动PHP-FPM:
cp /usr/local/php/etc/php-fpm.conf /usr/local/php/etc/php-fpm.conf.backup cp /usr/local/php/etc/php-fpm.d/www.conf /usr/local/php/etc/php-fpm.d/www.conf.backup systemctl restart php-fpm
在进行版本升级时,请务必参考相关软件的官方文档,并在测试环境中进行充分测试,以确保升级的成功和系统的稳定性。