电脑疯子技术论坛|电脑极客社区

微信扫一扫 分享朋友圈

已有 2304 人浏览分享

Centos7 yum安装 Lnmp以及Lamp

[复制链接]
2304 0

首先配置防火墙

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

1.关闭firewall:

  1. systemctl stop firewalld.service #停止firewall
  2.   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

  1. vi /etc/selinux/config
  2. #SELINUX=enforcing #注释掉
  3. SELINUX=disabled #增加
  4. :wq! #保存退出
  5. setenforce 0 #使配置立即生效
复制代码


Lnmp安装

1.安装nginx


  1. yum install yum-priorities -y
  2. wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
  3. rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
  4. yum install nginx
复制代码


2.启动nginx

  1. systemctl start nginx.service #启动nginx
  2. systemctl stop nginx.service #停止
  3. systemctl restart nginx.service #重启
  4. systemctl enable nginx.service #设置开机启动
复制代码


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


  1. cd /etc/nginx/conf.d/
  2. vim default.conf
  3. 把listen 80改成listen 81
  4. 然后重启nginx
  5. systemctl restart nginx.service #重启nginx
复制代码


4.下一步安装PHP-fpm

  1. yum install php-fpm
  2. 安装完毕后
  3. systemctl start php-fpm.service #启动php-fpm
  4. systemctl enable php-fpm.service #设置开机启动
复制代码


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


  1. location ~ \.php$ {
  2.     root      html;
  3.     fastcgi_pass  127.0.0.1:9000;
  4.     fastcgi_index index.php;
  5.     fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/$fastcgi_script_name;
  6.     include    fastcgi_params;
  7.   }
复制代码


7.访问test.php

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

8.负载配置

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

  2. upstream site{
  3.       server 172.16.170.138;
  4.       server 172.16.170.139;
  5.   }
  6.   server {
  7.     listen    80;
  8.     server_name ieccohomo.com;

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

  11.     location / {
  12.       root  /usr/share/nginx/html;
  13.       index index.html index.htm;
  14.       proxy_pass http://ieccohomo.com;
  15.     }
复制代码


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

Lamp安装

1.安装apache


  1. yum install httpd #根据提示,输入Y安装即可成功安装
  2.   systemctl start httpd.service #启动apache
  3.   systemctl stop httpd.service #停止apache
  4.   systemctl restart httpd.service #重启apache
  5.   systemctl enable httpd.service #设置apache开机启动
复制代码


2.安装mariadb(MySQL)

  1. yum install mariadb mariadb-server #询问是否要安装,输入Y即可自动安装,直到安装完成
  2.   systemctl start mariadb.service #启动MariaDB
  3.   systemctl stop mariadb.service #停止MariaDB
  4.   systemctl restart mariadb.service #重启MariaDB
  5.   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

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


5.访问测试

  1. cd /var/www/html
  2. vi index.php #输入下面内容
  3. <?php
  4.   phpinfo();
  5. ?>
  6. :wq! #保存退出
复制代码


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



您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

关注

0

粉丝

9021

主题
精彩推荐
热门资讯
网友晒图
图文推荐

Powered by Pcgho! X3.4

© 2008-2022 Pcgho Inc.