raksmart活动促销

分享

写回答

发帖

centos7利用yum安装lnmp的教程(linux+nginx+php7.1+mysql5.7)

Raksmart Raksmart 11432 人阅读 | 12 人回复

发表于 2018-3-24 20:30:06 | 显示全部楼层 |阅读模式

前言
本文主要介绍的是基于centos7进行yum安装lnmp(linux+nginx+php7.1+mysql5.7)的相关教程,文中将一步步介绍的非常详细,下面话不多说了,来一起看看详细的介绍吧。
步骤如下:

yum的安装
  1. yum update
复制代码

yum安装nginx
安装nginx最新源

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

安装nginx

  1. yum -y install nginx
复制代码

启动nginx

  1. service nginx start
复制代码

设置nginx服务器开机自启动

  1. systemctl enable nginx.service
复制代码

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

  1. systemctl list-dependencies | grep nginx
复制代码

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

  1. http://00.00.00.00/
复制代码

使用yum安装mysql5.7
安装mysql源

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

安装mysql

  1. yum -y install mysql-community-server install mysql-community-devel
复制代码

启动mysql

  1. service mysqld start
复制代码

检查mysql启动是否正常

  1. service mysqld status 或者 ps -ef | grep mysql
复制代码

设置mysqld服务开机自启动

  1. systemctl enable mysqld.service
复制代码

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

  1. systemctl list-dependencies | grep mysqld
复制代码

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

  1. grep 'temporary password' /var/log/mysqld.log
复制代码

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

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

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

  1. exit;
  2. mysql -u root -p
复制代码

安装php7.1
安装php源

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

检查源是否安装成功

  1. yum repolist enabled | grep "webtatic*"
复制代码

安装php扩展源

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

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

  1. php -v
复制代码

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

  1. php -m
复制代码

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

  1. service php-fpm star
复制代码

检查启动是否成功

  1. service php-fpm status
复制代码

设置开机自启动

  1. systemctl enable php-fpm.service
复制代码

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

  1. systemctl list-dependencies | grep php-fpm
  2. ps -ef | grep php-fpm
复制代码

nginx配置如下:

  1. server{
  2. listen  80;
  3. server_name youserver;
  4. index index.html index.php;
  5. root /home/public;
  6. #charset koi8-r;
  7. #access_log logs/host.access.log main;
  8. location / {
  9.   index index.html index.htm index.php;
  10.   try_files $uri $uri/ /index.php?$query_string;
  11.   }
  12. error_page 404    /404.html;
  13. # redirect server error pages to the static page /50x.html
  14. #
  15. error_page 500 502 503 504 /50x.html;
  16. location = /50x.html {
  17.   root html;
  18. }
  19. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  20. #
  21. #location ~ .php$ {
  22. # proxy_pass http://127.0.0.1;
  23. #}
  24. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  25. #
  26. location ~ .php$ {
  27.   root   /home/public;
  28.   fastcgi_pass 127.0.0.1:9000;
  29.   fastcgi_index index.php;
  30.   fastcgi_param SCRIPT_FILENAME /home/public$fastcgi_script_name;
  31.   include  fastcgi_params;
  32. }
  33. # deny access to .htaccess files, if Apache's document root
  34. # concurs with nginx's one
  35. #
  36. location ~ /.ht {
  37.   deny all;
  38. }
  39. }
复制代码

回答|共 12 个

穿越古代

发表于 2018-3-26 16:58:56 | 显示全部楼层

这个可以,很不错
回复 支持 反对

使用道具 举报

山不转水转

发表于 2018-3-26 16:59:25 | 显示全部楼层

我能说还是不懂啊
回复 支持 反对

使用道具 举报

普罗旺斯

发表于 2018-3-26 16:59:57 | 显示全部楼层

还是来迟一步啊
回复 支持 反对

使用道具 举报

变形金刚

发表于 2018-3-26 17:00:33 | 显示全部楼层

有教程就方便多了
回复 支持 反对

使用道具 举报

天下之大我为

发表于 2018-4-1 19:07:55 | 显示全部楼层

感谢感谢,辛苦啦
回复 支持 反对

使用道具 举报

铁树开花

发表于 2018-4-9 16:54:37 | 显示全部楼层

还是不会啊
回复 支持 反对

使用道具 举报

烟雨朦胧

发表于 2018-4-9 16:55:10 | 显示全部楼层

就一看而过吧
回复 支持 反对

使用道具 举报

柠檬派对

发表于 2018-4-16 16:58:19 | 显示全部楼层

这个可以啊
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

RAKsmart讨论

RAKsmart
优惠码:6.5折优惠链接
介绍:RAKsmart是知名的美国服务器租用商,包括美国站群服务器、美国cn2服务器、香港服务器等热门产品,RAKsmart与国内中国联通、中国电信、中国移动三大线路直连,国内访问速度快。
查看更多

麦★链接

发表主题