Centos 7.4 搭建LNMP

Centos 7.4 镜像  selinux 与 firewall 已关闭。

工作环境

  • 腾讯云 1核 1GB 1Mbps 云服务器
  • CentOS 7.2 64位
  • 已经安装了PHP
  • 使用putty链接服务器

1.安装nginx

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

安装nginx

yum -y install nginx

启动nginx

     systemctl start nginx

2.安装PHP7

2.1 安装  epel-release 

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

2.2 安装 php7 的 yum 源 

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

2.3 安装php7.0

yum install -y php70w

2.4 安装php扩展

yum install -y  php70w-mysql.x86_64   php70w-gd.x86_64   php70w-ldap.x86_64   php70w-mbstring.x86_64  php70w-mcrypt.x86_64

2.5 安装 php-fpm

yum install -y php70w-fpm

3 修改配置文件

3.1 修改nginx配置文件,nginx配置文件的位置在  /etc/nginx/nginx.config

vim  /etc/nginx/nginx.conf
 server {

listen 80 default_server;

listen [::]:80 default_server;

# 这里改动了,也可以写你的域名

server_name localhost;
# 设置网站根目录 
# /wwww
root /usr/share/nginx/html;


# Load configuration files for the default server block.

include /etc/nginx/default.d/*.conf;


location / {

# 这里改动了 定义首页索引文件的名称

index index.php index.html index.htm;

}


error_page 404 /404.html;

location = /40x.html {

}


error_page 500 502 503 504 /50x.html;

location = /50x.html {

}


# 这里新加的

# PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI协议默认配置.

# Fastcgi服务器和程序(PHP,Python)沟通的协议.

location ~ \.php$ {

# 设置监听端口

fastcgi_pass 127.0.0.1:9000;

# 设置nginx的默认首页文件(上面已经设置过了,可以删除)

fastcgi_index index.php;

# 设置脚本文件请求的路径

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param SCRIPT_FILENAME /www$fastcgi_script_name;

# 引入fastcgi的配置文件

include fastcgi_params;

}

}

3.2  修改php-fpm 配置文件 (/etc/php-fpm.d/www.conf)

  1. user =nginx

  2. ​group=nginx

3.3 重新启动nginx

systemctl restart nginx

3.4 启动php-fpm

systemctl start php-fpm.service

3.5 设置服务开机自启

  1. systemctl enable nginx

  2. systemctl enable php-fpm

4. 安装mysql

4.1下载mysql的repo源

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

4.2 安装mysql-community-release-el7-5.noarch.rpm包

rpm -ivh mysql-community-release-el7-5.noarch.rpm

4.3 安装mysql

sudo yum install -y  mysql-server

4.4 更改mysql的用户权限

sudo chown -R root:root /var/lib/mysql

4.5 重启服务

systemctl restart mysql.service

4.6 登陆并修改密码

  1. mysql -u root

  2. mysql > use mysql;

  3. mysql > update user set password=password(‘66666‘) where user=‘root‘;

  4. mysql > flush privileges;

  5. mysql > exit;

测试

我们可以通过下面的方法判断Nginx配置是否成功。

  1. 在Nginx的网站根目录(/usr/share/nginx/html)下创建一个php文件,随便起名我的是index.php

  2. 输入ip/index.php

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值