LNMP搭建笔记(20200915)

LNMP搭建笔记(20200915)

环境:CentOS7、php7.1、mariadb、nginx

一、准备环境

  • mariadb
  • php
  • Nginx

(一)安装与配置mariadb

1、安装数据库

yum -y install mariadb mariadb-server

2、启动服务

systemctl start mariadb.service
systemctl enable mariadb.service

3、重置数据库,root密码,是否可以远程登录等

mysql_secure_installation

[root@localhost ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we’ll need the current
password for the root user. If you’ve just installed MySQL, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): <–初次运行直接回车
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] #是否设置root用户密码,输入y并回车或直接回车
New password: #设置root用户的密码
Re-enter new password: #再输入一次你设置的密码
Password updated successfully!
Reloading privilege tables…
… Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] #是否删除匿名用户,生产环境建议删除,所以直接回车
… Success!
Normally, root should only be allowed to connect from ‘localhost’. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] #是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止
… Success!
By default, MySQL comes with a database named ‘test’ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] #是否删除test数据库,直接回车
Dropping test database…
… Success!
Removing privileges on test database…
… Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] #是否重新加载权限表,直接回车
… Success!
Cleaning up…
All done! If you’ve completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!

4、修改root远程登录权限

<mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root密码';
<mysql> FLUSH PRIVILEGES;

(二)安装PHP服务

1、下载yum源

http://mirror.webtatic.com/yum/el7/webtatic-release.rpm #php7的yum源(自动创建yum.repo(注意:需要外网))

安装php yum源之前需要的安装插件:epel-release
插件yum源地址:http://dl.fedoraproject.org/pub/epel/7/x86_64/

#直接配置域名源指向网络地址;
#修改yum.repo.d中配置文件
vi XXX.repo

[name]
name=XXXX
baseurl=http://dl.fedoraproject.org/pub/epel/7/x86_64/
enabled=1
gpgcheck=0

:wq
#保存退出后,重新编译yum源
yum clean all
yum makecache

我这里已经把需要的rpm包下载到本地,自己做了一个本地yum源。
2、安装php

yum -y install php71w php71w-cli php71w-common php71w-devel \
php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm \
php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb

3、安装完成后,启动php-fpm服务并设置开机启动

systemctl start php-fpm
systemctl enable php-fpm
systemctl status php-fpm

(三)安装Nginx服务

1、添加Nginx官方源

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

这里同php服务一样,已将需要的rpm包下载到本地。

2、安装Nginx

yum -y install nginx

3、修改配置文件(/etc/nginx/conf.d/default.conf)

cd /etc/nginx/conf.d
cp default.conf default.conf.bak
vi default.conf

修改下方语句,增加index.php
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
去掉文件中下方语句的#注释
location ~ .php$ {
# root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}

4.启动服务并设置开机启动

systemctl start nginx
systemctl enable nginx
systemctl status nginx

二、测试环境

以上LNMP基本就已经安装完成,下面进行环境测试,
首先是网页的存放位置: /usr/share/nginx/html
将你的PHP模板放入以上位置,进行访问,
我这里使用的是WordPress博客模板。
选择适当的方式将模板拷入:/usr/share/nginx/html
然后通过网页进行访问:http://XXX.XXX.XXX.XXX/WordPress/index.php

访问成功即为搭建成功!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值