LNMP, CentOS7.0+Nginx+Mysql5.7+PHP7环境安装

LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。这里和家分享一下,如何在CentOS 7.0上搭建一个这样的环境,其中软件使用yum方式安装。

进入CentOS 7.0中,首先更新yum。

1 yum -y update

一、修改 yum 源

1 [root@localhost ~]# rpm -Uvh https://dl.Fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
2 [root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
3 [root@localhost ~]# rpm -Uvh  http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

Webtatic:https://webtatic.com
MySQL:https://dev.mysql.com/downloa...

二、安装 Nginx、MySQL、PHP

1 [root@localhost ~]# yum -y install nginx
2 [root@localhost ~]# yum -y install mysql-community-server
3 [root@localhost ~]# yum -y install php70w-devel php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64  php70w-pdo.x86_64   php70w-mysqlnd  php70w-fpm php70w-opcache php70w-pecl-redis php70w-pecl-mongo

三、配置

1、配置 MySQL
MySQL 安装完成之后,在 /var/log/mysqld.log 文件中给 root 生成了一个默认密码
通过下面的方式找到root 默认密码,然后登录 MySQL 进行修改:

1 [root@localhost ~]# systemctl start mysqld    # 启动 MySQL
2 [root@localhost ~]# grep 'temporary password' /var/log/mysqld.log  # 查找默认密码
3 2017-04-10T02:58:16.806931Z 1 [Note] A temporary password is generated for root@localhost: iacFXpWt-6gJ

登录 MySQL

1 [root@localhost ~]# mysql -uroot -p'iacFXpWt-6gJ'  

修改root 默认密码:

1 mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyPass1!';

或者:

1 mysql> set password for 'root'@'localhost'=password('123abc'); 


MySQL5.7 默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示 ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 错误

详见 MySQL 官网密码策略详细说明:https://dev.mysql.com/doc/ref...

配置默认编码为 utf8
修改 /etc/my.cnf 配置文件,在 [mysqld] 下添加编码配置,配置完成后重启:

1 [root@localhost ~]# vim /etc/my.cnf
2 [mysqld]
3 character_set_server=utf8
4 init_connect='SET NAMES utf8'
5 [root@localhost ~]# systemctl restart mysqld    # 重启 MySQL

扫描二维码关注公众号,回复: 2131128 查看本文章

设置开机启动:

1 [root@localhost ~]# systemctl enable mysqld

默认配置文件路径:
配置文件:/etc/my.cnf
日志文件:/var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket 文件:/var/run/mysqld/mysqld.pid

2、配置 Nginx
安装完成以后查看自己防火墙是否开启,如果已开启,我们需要修改防火墙配置,开启 Nginx 外网端口访问。

1 [root@localhost ~]# systemctl status firewalld

如果显示 active (running),则需要调整防火墙规则的配置。

修改 /etc/firewalld/zones/public.xml文件,在zone一节中增加
保存后重新加载 firewalld 服务:

1 [root@localhost ~]# vim /etc/firewalld/zones/public.xml
2 <zone>
3     ...
4     <service name="nginx"/>
5 <zone>
6 [root@localhost ~]# systemctl reload firewalld

修改 Nginx 配置:

1 [root@localhost ~]# vim /etc/nginx/nginx.conf

在 server {} 里添加:

 1 location / {
 2     #定义首页索引文件的名称
 3     index index.php index.html index.htm;   
 4 }
 5  
 6 # PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI默认配置.
 7 location ~ .php$ {
 8     fastcgi_pass 127.0.0.1:9000;
 9     fastcgi_index index.php;
10     fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
11     include fastcgi_params;
12 }

配置完成重启 Nginx

1 [root@localhost ~]# systemctl start nginx    # 启动 Nginx

:本文只是简单配置 Nginx,具体更多配置请自行百度。

设置开机启动:

1 [root@localhost ~]# systemctl enable nginx

3、设置开机启动 php-fpm

1 [root@localhost ~]# systemctl enable php-fpm
2 [root@localhost ~]# systemctl start php-fpm    # 启动 php-fpm

四、测试

  • 在 /usr/share/nginx/html 文件下创建php文件,输出 phpinfo 信息

  • 1 cat>>phpinfo.php
  • 浏览器访问 http://<内网IP地址>/phpinfo.php,如果看到 PHP信息,说明安装成功,内网地址通过ifconfig查看

猜你喜欢

转载自www.cnblogs.com/tdalcn/p/9298267.html