centos7 部署LNMP

1.安装Nginx

使用Nginx官方提供的rpm包

[root@nginx ~]# cat /etc/yum.repos.d/nginx.repo

[nginx]

name=nginx repo

baseurl=http://nginx.org/packages/centos/7/$basearch/

gpgcheck=0

enabled=1

 

//2.执行yum安装

[root@nginx ~]# yum install nginx -y

[root@nginx ~]# systemctl start nginx

[root@nginx ~]# systemctl enable nginx

2.使用第三方扩展epel源安装php7.2

移除旧版php

[root@nginx ~]# yum remove php-mysql-5.4 php php-fpm php-common

安装扩展源

[root@nginx ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

[root@nginx ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

 

安装php72版本

[root@nginx ~]# yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-pdo php72w-xml php72w-fpm php72w-mysqlnd php72w-opcache

 

启动php

[root@nginx ~]# systemctl start php-fpm

[root@nginx ~]# systemctl enable php-fpm

3.安装mysql

下载官方扩展源, 扩展源集成mysql5.6、5.7、8.0,仅5.7仓库是开启

[root@nginx ~]# rpm -ivh http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql57-community-release-el7-10.noarch.rpm

[root@nginx ~]# yum install mysql-community-server -y

[root@nginx ~]# systemctl start mysqld

[root@nginx ~]# systemctl enable mysqld

 

如果mysql登陆需要密码,请查看该文件

[root@nginx ~]# grep 'temporary password' /var/log/mysqld.log

 

登陆mysql重新配置密码

[root@nginx ~]# mysql -uroot -p'password'

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'zlx!@345';  ###必须符合密码复杂性。

4.配置php 结合nginx 

Vi /etc/nginx/conf/conf.d/default.conf

server {

    listen       80;

    server_name  localhost;

    location / {

        root   /usr/share/nginx/html;

        index  index.php index.html index.htm;

    }

    location ~ \.php$ {

        root           html;

        fastcgi_pass   127.0.0.1:9000;

        fastcgi_index  index.php;

        fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;

        include        fastcgi_params;

    }

5.添加php测试页面

 

[root@nginx ~]# cat /usr/share/nginx/html/index.php

 

<?php

 

        phpinfo();

 

?>

访问链接:http://192.168.10.145/index.php

 

posted @ 2018-06-19 14:45  Mr.zou  阅读(132)  评论(0编辑  收藏  举报