centos7.0之Lnmp和Lamp

前端之家收集整理的这篇文章主要介绍了centos7.0之Lnmp和Lamp前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

首先配置防火墙
CentOS 7.0默认使用的是firewall作为防火墙
1.关闭firewall:

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

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.访问http://ip:81即可看到Nginx首页 5.下一步安装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

  1. /usr/share/Nginx/html中新建一个test.PHP <?PHP echo 123;?>
  2.  
  3. 访问http://ip:81/test.PHP即可看到Nginx中的PHP页面

8.负载配置

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

  1. upstream site{
  2. server 172.16.170.138;
  3. server 172.16.170.139;
  4. }
  5. server {
  6. listen 80;
  7. server_name localhost;
  8.  
  9. #charset koi8-r;
  10. #access_log /var/log/Nginx/log/host.access.log main;
  11.  
  12. location / {
  13. root /usr/share/Nginx/html;
  14. index index.html index.htm;
  15. proxy_pass http://site;
  16. }

9.域名修改 把上面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开机启动
  • 1
  • 2
  • 3
  • 4
  • 5

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密码,安装后默认为空

  1. 修改MysqL密码:set password for 'root'@'localhost'=password('root');
  1. 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 PHP-xml PHP-xmlrpc PHP-mbstring PHP-bcmath PHP-mhash
  2. #这里选择以上安装包进行安装,根据提示输入Y回车
  3. systemctl restart mariadb.service #重启MariaDB
  4. systemctl restart httpd.service #重启apache

5.访问测试

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

在客户端浏览器输入服务器IP地址,可以看到如下图所示相关的配置信息!

猜你在找的CentOS相关文章