Linux搭建LNMP环境
安装环境
- CentOS 7 Linux系统安装nginx,php,mysql简写为LNMP
磨刀不误砍柴功,准备工作做好
关闭selinux
plaintext
1 |
|
修改成SELinux=disabled,需要重启系统生效
检查网络连通性,保证设备能访问外网
plaintext
1 |
|
关闭防火墙
plaintext
1 |
|
如果遇到这样的报错Failed to start firewalld.service: Unit not found.解决办法如下(依次执行)
plaintext
1 |
|
配置阿里云yum源
安装wget
plaintext
1 |
|
备份原来的yum源
plaintext
1 |
|
plaintext
1 |
|
plaintext
1 |
|
配置阿里云yum源
plaintext
1 |
|
plaintext
1 |
|
清里yum缓存(重要)
plaintext
1 |
|
方法一:编译安装nginx(更适合专业人员)
安装c++编译环境
plaintext
1 |
|
安装openssl,pcre,zlib,vim,httpd-tools
plaintext
1 |
|
编译安装nginx
plaintext
1 |
|
plaintext
1 |
|
plaintext
1 |
|
plaintext
1 |
|
plaintext
1 |
|
环境变量部分,配置好了就可以在任何目录执行nginx命令,感觉很有必要
查看nginx安装目录
plaintext
1 |
|
配置环境变量
plaintext
1 |
|
里面写
plaintext
1 |
|
重新ssh连接使环境变量生效,不用重启系统
检查nginx环境变量是否配置成功,出现/usr/local/nginx/sbin就成功了,即出现你的安装路径/sbin
plaintext
1 |
|
方法二:rpm包安装(简单)
下载rpm包
plaintext
1 |
|
安装,默认安装路径/etc/nginx
plaintext
1 |
|
启动
plaintext
1 |
|
开机自启(记得关selinux,上面有)
plaintext
1 |
|
浏览器访问虚拟机或者服务器ip,出现Welcome to nginx!就安装成功啦
基本操作命令
相关常用指令及参数
参数 | 释义 |
---|---|
nginx -h/-? | 输出nginx的帮助信息 |
nginx -v | 输出nginx版本信息 |
nginx -t | 检查nginx配置文件语法是否正确 |
nginx -T | 检查配置输出配置信息 |
nginx -s [参数] | 参数=stop,quit,reopen,reload |
nginx -c | 设置自定义的nginx配置文件路径 |
nginx -g | 设置覆盖一些默认的参数 |
nginx -q | 检测配置文件期间屏蔽非错误信息 |
启动nginx
plaintext
1 |
|
访问ip:80,能访问则启动成功
停止nginx
plaintext
1 |
|
平滑重启
plaintext
1 |
|
查看nginx相关进程
plaintext
1 |
|
每次启动nginx前记得检查配置文件语法,ok就是没有问题
plaintext
1 |
|
安装php7.0
添加epel第三方依赖库,安装YUM源
plaintext
1 |
|
plaintext
1 |
|
plaintext
1 |
|
plaintext
1 |
|
安装PHP相关依赖库和模块
plaintext
1 |
|
检查php版本
plaintext
1 |
|
启动php-fpm,并设置开机自启
plaintext
1 |
|
安装mysql
下载mysql压缩包
plaintext
1 |
|
解压
plaintext
1 |
|
本地安装MySQL
plaintext
1 |
|
查看MySQL版本
plaintext
1 |
|
重启MySQL,并设置开启自启
plaintext
1 |
|
获取密码,最后一段就是密码
plaintext
1 |
|
登录MySQL
plaintext
1 |
|
先设置一个复杂的密码
plaintext
1 |
|
修改密码规则
plaintext
1 |
|
现在可以设置简单的密码
plaintext
1 |
|
进入MySQL数据库
plaintext
1 |
|
修改权限、允许远程登陆
plaintext
1 |
|
plaintext
1 |
|
plaintext
1 |
|
plaintext
1 |
|
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 🏰linlink~个人笔记🏰!