ArcherWong博客
首页
博客
centos笔记-centos7.3配置LNMP
作者:ArcherWong
分类:linux
时间:2019-01-03 21:35:59
阅读:354
[TOC] # 1 源的配置 1.换成国内的源,可以提高下载速度 首先备份/etc/yum.repos.d/CentOS-Base.repo ``` mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup ``` 下载对应版本repo文件, 放入/etc/yum.repos.d/(操作前请做好相应备份) ``` cd /etc/yum.repos.d/ wget http://mirrors.163.com/.help/CentOS6-Base-163.repo ``` 运行以下命令生成缓存 ``` yum clean all yum makecache ``` 参考地址: http://mirrors.163.com/.help/centos.html 2.添加更多的源 CentOS由于很追求稳定性,所以官方源中自带的软件不多,因而需要一些第三方源:epel是对官方源的补充,可以提供更新更丰富的rpm包;官方不提供php7的rpm包,php7有两个源可以选择,一个是webtatic提供的,也就是php70w,另一个可以使用remi源,我使用的是webtatic提供的 安装相应的源(webtatic依赖epel) CentOS/RHEL 7.x: ``` 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 ``` # 2 安装软件 注意:前提是有可用的源,出于安全和稳定等原因,有些软件包是本身的源不具备的 ## 2.1 安装php7 ``` yum install php70w php70w-fpm php70w-mysql ``` php -v //查看是否安装成功 其它一些可以安装的扩展等 ``` yum install php70w-devel yum install php70w-pdo php70w-xml php70w-mbstring ``` ## 2.2 安装nginx ``` yum install nginx nginx -v ``` ## 2.3 安装mysql ``` yum install mariadb-server -y //安装 systemctl start mariadb.service //启动 systemctl enable mariadb.service //设置开机启动 mysql_secure_installation //初始化设置 ``` ## 2.4 安装vsftp (ftp登录配置) ``` yum install vsftpd ``` 相关操作 禁止匿名登陆 `vim /etc/vsftpd/vsftpd.conf` 将配置文件中第11行 ``` anonymous_enable=YES anonymous_enable=NO ``` 允许root账户登录,编辑/etc/vsftpd/user_list和/etc/vsftpd/ftpusers两个设置文件脚本,将root账户前加上#号变为注释。(即让root账户从禁止登录的用户列表中排除) 开启vsftpd ``` service vsftpd start ``` 本地客户端filezilla,百度自行下载配置 # 3 开机启动设置 ``` systemctl enable mariadb.service systemctl enable php-fpm.service systemctl enable nginx.service systemctl enable vsftpd.service ``` 相关操作 查看开机启动情况 ``` systemctl list-unit-files systemctl list-unit-files | grep fpm ``` 设置为开机启动 ``` systemctl enable mariadb.service ``` 取消开机启动 ``` systemctl disable mariadb.service ``` # 4 其它一些配置 ## 4.1 git的设置 下载git ``` yum install git ``` 生成密钥,位置在~/.ssh文件夹下 ``` ssh-keygen -t rsa -C "your_email@example.com" ``` 全局配置 ``` git config [--global] user.name "name" git config [--global] user.email "email address" ``` ## 4.2 mysql本地登录 步骤: 登陆mysql ``` mysql -uroot -p123456 ``` 切换到mysql这个数据库 ``` mysql> use mysql; ``` 查看root用户配置 ``` mysql> select host,user from user where user='root'; ``` 如果查询结果中不包含以下记录,请添加,否则请忽略次步骤 ``` +--------------------+------+ | host | user | +--------------------+------+ | % | root | +--------------------+------+ ``` 添加方法: mysql> update user set host = '%' where user = 'root' and host = '127.0.0.1'; ``` +--------------------+------+ | host | user | +--------------------+------+ | % | root | | ::1 | root | | localhost | root | | vm\_33\_19\_centos | root | +--------------------+------+ ``` 使配置生效 ``` mysql> flush privileges; ``` 配置完成,客户端重新登录成功; ## 4.3 基本nginx配置 ``` server{ #分别写了www和不带www的域名 server_name www.zhengde.site zhengde.site; listen 80; #工程根目录 root /var/data/blog/; charset UTF-8; #日志文件位置,自己选择 access_log /var/log/nginx/blog/access.log; error_log /var/log/nginx/blog/error.log; index index.php index.html index.htm; #error_page 500 502 503 504 404 /missing.html; #error_page 403 =404 /missing.html; #主要作用是xxxx/index.php/控制器/方法,一般的index.php是隐藏的,不写这句就找不到了 location / { try_files $uri /index.php$is_args$args; } location ~ \.php$ { #这个要看你监听的位置 fastcgi_pass unix:/run/php/php7.0-fpm.sock; #二选一,第一种写法 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; #二选一,第二种写法,但是需要在外层创建 fastcgi.conf文件 # include fastcgi.conf; } } ``` ## 4.4 certbot安装(用于生成https证书,不用可忽略) ``` sudo yum install certbot-nginx certbot certonly --webroot -w /data/blog -d xxxx.cn -w /data/blog -d www.xxxx.cn -w /data/blog -d xxxx.cn -w /data/blog -d www.xxxx.cn ```
标签:
上一篇:
letsencrypt证书-使用certbot申请wildcard证书
下一篇:
centos笔记-linux操作
文章分类
css
elasticsearch
git
golang
guacamole
javascript
letsencrypt
linux
nginx
other
php
python
vue
web
阅读排行
golang笔记---关联数组(map)
centos7.3配置guacamole
letsencrypt证书-管理工具certbot
golang笔记---template模板语法
nginx笔记-proxy_cache缓存详解
友情链接
node文件
laravel-vue
ArcherWong的博客园