Centos7.3服务器搭建LNMP环境的方法
本文实例讲述了centos7.3服务器搭建lnmp环境的方法。分享给大家供大家参考,具体如下:
需求:在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包
建立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扩展
安装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
看到 hello eric 就大功告成~
希望本文所述对大家centos服务器配置有所帮助。