美文网首页
yum安装nginx,mysql,php

yum安装nginx,mysql,php

作者: 冷掌柜 | 来源:发表于2021-05-13 19:26 被阅读0次

centos7

一、安装nginx

1.使用yum安装nginx,安装nginx库
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2.命令安装nginx
yum -y install nginx
3.启动nginx
systemctl start nginx   #centos7
查看nginx版本
nginx -v
4.防火墙
防火墙允许通过80端口,查看防火墙状态
systemctl status firewalld
查看防火墙开发端口
netstat -anp
查询是否开启80端口 
firewall-cmd --query-port=80/tcp
开通80端口
 firewall-cmd --zone=public --add-port=80/tcp --permanent 
重启防火墙
systemctl start firewalld

##nginx报错
nginx: [error] open() "/var/run/nginx.pid" failed (2: No such file or direct
方法1.创建默认目录 /var/run/nginx/ ;
          然后cd /sbin目录; 
          运行 ./nginx -c /etc/nginx/nginx.conf
方法2.修改 nginx.conf 文件,指定 pid文件 所在目录。
(1)进入 cd /usr/local/nginx/conf/ 目录,编辑配置文件nginx.conf ;
(2)在配置文件中有个注释的地方: #pid        logs/nginx.pid,  
(3)将注释放开,并修改为:pid    /usr/local/nginx/logs/nginx.pid;
(4)在 /usr/local/nginx 目录下创建 logs 目录:mkdir /usr/local/nginx/logs
(5)在/usr/sbin 下重启nginx

##nginx /etc/nginx/conf.d中虚拟机配置
server {
    listen       80;
    server_name  www.xxx.com;
    index index.html index.htm index.php default.html default.htm default.php;
    root /xxx/xxx/xxx/;  项目目录

    access_log  /var/log/nginx/xxx.log  main;

    location / {
        # root   /usr/share/nginx/html;
        # root /vagrant/blog/public/;
        index  index.html index.htm index.php;
        try_files $uri $uri/ /index.php?$query_string;
    }
    error_page  404              /404.html;
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    location ~ \.php$ {
    #    root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
    location ~ /\.ht {
        deny  all;
    }
}

安装mysql(centos7)

1.去官网下载yum仓库文件
#配置好yum源,包括epel源
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
#将复制的连接地址下载
[root@localhost ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
[root@localhost ~]# ls
anaconda-ks.cfg  mysql80-community-release-el7-3.noarch.rpm

2.安装yum仓库文件
#可是使用rpm -ivh或者是yum localinstall 去安装,两者实质是一样的
[root@localhost ~]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm
#安装完成后可以看到mysql的repo文件
[root@localhost ~]# ls /etc/yum.repos.d/
CentOS-Base.repo  epel.repo  mysql-community.repo  mysql-community-source.repo

3.版本选择
 [root@localhost ~]# yum repolist enabled | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community                 185
mysql-tools-community/x86_64      MySQL Tools Community                      123
mysql80-community/x86_64          MySQL 8.0 Community Server                 229
# 安装 YUM 管理工具包,此包提供了 yum-config-manager 命令工具
[root@localhost ~]# yum -y install yum-utils
[root@localhost ~]# yum-config-manager --disable mysql80-community
[root@localhost ~]# yum-config-manager --enable mysql57-community
#查看默认启动的仓库
[root@localhost ~]# yum repolist enabled | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community                 185
mysql-tools-community/x86_64      MySQL Tools Community                      123
mysql57-community/x86_64          MySQL 5.7 Community Server                 484
4.安装
[root@localhost ~]# yum install -y  mysql-community-server
5.设置默认配置
在/etc/my.cnf的文件中设置
[mysqld]
......
#添加下面几行,设置默认引擎编码和排序规则
default-storage-engine=INNODB
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
skip-character-set-client-handshake
secure_file_priv='' 
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
6.启动服务
# 启动
systemctl start mysqld
# 查看状态
systemctl status mysqld
# 开机自启动
systemctl enable mysqld
# 查看监听端口,默认 3306
ss -natl |grep 3306

7.初始化
MySQL服务器初始化(从MySQL 5.7开始):
在 MySQL 服务器初始启动时,如果服务器的数据目录为空,则会发生以下情况:
(1)MySQL 服务器已初始化。
(2)在数据目录中生成SSL证书和密钥文件。
(3)安装并启用该 validate_password 插件。
(4)将创建一个超级用户 帐户'root'@'localhost'。并会设置超级用户的密码,将其存储在错误日志文件/var/log/mysqld.log中。
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log
2021-01-25T04:26:33.010077Z 1 [Note] A temporary password is generated for root@localhost: *sH2qhGeN(eB

8.修改初始密码
日志中(/var/log/mysqld.log)得到的密码登录
要设置比较简单的密码就需要取消密码复杂度
编辑 my.cnf配置文件, 在 [mysqld]配置块儿中添加如下内容
plugin-load=validate_password.so 
validate-password=OFF

9.远程连接
方法一:远程登录还需要授权远程登录
Mysql默认不允许远程登录,我们需要设置关闭selinux或者防火墙,不关防火墙就开放3306端口;
 mysql> grant all privileges on *.* to root@localhost identified by '数据库密码';
 Query OK, 0 rows affected, 1 warning (0.00 sec)
#放开3306端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
方法二:(常用)
mysql> use mysql;
Database changed
mysql> update user set host=’%’ where user=’root’;
mysql> flush privileges;
重启mysql

安装php

1.[root@10 ~]# yum install epel-release
2.[root@10 ~]# yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
3.[root@10 ~]# yum -y install yum-utils
4.[root@10 ~]# yum repolist all |grep php
5.[root@10 ~]# yum-config-manager --enable remi-php74
6.[root@10 ~]# yum install php  php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-redis
7.[root@10 ~]# systemctl start php-fpm
8.[root@10 ~]# php -v

centos8

安装php74

1.添加几个源,不然会报错 #php高版本的yum源地址,有两部分,其中一部分是epel-release,另外一部分来自webtatic。如果跳过epel-release的话,安装webtatic的时候
2.rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
3.rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-8.rpm
4.yum update 更新yum源
5.yum install yum-utils
# 安装
yum install php74-php
#安装php拓展
yum install php74-php-gd php74-php-pdo php74-php-mbstring php74-php-cli php74-php-fpm php74-php-mysqlnd php74-php-zip php74-php-dom php74-php-bcmath
# 通过grep查找扩展
yum search php74* | grep swoole

# 命令
systemctl restart php74-php-fpm #重启
systemctl start php74-php-fpm #启动
systemctl stop php74-php-fpm #关闭
systemctl status php74-php-fpm #检查状态
php -m #查看PHP已安装拓展模块
php -v #查看PHP版本

安装nginx

8.yum install nginx

安装mysql8.0.25

#下载
wget https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm
#安装数据源
 yum install mysql80-community-release-el8-1.noarch.rpm
#检查数据源
yum repolist enabled | grep "mysql.*-community.*"
#禁用CentOS8自带mysql模块
yum module disable mysql
#安装数据库
yum install mysql-community-server
#启动mysql
service mysqld start
service mysqld status
#显示mysql的随机密码
grep 'temporary password' /var/log/mysqld.log
#登录mysql
mysql -u root -p
#修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Test_123456';
#查看密码策略
SHOW VARIABLES LIKE 'validate_password%';
#开放远程访问
#1.创建权限用户记录
create user 'root'@'%' identified by 'Test_123456';
#2. 授权
grant all privileges on *.* to 'root'@'%' with grant option;

安装mysql57

1、删除mysql8.0
yum remove mysql
2、删除共享Lib库
rm -R /var/lib/mysql
3、安装mysql5.7
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
// 先禁用本地的 MySQL 模块在安装即可
yum module disable mysql
// 安装
yum -y install mysql-community-server
授权远程登录
mysql>use mysql;
msyql>update user set user.Host='%' where user.User='root';
mysql>flush privileges;

systemctl start mysqld.service    启动mysql
systemctl status mysqld.service  查看mysql状态
systemctl stop mysqld.service   关闭mysql

相关文章

网友评论

      本文标题:yum安装nginx,mysql,php

      本文链接:https://www.haomeiwen.com/subject/prfmkltx.html