阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS7 yum安装LNMP以及LAMP

155次阅读
没有评论

共计 4031 个字符,预计需要花费 11 分钟才能阅读完成。

简单记录在 CentOS7 下 yum 安装 LNMP 以及 LAMP 的过程。

首先配置防火墙

CentOS 7.0 默认使用的是 firewall 作为防火墙

1. 关闭 firewall:

systemctl stop firewalld.service #停止 firewall
  systemctl disable firewalld.service #禁止 firewall 开机启动

或者开启某端口
firewall-cmd –permanent –add-port=50000/tcp
用该命令查询 firewall-cmd –permanent –query-port=50000/tcp
如果是 yes 就是添加成功,如果是 no 就是没成功
成功后重载防火墙 firewall-cmd –reload
2. 关闭 SELINUX

vi /etc/selinux/config
#SELINUX=enforcing #注释掉
SELINUX=disabled #增加
:wq! #保存退出
setenforce 0 #使配置立即生效

Lnmp 安装

1. 安装 nginx

yum install yum-priorities -y
wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install nginx

2. 启动 nginx

systemctl start nginx.service #启动 nginx
systemctl stop nginx.service #停止
systemctl restart nginx.service #重启
systemctl enable nginx.service #设置开机启动

3. 更改 nginx 端口号(根据自己需求)

cd /etc/nginx/conf.d/
vim default.conf
把 listen 80 改成 listen 81
然后重启 nginx
systemctl restart nginx.service #重启 nginx

4. 访问 http://ip:81 即可看到 nginx 首页

5. 下一步安装 PHP-fpm

yum install php-fpm
安装完毕后
systemctl start php-fpm.service #启动 php-fpm
systemctl enable php-fpm.service #设置开机启动

6. 更改 nginx 配置文件识别 php  vi /etc/nginx/conf.d/default.conf,把之前的 #给去掉就可以了,顺手改一下 fastcgi_param

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;
  }

7. 访问 test.php

在 /usr/share/nginx/html 中新建一个 test.php <?php echo 123;?>

访问 http://ip:81/test.php 即可看到 nginx 中的 php 页面

8. 负载配置

进入 vi /etc/nginx/conf.d/default.conf

upstream site{
      server 172.16.170.138;
      server 172.16.170.139;
  }
  server {
    listen    80;
    server_name ieccohomo.com;

    #charset koi8-r;
    #access_log /var/log/nginx/log/host.access.log main;

    location / {
      root  /usr/share/nginx/html;
      index index.html index.htm;
      proxy_pass http://ieccohomo.com;
    }

9. 域名修改  把上面(ieccohomo.com)site,localhost 改为 www.a.com

Lamp 安装

1. 安装 apache

yum install httpd #根据提示,输入 Y 安装即可成功安装
  systemctl start httpd.service #启动 apache
  systemctl stop httpd.service #停止 apache
  systemctl restart httpd.service #重启 apache
  systemctl enable httpd.service #设置 apache 开机启动

2. 安装 mariadb(MySQL)

yum install mariadb mariadb-server #询问是否要安装,输入 Y 即可自动安装, 直到安装完成
  systemctl start mariadb.service #启动 MariaDB
  systemctl stop mariadb.service #停止 MariaDB
  systemctl restart mariadb.service #重启 MariaDB
  systemctl enable mariadb.service #设置开机启动

3. 修改 mysql 密码,安装后默认为空

修改 mysql 密码:set password for ‘root’@’localhost’=password ‘root’;

mysql 授权远程连接(navicat 等):grant all on *.* to root identified by ‘root’;

4. 安装 PHP 以及组件,使 PHP 支持 MariaDB

yum install php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash
# 这里选择以上安装包进行安装,根据提示输入 Y 回车
systemctl restart mariadb.service #重启 MariaDB
systemctl restart httpd.service #重启 apache

5. 访问测试

cd /var/www/html
vi index.php #输入下面内容
 <?php
  phpinfo();
?>
:wq! #保存退出

在客户端浏览器输入服务器 IP 地址端口号

CentOS 7 源码编译安装 PHP5.6 和 Nginx1.7.9 及 MySQL(搭建 LNMP 环境) http://www.linuxidc.com/Linux/2015-12/126200.htm

Ubuntu 14.04 LTS 安装 LNMP Nginx\PHP5 (PHP-FPM)\MySQL  http://www.linuxidc.com/Linux/2014-05/102351.htm

CentOS 6.8 编译安装 LNMP 简述  http://www.linuxidc.com/Linux/2017-05/143667.htm

Ubuntu 16.04 下源码配置 LNMP 开发环境 http://www.linuxidc.com/Linux/2016-09/135381.htm

CentOS 7 源码编译安装 PHP5.6 和 Nginx1.7.9 及 MySQL(搭建 LNMP 环境) http://www.linuxidc.com/Linux/2015-12/126200.htm

CentOS 7 源码安装最新版 LNMP 环境 http://www.linuxidc.com/Linux/2015-04/116058.htm

CentOS 6.8 安装 LNMP 环境(Linux+Nginx+MySQL+PHP)http://www.linuxidc.com/Linux/2017-04/142880.htm

Ubuntu 系统下 LNMP 环境的搭建  http://www.linuxidc.com/Linux/2017-04/142610.htm

Ubuntu 16.04 LTS 下 LNMP 环境配置简述  http://www.linuxidc.com/Linux/2017-05/144252.htm

CentOS7 下安装部署 LAMP 环境  http://www.linuxidc.com/Linux/2016-04/130653.htm

CentOS 7 上安装(LAMP)服务 Linux,Apache,MySQL,PHP  http://www.linuxidc.com/Linux/2017-05/143868.htm

Ubuntu Server 14.04 LTS 下搭建 LAMP 环境图文详解  http://www.linuxidc.com/Linux/2016-12/138758.htm

Ubuntu Server 16.04 下配置 LAMP 环境 http://www.linuxidc.com/Linux/2016-12/138757.htm

在 Ubuntu 17.04 上安装搭建 LAMP 组件环境  http://www.linuxidc.com/Linux/2017-07/145644.htm

CentOS 6.7 编译安装 LAMP 详解 http://www.linuxidc.com/Linux/2017-03/141244.htm

Ubuntu 16.04 搭建 LAMP 开发环境 http://www.linuxidc.com/Linux/2016-10/136327.htm

CentOS 7.0 搭建 LAMP 环境  http://www.linuxidc.com/Linux/2017-10/147689.htm

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-10/147839.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-21发表,共计4031字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中