首页 > 数据库 >Ubuntu 22.04 LTS 安装最新稳定版本nginx、mysql5.7和php7.2

Ubuntu 22.04 LTS 安装最新稳定版本nginx、mysql5.7和php7.2

时间:2023-11-16 18:34:40浏览次数:45  
标签:LTS etc mysql5.7 ubuntu php7.2 apt nginx mysql

Ubuntu 22.04 LTS 安装最新稳定版本nginx、mysql5.7和php7.2

全部apt-get安装,就是快,迅速。前提是需要在有网络环境的情况下哈!!
操作系统版本:Ubuntu 22.04 LTS

image

一、安装最新稳定版本的nginx

apt-get update
# 查看默认安装的nginx版本(默认为1.18。有点老,我们安装最新稳定版本)
apt-cache policy nginx
# 修改apt源,在最后添加(:wq保存退出)
vim /etc/apt/sources.list
# NGINX
deb http://nginx.org/packages/ubuntu jammy nginx
deb-src http://nginx.org/packages/ubuntu jammy nginx
# 导入nginx公钥
wget https://nginx.org/keys/nginx_signing.key
apt-key add nginx_signing.key
# 更新apt源
apt-get update
# 再次查看默认的nginx版本(第一个已经是最新稳定的nginx版本)
apt-cache policy nginx
# 安装nginx
apt-get install nginx
# 查看nginx版本加入开机启动
nginx -V
systemctl enable nginx
systemctl is-enabled nginx

image
image
image
image
image
image

至此ningx安装完成

二、安装mysql5.7版本

可以参考:https://www.cnblogs.com/wltian-one/p/17767082.html
基本是一样的。

# 查看系统默认安装的数据库版本(ubuntu 22.04自带的版本是8.0.35,而我们需要安装mysql5.7的版本就需要换源)
apt-cache policy mysql-server
# 备份原来的sorce文件
cp /etc/apt/sources.list /etc/apt/sources.list_back
# (dG全部删除)
vim /etc/apt/sources.list
#  阿里源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
# 导入mysql公钥
gpg --keyserver keyserver.ubuntu.com --recv 3B4FE6ACC0B21F32
gpg --export --armor 3B4FE6ACC0B21F32 | apt-key add -
# 更新
apt-get update
# 再次查看默认mysql版本
apt-cache policy mysql-server
# 安装mysql
apt-get install mysql-server-5.7
# 查看mysql是否安装成功
dpkg -l | grep mysql
# 设置开机自启
systemctl enable mysql
systemctl is-enabled mysql
# 修改mysql密码(直接输入mysql,此时不需要输入密码)
mysql 
msyql>use mysql;
mysql> alter user root@'localhost' identified with mysql_native_password by "12345678";
mysql> flush privileges;
mysql> exit
# 把镜像源重新换回
rm -f /etc/apt/sources.list
mv /etc/apt/sources.list_back   /etc/apt/sources.list
apt-get update

退出后重新进入就需要输入密码了!

image

image
image
image
image

三、修改mysql数据库数据存储位置(按照实际需求来,可选)

1、先停止mysql服务

systemctl stop mysql

2、创建新的数据存储目录

mkdir /home/mysql
cp -ar /var/lib/mysql/* /home/mysql
chown -R mysql:mysql /home/mysql

image

3、修改mysql配置文件

# 先备份一份
cp -a /etc/mysql/mysql.conf.d/mysqld.cnf /etc/mysql/mysql.conf.d/mysqld.cnf_back
vim /etc/mysql/mysql.conf.d/mysqld.cnf
datadir         = /home/mysql

image

注意:只是修改MySQL的配置文件是不行的,因为Ubuntu有访问控制系统apparmor,所以还需要修改与该访问控制系统相关的文件

4、修改安全保护文件

cp -a /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/usr.sbin.mysqld_back
vim /etc/apparmor.d/usr.sbin.mysqld
把带有/var/lib/mysql
/var/lib/mysql/ r,
/var/lib/mysql/** rwk,
改成
/home/mysql/ r,
/home/mysql/** rwk,

image

5、修改访问控制文件

cp -a /etc/apparmor.d/abstractions/mysql /etc/apparmor.d/abstractions/mysql_back
vim /etc/apparmor.d/abstractions/mysql
/var/lib/mysql{,d}/mysql{,d}.sock rw,
改成
/home/mysql{,d}/mysql{,d}.sock rw,

vim /etc/apparmor.d/tunables/alias
#最后添加
alias /var/lib/mysql/ -> /home/mysql/,

image

6、重启apparmor服务

systemctl restart apparmor

7、开启数据库

systemctl start mysql

8、查看数据库的状态

systemctl status mysql
image

至此mysql数据库安装完成

四、安装php7.2

1、安装 SURY APT 存储库

# 查看默认安装的php
apt-cache policy php

image

# 要在 Ubuntu 22.04 上安装 PHP 7.1/7.2/7.3/7.4,您需要安装 SURY,即提供 PHP 包的第三方存储库。
apt-get -y install software-properties-common
add-apt-repository ppa:ondrej/php --yes
apt-get update
# 查看
apt list|grep php7.2-*

image

2、安装php7.2

apt-get -y install php7.2

下载了php7.2会自动下载apache2,这时候需要我们删除apache2

# 查看apache2
dpkg -l |grep apache2
# 删除
apt-get autoremove apache2
apt-get autoremove apache2-bin
find /etc -name "*apache*" |xargs rm -rf 
rm -rf /var/www
rm -rf /etc/libapache2-mod-jk
rm -rf /etc/init.d/apache2
rm -rf /etc/apache2
# 删除关联
dpkg -l |grep apache2|awk '{print $2}'|xargs dpkg -P
# 再次查看apache2
dpkg -l |grep apache2
# 安装扩展(安装自己的需求)
apt-get install php7.2-curl php7.2-dev php7.2-gd php7.2-mysql php7.2-xml php7.2-xdebug php7.2-redis php7.2-apcu php7.2-intl php7.2-memcached
# 查看
php -v
php -m
dpkg -l | grep php7.2*
# 开机自启
systemctl enable php7.2-fpm

image
image


至此php7.2安装成功

四、nginx调用php7.2

location ~ \.php$ {
        fastcgi_pass   unix:/run/php/php7.2-fpm.sock;
        fastcgi_index  index.php;
        include  fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
}

标签:LTS,etc,mysql5.7,ubuntu,php7.2,apt,nginx,mysql
From: https://www.cnblogs.com/wltian-one/p/17836707.html

相关文章

  • MySQL5.7双主安装
    214、215 两台服务器1.下载MySQL安装包https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.43-linux-glibc2.12-x86_64.tar.gz2.上传至服务器并解压./bin/mysqld--initialize--user=mysql--basedir=/usr/local/mysql--datadir=/data/mysql/data3.配置文件/etc/my......
  • windows安装mysql5.7.24
    下载mysql5.7.24.ziphttps://downloads.mysql.com/archives/community/解压1.安装,管理员权限打开cmd窗口,输入下边命令mysqld--installmysql--defaults-file=D:\mysql-5.7.24-winx64\mysql-5.7.24-winx64\my.ini(注:若出现MSVCR120.dll、MSVCP120.dll缺失,则安装vcredist_x64.exe......
  • mysql5.7安装插件udp(lib_mysqludf_sys)
    项目应用中需要用mysql执行一下命令行.几经搜索可以安装lib_mysqludf_sys插件可以实现本地window环境安装(mysql8.0,64位,使用lib_mysqludf_sys.dll文件)--查看环境中插件目录showvariableslike'%plugin%';--plugin_dir C:/mysql/lib/plugin/--将lib_mysqludf_sys......
  • Docker 树莓派 mysql5.7
    创建my.cnf[mysqld]##server_id=1##binlog-ignore-db=mysql##log-bin=replicas-mysql-bin##binlog_cache_size=1M##binlog_format=mixed##expire_logs_days=7#设置比较表名和数据库名时忽略大小写lower_case_table_names=1max_allowed_packet=125Mmax_c......
  • win版本 mysql5.7 解压安装流程
    win版本mysql5.7解压安装流程https://dev.mysql.com/downloads/mysql/5.7.html#downloads1、添加系统变量变量名:MYSQL_HOME变量值:D:\ProgramData\mysql-5.7.44-winx642、编辑my.inimy.ini[mysqld]basedir=D:\ProgramData\mysql-5.7.44-winx64datadir=D:\ProgramData\mysql-5.7.......
  • php7.2安装swoole扩展
    swoole:  官网: https://www.swoole.com  github: https://github.com/swoole/swoole-src   gitee: https://gitee.com/swoole/swooleyuminstallunzipyuminstallpcre-develautoconfmake1.下载源码包并解压: cd/downloadwgethttps://gitee.com/......
  • Ubuntu LTS 坚持 10 年更新不动摇
    Linux 内核开发者JonathanCorbet此前在欧洲开源峰会上宣布,LTS内核的支持时间将从六年缩短至两年,原因在于缺乏使用和缺乏支持。稳定版内核维护者GregKroah-Hartman也表示“没人用LTS内核”。近日,Ubuntu开发商Canonical发表博客称,他们会坚持为UbuntuLTS版本......
  • Centos7 安装 Mysql5.7
    一、下载mysql5.7的安装包下载地址:https://dev.mysql.com/downloads/mysql/5.7.html①、选择linux版的②、选择64bit,根据自己的情况来看③、选择下载tar包④、点击下载⑤、等待下载完二、上传到服务器上传到服务器有好几种方法,任意采用一种就可以......
  • Numerical Results of TTCGP and iTTCGP
     ......
  • Numerical Results of iTTCGP
     ......