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

作者:baihe 时间:2023-11-14 11:40:18 

前言

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

步骤如下:

yum的安装

yum update

yum安装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*"

安装nginx

yum -y install nginx

启动nginx

service nginx start

设置nginx服务器开机自启动

systemctl enable nginx.service

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

systemctl list-dependencies | grep nginx

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

http://00.00.00.00/

使用yum安装mysql5.7

安装mysql源

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

安装mysql

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

启动mysql

service mysqld start

检查mysql启动是否正常

service mysqld status 或者 ps -ef | grep mysql

设置mysqld服务开机自启动

systemctl enable mysqld.service

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

systemctl list-dependencies | grep mysqld

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

查看mysql的随机密码

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

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

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

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

exit;
mysql -u root -p

安装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

检查源是否安装成功

yum repolist enabled | grep "webtatic*"

安装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

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

验证php是否安装成功

php -v

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

php -m

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

启动php-fpm

service php-fpm star

检查启动是否成功

service php-fpm status

设置开机自启动

systemctl enable php-fpm.service

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

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

nginx配置如下:

server{
listen  80;
server_name youserver;
index index.html index.php;
root /home/public;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
 index index.html index.htm index.php;
 try_files $uri $uri/ /index.php?$query_string;
 }
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 html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ .php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
 root   /home/public;
 fastcgi_pass 127.0.0.1:9000;
 fastcgi_index index.php;
 fastcgi_param SCRIPT_FILENAME /home/public$fastcgi_script_name;
 include  fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /.ht {
 deny all;
}
}

来源:https://segmentfault.com/a/1190000013842789

标签:centos7,yum,lnmp
0
投稿

猜你喜欢

  • Asp测试网速代码(带进度条)

    2007-11-12 13:09:00
  • mysql8.0.11 winx64安装配置方法图文教程(win10)

    2024-01-23 07:58:58
  • python中将zip压缩包转为gz.tar的方法

    2022-02-28 18:50:49
  • python模拟登录百度代码分享(获取百度贴吧等级)

    2022-05-13 02:54:34
  • python requests.get带header

    2022-07-28 20:50:40
  • Mysql的服务无法启动的1067错误解决

    2012-01-05 19:31:56
  • asp中判断是否是手机浏览器以及手机类型

    2014-12-06 09:33:05
  • python对配置文件.ini进行增删改查操作的方法示例

    2023-10-25 05:56:13
  • opencv python统计及绘制直方图的方法

    2021-12-27 21:52:45
  • Pytorch模型微调fine-tune详解

    2021-06-17 07:29:00
  • PYTHON 中使用 GLOBAL引发的一系列问题

    2023-07-08 16:24:21
  • 详解vue事件对象、冒泡、阻止默认行为

    2024-04-28 09:26:19
  • sqlserver对字段的添加修改删除、以及字段的说明

    2024-01-25 23:43:41
  • flask route对协议作用及设计思路

    2023-01-19 13:21:34
  • 在SQL Server 2008中安装安全审计

    2009-02-24 17:22:00
  • Python调用腾讯云短信服务发送手机短信

    2021-10-07 16:55:38
  • 关于ASP代码的加密

    2007-10-15 12:30:00
  • 如何使用表格来储存数据库的记录?

    2010-05-16 15:14:00
  • python写入文件自动换行问题的方法

    2022-06-13 11:28:18
  • 浅谈Python2.6和Python3.0中八进制数字表示的区别

    2023-04-22 23:56:42
  • asp之家 网络编程 m.aspxhome.com