Centos7.6配置lnmp

正文开始之前,先唠叨几句。

前段时间,博客遭到流量攻击,还好攻击流量不是很大,只有访客记录表的数据有些缺失。服务器现在用的是apache服务器,经受不住大流量的访问,服务器也快要到期了,新换一台服务器,重新配置一个nginx服务器吧。下边是我的血泪史。当然,我这只是能让我的网站在服务器上跑起来,在深入的运行权限之类的问题,目前可能涉及不到,以后遇到了再补充。

(一):安装nginx1.1.6

这个在LAMP环境配置及NGINX安装中介绍过,这里再介绍另一种方法,都大同小异,参照那个都可以。

1:安装nginx的yum源

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

2:使用yum安装nginx

yum install -y nginx

3:启动nginx并设置开机自动运行

systemctl start nginx #启动,restart-重启,stop-停止
systemctl enable nginx #开机启动

4:卸载nginx

yum remove nginx

5:查看nginx运行状态

systemctl  status  nginx

1.png

6:查看nginx版本

nginx -v

在这里插入图片描述

至此,nginx安装成功,在浏览器中输入你服务器的ip,就会出现如下界面。

在这里插入图片描述

最大的bug来了:(这是我配置的时候最大的bug)

配置nginx服务器成功之后,如果在浏览器输入服务器ip显示无法访问。

百思不得其姐。(难怪我单身)

百度了一下,没有找到答案,分开太麻烦了,寻思找个lnmp一件安装包装上试试,也不好用,最后发现,新买的服务器80端口没有开放。Nginx配置文件中,监听的是80端口,所以,一直不好用,开放特定端口,我之前日志中有写。大家可以去参照。至此,nginx安装完成。

(二):安装PHP7.2

我这里安装的是PHP7.2,如果你的项目能兼容的话,不建议安装PHP5.

1:安装PHP的yum源

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:查看php7 yum组件

yum search php72w

3:选择自己需要的组件安装,php72w.x86_64 和 php72w-fpm.x86_64 为核心程序必装

yum install php72w.x86_64 php72w-fpm.x86_64 php72w-cli.x86_64 php72w-common.x86_64 php72w-gd.x86_64 php72w-ldap.x86_64 php72w-mbstring.x86_64 php72w-mcrypt.x86_64 php72w-mysql.x86_64 php72w-pdo.x86_64 php72w-pecl-redis.x86_64

4:启动php并设为开机启动

systemctl start php-fpm #启动,restart-重启,stop-停止
systemctl enable php-fpm #开机启动

5:查看版本及运行状态

php-fpm -v #查看版本
ps -ef | grep php-fpm #查看运行状态

PHP安装这个没什么可说的,一步一步安装就好了。

(三):修改nginx配置

这个需要修改nginx的配置文件nginx.conf

查找文件位置命令

whereis nginx.conf

修改这个有两个方式,如果你很了解linux操作命令,你可以使用vim直接在服务器上修改,不然,找到文件位置之后,将文件下载下来,在你本地修改完成之后,在传到服务器上。

vi /etc/nginx/conf.d/default.conf

1:找到第一个location中的这一行

index  index.html index.htm;
修改为:
index  index.php index.html index.htm; #添加index.php
 

2:把FastCGI server这行下面的location的注释去掉,并修改成下面这样子

     # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
     #
     location ~ .php$ {
    
    
     root            /usr/share/nginx/html;  #网站根目录
     fastcgi_pass   127.0.0.1:9000;
     fastcgi_index  index.php;
     fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
     include        fastcgi_params;
     }
service nginx restart   #重启nginx
service php-fpm start   #开启php-fpm

3:在网站根目录新建index.php文件

vim /usr/share/nginx/html/index.php

随便写点什么内容都好,我这里输出的是phpinfo();

服务器ip/index.php 能访问,就说明nginx与 phpfpm配置成功。

(四):安装数据库maraidb10.3

(1)配置mariadb Yum源

 vi /etc/yum.repos.d/MariaDB.repo
在该文件中添加以下内容保存:
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.2/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

(2)安装 MariaDB

yum install MariaDB-server MariaDB-client -y

(3)启动、停止服务

systemctl start mariadb
systemctl stop mariadb

(4)设置开机启动

systemctl enable mariadb

(5)接下来进行MariaDB的相关简单配置

mysql_secure_installation

首先是设置密码,会提示先输入密码

Enter current password for root (enter for none):<–初次运行直接回车

设置密码

Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
New password: <– 设置root用户的密码
Re-enter new password: <– 再输入一次你设置的密码

其他配置

Remove anonymous users? [Y/n] <– 是否删除匿名用户,回车
Disallow root login remotely? [Y/n] <–是否禁止root远程登录,回车,
Remove test database and access to it? [Y/n] <– 是否删除test数据库,回车
Reload privilege tables now? [Y/n] <– 是否重新加载权限表,回车

初始化MariaDB完成,接下来测试登录

mysql -uroot –ppassword

添加用户,设置权限

创建用户命令

mysql>create user username@localhost identified by 'password';

直接创建用户并授权的命令

mysql>grant all on *.* to username@localhost indentified by 'password';

授予外网登陆权限

mysql>grant all privileges on *.* to username@'%' identified by 'password';

授予权限并且可以授权

mysql>grant all privileges on *.* to username@'hostname' identified by 'password' with grant option;

简单的用户和权限配置基本就这样了。

Maraidb安装完成。

如果安装完成之后没有mysql表 那就去/var/lib/ 把mysql文件夹删掉

至此,lnmp环境配置完成。

我就是这样配置的,我只是把在我服务器上配置的过程写了下来。

有好的建议,请在下方输入你的评论。

欢迎访问个人博客
https://guanchao.site

欢迎访问小程序:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_39708228/article/details/113033983