通过yum在CentOS7部署LNMP环境(Centos7.4+Nginx1.12+mariadb5.5.56+PHP7.0)

LNMP环境

CentOS Linux release 7.4.1708

PHP 7.0.25

nginx version: nginx/1.12.2

mariadb: 5.5.56-MariaDB

一、环境准备:

操作系统: CentOS Linux release 7.4.1708

关闭防火墙

#systemctl stop firewalld

# setenforce 0

检查网络连通性:

#ping -c2 baidu.com

二、安装配置mysql

安装mariadb

# yum install -y mariadb-server mariadb

启动数据库并配置开机自启动

# systemctl start mariadb &&  systemctl enable mariadb

初始化数据库,配置root用户密码

# mysql_secure_installation

查看数据库状态

# systemctl status mariadb

三、安装Nginx

1.配置企业源

# yum install -y epel-release

2.安装nginx

# yum install -y nginx

3.设置开机自启动并启动服务

# systemctl enable nginx && systemctl start nginx

4.查看服务状态

# systemctl status nginx

# netstat  -lant | grep 80

5.浏览器访问http://localhost_ip

 

Nginx 默认的HTML根目录是:/usr/share/nginx/html,可以修改其下的 index.html 的内容再看看效果。

四、安装配置php7

1.配置源

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

2.安装php7

#yum install 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-mysql.x86_64 php70w-pdo.x86_64 -y

3.安装php-fpm

#yum install php70w-fpm -y

4.编辑/etc/php.ini  取消764行注释,并设置为0

762 cgi.fix_pathinfo=0

编辑/etc/php-fpm.d/www.conf

8 user = nginx

10 group = nginx

34 listen.owner = apache

35 listen.group = apache

5.启动服务被开机自启

#systemctl start php-fpm &&  systemctl enable php-fpm

查看服务状态

#systemctl status php-fpm

五、配置Nginx

#vi /etc/nginx/nginx.conf

添加以下内容

 

server{

 

          index  index.html index.htm index.php;

        location / {

        }

        location ~ \.php$ {

           root           html;

           fastcgi_pass   127.0.0.1:9000;

           fastcgi_index  index.php;

           fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

           include        fastcgi_params;

       }

 }

重启服务

#systemctl restart nginx

#echo “<?php phpinfo();?>”  > /usr/share/nginx/html/index.php

六、访问确认

http://localhost_ip

根据 Server API 行看出,是通过 FPM/FastCGI 方式工作的

附:

更改index.php 测试php是否可以连接数据库 

<?php

$servername = "localhost";

$username = "username";

$password = "password";

// 创建连接

$conn = new mysqli($servername, $username, $password);

// 检测连接

if ($conn->connect_error){

  die("连接失败: " . $conn->connect_error);

}

echo "连接成功";

?>

参考:https://www.awaimai.com/671.html;http://www.runoob.com/php/php-mysql-connect.html

 

posted @ 2017-12-06 14:09  苏方木  阅读(393)  评论(0编辑  收藏  举报