在Linux系统上进行LNMP(Linux, Nginx, MySQL/MariaDB, PHP)的版本升级,通常需要分别对每个组件进行更新。以下是详细的升级步骤和注意事项:
备份当前配置:
sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup
下载新版本:
访问Nginx官方网站获取最新版本号,例如nginx-1.20.1
。
编译安装:
cd /usr/local/src
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
备份数据库:
mysqldump -u root -p all > all_databases.sql
下载新版本:
访问MySQL官方网站获取最新版本号,例如mysql-8.0.26
。
编译安装:
cd /usr/local/src
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 && make install
配置并启动MySQL:
cp support-files/mysql.server /etc/init.d/mysql
systemctl start mysql
systemctl enable mysql
备份当前配置:
cp /usr/local/php/etc/php.ini /usr/local/php/etc/php.ini.backup
下载新版本:
访问PHP官方网站获取最新版本号,例如php-7.4.26
。
编译安装:
cd /usr/local/src
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 && 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
以上步骤和注意事项为一般性指导,具体操作可能会因Linux发行版和版本的不同而有所差异。在执行升级操作时,请参考相应发行版的官方文档或寻求专业人士的帮助。