centos7yum安装lnmp环境

搭建LNMP环境

1.登录配置服务器

为服务器添加一个ius仓库,使服务器可以下载到更新版本的软件。

//为centos7添加一个ius仓库

yum install https://centos7.iuscommunity.org/ius-release.rpm -y

//顺便安装一些常用软件

yum install vim wget git unzip -y

2.安装配置Nginx

//安装Nginx

yum install nginx -y

//启动Nginx

systemctl start nginx

//设置nginx开机启动

systemctl enable nginx

3.安装配置mysql数据库 Mariadb

仅完成Mariadb的安装和root密码的设置。

//删除系统自带的低版本Mariadb

yum remove mariadb-libs -y

//安装ius仓库的新版mariadb

yum install mariadb101u-server -y

//启动Mariadb

systemctl start mariadb

//设置mariadb开机启动

systemctl enable maridb

//为mariadb设置root密码

mysql_secure_installation

//配置完成重启一下Mariadb

systemctl restart mariadb

4.安装配置PHP

这里只安装常用的PHP拓展,具体使用时需要什么拓展即安装什么拓展即可。

//安装IUS仓库提供的PHP7.1

yum install php71u-fpm php71u-cli php71u-xml php71u-gd php71u-mysqlnd php71u-pdo php71u-mcrypt php71u-mbstring php71u-json php71u-opcache -y

//启动php-fpm

systemctl start php-fpm

//设置开机自启动php-fpm

systemctl enable php-fpm

//修改nginx配置使其支持php,两个I地方

cd /etc/nginx/

mv nginx.conf nginx.conf.bak

cp nginx.conf.default nginx.conf

//添加目录和php主页如下

vim nginx.conf

location / {

root /usr/share/nginx/html;

index index.php index.html index.htm;

//前面的#取消 修改如下

location ~ .php$ {

root /usr/share/nginx/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;

}

//重启nginx

systemctl restart nginx

测试php

vim /usr/share/nginx/html/info.php

<?php

phpinfo();

?>

浏览器输入http://ip/info.php

看到页面 PHP Version 7.1.17 成功

基本已经安装成功LNMP环境了,拷贝网页文件到/usr/share/nginx/html下部署你的网站吧

nginx配置文件,默认的存放路径是/etc/nginx/nginx.conf

nginx的html目录,默认的存放路径是/usr/share/nginx/html

猜你喜欢

转载自www.cnblogs.com/muyo/p/9080300.html
今日推荐