温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Centos7.3服务器如何搭建LNMP环境

发布时间:2021-02-22 10:47:41 来源:亿速云 阅读:117 作者:小新 栏目:服务器

这篇文章主要介绍Centos7.3服务器如何搭建LNMP环境,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

1. 关闭防火墙和selinux

打开文件selinux

vim /etc/sysconfig/selinux

将文件中SELINUX=enforcing改为disabled,然后执行”setenforce 0″不用重启地关闭selinux。

SELINUX=disabled

关闭放火墙

systemctl stop firewalld.service

2.安装软件

2.1 MYSQL安装

下载mysql的repo源

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

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

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

安装MYSQL

sudo yum install -y mysql-server

更改MYSQL用户权限:

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

重启服务:

systemctl restart mysql.service

登录,并修改密码:

mysql -u root
mysql > use mysql;
mysql > update user set password=password(‘123456‘) where user='root';
mysql > flush privilgegs;
mysql > exit;

2.2 nginx安装

下载对应当前系统版本的nginx包

复制代码 代码如下:

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

建立nginx的yum仓库(默认yum是没有nginx的)

rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm

下载并安装nginx

yum install -y nginx

nginx启动

systemctl start nginx.service

2.3 安装php

rpm 安装 Php7 相应的 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

安装php7.0

yum install -y php70w

安装php扩展

复制代码 代码如下:

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

安装PHP FPM

yum install -y php70w-fpm

3. 修改配置文件

3.1修改Nginx配置文件

nginx配置文件位置:(/etc/nginx/conf.d/default.conf)

vim /etc/nginx/conf.d/default.conf

修改 root目录,可自定义:

root  /forest/nginxDir/html;

修改配置php解析:

location ~.php$ {
 root  /forest/nginxDir/html;
 fastcgi_pass 127.0.0.1:9000;
 fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 include  fastcgi_params;
}

3.2 修改php-fpm配置文件

php-fpm配置文件位置:(/etc/php-fpm.d/www.conf)

修改

user =nginx
group=nginx

4.放入测试文件

cd /forest/nginxDir/html
echo 'hello eric' >index.php

5.启动服务

5.1 启动nginx服务:

systemctl start nginx.service

查看启动状态:

systemctl status nginx

看到以下字眼说明启动成功!

Active: active (running) since 六 2016-11-19 13:40:04 CST; 50min ago

5.2 启动PHP-FPM:

systemctl start php-fpm.service

查看启动状态:

systemctl status php-fpm.service

看到以下字眼说明启动成功!

Active: active (running) since 六 2016-11-19 14:14:33 CST; 18min ago

6.测试

在浏览器打开192.168.44.129:80/index.php

以上是“Centos7.3服务器如何搭建LNMP环境”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI