二丫讲梵 二丫讲梵
首页
  • 最佳实践
  • 迎刃而解
  • Nginx
  • Php
  • Zabbix
  • AWS
  • Prometheus
  • Grafana
  • CentOS
  • Systemd
  • Docker
  • Rancher
  • Ansible
  • Ldap
  • Gitlab
  • GitHub
  • Etcd
  • Consul
  • RabbitMQ
  • Kafka
  • MySql
  • MongoDB
  • OpenVPN
  • KVM
  • VMware
  • Other
  • ELK
  • K8S
  • LLM
  • Nexus
  • Jenkins
  • 随写编年
  • 家人物语
  • 追忆青春
  • 父亲的朋友圈
  • 电影音乐
  • 效率工具
  • 博客相关
  • Shell
  • 前端实践
  • Vue学习笔记
  • Golang学习笔记
  • Golang编程技巧
  • 学习周刊
  • Obsidian插件周刊
关于
友链
  • 本站索引

    • 分类
    • 标签
    • 归档
  • 本站页面

    • 导航
    • 打赏
  • 我的工具

    • 备忘录清单 (opens new window)
    • json2go (opens new window)
    • gopher (opens new window)
    • 微信MD编辑 (opens new window)
    • 国内镜像 (opens new window)
    • 出口IP查询 (opens new window)
    • 代码高亮工具 (opens new window)
  • 外站页面

    • 开往 (opens new window)
    • ldapdoc (opens new window)
    • HowToStartOpenSource (opens new window)
    • vdoing-template (opens new window)
GitHub (opens new window)

二丫讲梵

行者常至,为者常成
首页
  • 最佳实践
  • 迎刃而解
  • Nginx
  • Php
  • Zabbix
  • AWS
  • Prometheus
  • Grafana
  • CentOS
  • Systemd
  • Docker
  • Rancher
  • Ansible
  • Ldap
  • Gitlab
  • GitHub
  • Etcd
  • Consul
  • RabbitMQ
  • Kafka
  • MySql
  • MongoDB
  • OpenVPN
  • KVM
  • VMware
  • Other
  • ELK
  • K8S
  • LLM
  • Nexus
  • Jenkins
  • 随写编年
  • 家人物语
  • 追忆青春
  • 父亲的朋友圈
  • 电影音乐
  • 效率工具
  • 博客相关
  • Shell
  • 前端实践
  • Vue学习笔记
  • Golang学习笔记
  • Golang编程技巧
  • 学习周刊
  • Obsidian插件周刊
关于
友链
  • 本站索引

    • 分类
    • 标签
    • 归档
  • 本站页面

    • 导航
    • 打赏
  • 我的工具

    • 备忘录清单 (opens new window)
    • json2go (opens new window)
    • gopher (opens new window)
    • 微信MD编辑 (opens new window)
    • 国内镜像 (opens new window)
    • 出口IP查询 (opens new window)
    • 代码高亮工具 (opens new window)
  • 外站页面

    • 开往 (opens new window)
    • ldapdoc (opens new window)
    • HowToStartOpenSource (opens new window)
    • vdoing-template (opens new window)
GitHub (opens new window)
  • 最佳实践

  • 迎刃而解

  • Nginx

  • Php

  • Zabbix

  • AWS

  • Prometheus

  • Grafana

  • Loki

  • CentOS

    • Linux好用命令之w命令
    • Linux好用命令之top命令
    • Linux好用命令之free命令
    • Linux好用命令之lsof命令
    • Linux好用命令之expect命令
    • Linux好用命令之gzip保留原文件解压缩
    • Linux好用命令之dig命令
    • Linux好用命令之rsync命令
    • Linux好用命令之curl劫持请求的三种方式
    • Linux好用命令之base64命令
    • Linux好用命令之figlet命令
    • Linux好用命令之watch命令
    • 使用trash-cli给Linux服务器加一个回收站的功能
    • CentOS-7中tmp目录的清理规则
    • 用yum的方式快速安装lnmp环境(MySQL5-5&5-7,php5-x&7-x)
      • 1,准备。
      • 2,安装 nginx
      • 3,安装 php
      • 4,安装 mysql
      • 5,添加 nginx 配置
      • 6,测试 php 是否正常运行
      • 1,安装 nginx。
      • 2,安装 mysql5.7
      • 3,安装 php7.1
      • 4,配置 nginx。
    • CentOS系统里TCP状态中TIME_WAIT超过3万的分析与建议
    • CentOS-7如何释放主机根分区的磁盘空间
    • 实践一次抓包看到TCP的三次握手与四次挥手及其他
    • CentOS-arm架构下安装docker
    • Logrotate入门了解及生产实践
    • 为什么不建议Linux用root登陆或启动服务
  • Supervisord

  • Systemd

  • Docker

  • Docker-Compose

  • Rancher

  • Ansible

  • OpenLdap

  • GitLab

  • GitHub

  • Etcd

  • Consul

  • RabbitMQ

  • Kafka

  • Mysql

  • MongoDB

  • OpenVPN

  • Kvm

  • VMware

  • 配置文件详解

  • Other

  • 运维观止
  • CentOS
二丫讲梵
2019-10-14
目录

用yum的方式快速安装lnmp环境(MySQL5-5&5-7,php5-x&7-x)

文章发布较早,内容可能过时,阅读注意甄别。
  • mysql-5.5
  • php-5.x

# 1,准备。

安装 LNMP 之前要安装 EPEL,以便安装源以外的软件,如 Nginx,phpMyAdmin 等

yum install epel-release -y
1

# 2,安装 nginx

yum install nginx -y
systemctl start nginx
systemctl enable nginx
1
2
3

# 3,安装 php

yum install -y php php-devel php-fpm php-mysql php-common php-devel php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt libmcrypt-devel
systemctl start php-fpm
systemctl enable php-fpm
1
2
3

# 4,安装 mysql

yum -y install mariadb mariadb-server
systemctl enable mariadb
systemctl restart mariadb
1
2
3

初始化数据库:

mysql_secure_installation << EOF
Y
123456
123456
Y
Y
Y
Y
EOF
1
2
3
4
5
6
7
8
9

密码是123456。

然后验证一下:

[root@localhost ~]$mysql -u root -p123456 -e 'show databases'
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
1
2
3
4
5
6
7
8

# 5,添加 nginx 配置

[root@jenkins ~]# cat /etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_name  10.0.40.245;
    root   /usr/share/nginx/html;
        location / {
            root   /usr/share/nginx/html;
            index index.php index.html index.htm;
        }
    error_page  404              /404.html;
    # redirect server error pages to the static page /50x.html
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    location ~ \.php$ {
        root           /usr/share/nginx/html;
        try_files $uri =404;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

重启 nginx 即可

# 6,测试 php 是否正常运行

[root@jenkins ~]# cat /usr/share/nginx/html/index.php
<?php
// Show all information, defaults to INFO_ALL
phpinfo();
// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(INFO_MODULES);
?>
1
2
3
4
5
6
7
8

web 访问 index.php

10.0.40.245/index.php

img

  • mysql-5.7
  • php-7.x

# 1,安装 nginx。

安装 nginx 最新源

yum localinstall http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum repolist enabled | grep "nginx*"
1
2

安装 nginx

yum -y install nginx
1

启动 nginx

service nginx start
1

设置 nginx 服务器开机自启动

systemctl enable nginx.service
1

检查开机自动是否设置成功

systemctl list-dependencies | grep nginx
1

浏览器中输入本机 ip, 检测是否安装成功

http://127.0.0.1 (opens new window)

# 2,安装 mysql5.7

安装 mysql 源

yum -y localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
yum repolist enabled | grep "mysql.*-community.*"
1
2

安装 mysql

yum -y install mysql-community-server mysql-community-devel
1

启动 mysql

service mysqld start
1

检查 mysql 启动是否正常

service mysqld status 或者 ps -ef | grep mysql
1

设置 mysqld 服务开机自启动

systemctl enable mysqld.service
1

检查 mysqld 开机自启动是否设置成功

systemctl list-dependencies | grep mysqld
1

mysql5.7 以后的争强了安全机制, 所以使用 yum 安装, 启动会系统会自动生成一个随机的密码, 修改 mysql 密码

查看 mysql 的随机密码

grep 'temporary password' /var/log/mysqld.log
1

使用查询得到的随机密码在终端登录

mysql -u root -p 更改密码(mysql文档规定,密码必须包括大小写字母数字加特殊符号>8位)
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Yourpassword';
1
2

退出 mysql 客户端, 用刚才修改的密码登录确保密码修改成功

exit;
mysql -u root -p
1
2

# 3,安装 php7.1

安装 php 源

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
1
2

检查源是否安装成功

 yum repolist enabled | grep "webtatic*"
1

安装 php 扩展源

yum -y install php71w php71w-fpm
yum -y install php71w-mbstring php71w-common php71w-gd php71w-mcrypt
yum -y install php71w-mysql php71w-xml php71w-cli php71w-devel
yum -y install php71w-pecl-memcached php71w-pecl-redis php71w-opcache
1
2
3
4

验证 php7.1.x 和扩展是否安装成功 验证 php 是否安装成功

php -v
1

验证对应的扩展是否安装成功

php -m
1

设置 php-fpm 并检测 php-fpm 的运行状态 启动 php-fpm

service php-fpm start
1

检查启动是否成功

service php-fpm status
1

设置开机自启动

systemctl enable php-fpm.service
1

检查开机自启动是否设置成功

systemctl list-dependencies | grep php-fpm
ps -ef | grep php-fpm
1
2

# 4,配置 nginx。

$ cat /etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_name  localhost;
    root   /usr/share/nginx/html;
        location / {
            root   /usr/share/nginx/html;
            index index.php index.html index.htm;
        }
    error_page  404              /404.html;
    # redirect server error pages to the static page /50x.html
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    location ~ \.php$ {
        root           /usr/share/nginx/html;
        try_files $uri =404;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
微信 支付宝
上次更新: 2024/07/04, 22:40:37
CentOS-7中tmp目录的清理规则
CentOS系统里TCP状态中TIME_WAIT超过3万的分析与建议

← CentOS-7中tmp目录的清理规则 CentOS系统里TCP状态中TIME_WAIT超过3万的分析与建议→

最近更新
01
学习周刊-总第212期-2025年第21周
05-22
02
从赵心童世锦赛夺冠聊聊我的斯诺克情缘
05-16
03
学习周刊-总第211期-2025年第20周
05-15
更多文章>
Theme by Vdoing | Copyright © 2017-2025 | 点击查看十年之约 | 浙ICP备18057030号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式