zoukankan      html  css  js  c++  java
  • lamp 环境搭建

    安装Apache&Nginx

    ①.升级一下yum源(不是必须的),升级会花点时间,需要选择的地方都选择都输入“y”即可

    yum update
    

    ②. 安装Apache

    yum list |grep httpd    //查看有哪些Apache可以安装
    yum install -y httpd    //安装Apache指令
    http -v               //安装完成后查看Apache版本指令
    显示内容如下
    Server version: Apache/2.4.6 (CentOS)
    Server built:   Apr 12 2017 21:03:28
    

    ③.通过浏览器访问
    在本机的浏览器的地址栏中输入虚拟主机的ip地址,但是浏览器中没有显示有效的内容

     
    2017-06-11_124942.png

    这种情况基本是Centos自带的防火墙开启造成的

    1.关闭防火墙
    [root@localhost /]# systemctl systemctl stop firewalld   //关闭防火墙
    [root@localhost /]# systemctl systemctl status firewalld //查看防火墙状态
    [root@localhost /]# systemctl systemctl restart httpd    //重启Apache
    

    再次刷新浏览器

     
    2017-06-11.png

    如果不想关闭防火墙,那我们可以在防火墙上允许访问80端口(这是Apache默认的端口)

    2.防火墙上开启80端口
    [root@localhost /]# firewall-cmd --permanent --zone=public --add-port=80/tcp //开启80端口并且永久生效
    success
    [root@localhost /]# firewall-cmd --reload  //重新载入防火墙配置
    success
    [root@localhost /]# systemctl status firewalld
    ● firewalld.service - firewalld - dynamic firewall daemon
       Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2017-06-11 13:08:10 CST; 8s ago  //防火墙的状体是开启的
    

    刷新浏览器依旧能访问到Apache的默认页面
    ④.安装Ngixn

    [root@localhost /]# yum search nginx  //搜索没有nginx这个安装包 很遗憾的是没有
    [root@localhost /]# yum install nginx  //尝试安装
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirrors.tuna.tsinghua.edu.cn
     * extras: mirrors.tuna.tsinghua.edu.cn
     * updates: mirrors.tuna.tsinghua.edu.cn
    No package nginx available.   //还是没有nginx的安装包
    //将nginx放到yum repro库中
    [root@localhost /]# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
    [root@localhost /]# yum search nginx  //再次搜索nginx安装包
    ======================================================== N/S matched: nginx =========================================================
    nginx-debug.x86_64 : debug version of nginx
    nginx-debuginfo.x86_64 : Debug information for package nginx
    nginx-module-geoip.x86_64 : nginx GeoIP dynamic modules
    nginx-module-geoip-debuginfo.x86_64 : Debug information for package nginx-module-geoip
    nginx-module-image-filter.x86_64 : nginx image filter dynamic module
    nginx-module-image-filter-debuginfo.x86_64 : Debug information for package nginx-module-image-filter
    nginx-module-njs.x86_64 : nginx nginScript dynamic modules
    nginx-module-njs-debuginfo.x86_64 : Debug information for package nginx-module-njs
    nginx-module-perl.x86_64 : nginx Perl dynamic module
    nginx-module-perl-debuginfo.x86_64 : Debug information for package nginx-module-perl
    nginx-module-xslt.x86_64 : nginx xslt dynamic module
    nginx-module-xslt-debuginfo.x86_64 : Debug information for package nginx-module-xslt
    nginx-nr-agent.noarch : New Relic agent for NGINX and NGINX Plus
    nginx-release-centos.noarch : nginx repo configuration and pgp public keys
    pcp-pmda-nginx.x86_64 : Performance Co-Pilot (PCP) metrics for the Nginx Webserver
    nginx.x86_64 : High performance web server   //是存在nginx安装包的
    [root@localhost /]# yum install nginx   //安装nginx
    [root@localhost /]# nginx -v     //查看nginx版本
    nginx version: nginx/1.12.0
    [root@localhost /]# systemctl restart nginx     // 重启nginx
    

    我希望通过80端口访问的是Apach服务器,通过8080端口访问的是nginx服务器,这么做?

    [root@localhost /]# firewall-cmd --permanent --zone=public --add-port=8080/tcp   
    success
    [root@localhost /]# firewall-cmd --reload
    success
    [root@localhost /]# firewall-cmd --zone=public --list-ports  //查看所有打开的端口
    80/tcp 8080/tcp    //80,8080已经打开
    [root@localhost /]# cd /etc/nginx/conf.d
    [root@localhost conf.d]# vim default.conf  //将其中的listen 80;修改为 listen 8080;
    [root@localhost conf.d]# systemctl restart nginx  //重启nginx 
    

    通过浏览器访问

     
    2017-06-11.png

    安装MySql

     
    2017-06-11.png

    CetOS7已使用了MariaDB替代了默认的MySQL ,所以我们想使用MySQL还得多做点事情

    [root@localhost /]# yum install wget      //安装wget
    [root@localhost /]# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm    //下载mysql5.7的rpm文件
    [root@localhost /]# yum localinstall mysql57-community-release-el7-8.noarch.rpm    //安装rmp文件
    [root@localhost /]#yum install mysql-community-server  //安装MySQL数据库 约190M左右
    [root@localhost /]# systemctl start mysqld   //启动数据库
    [root@localhost /]# grep 'temporary password' /var/log/mysqld.log  //查看MySQL数据的原始密码文件 
    2017-06-11T06:18:16.057811Z 1 [Note] A temporary password is generated for root@localhost: uvrpXRuul6/h    
    [root@localhost /]# mysql -u root -p     //进入数据库系统
    mysql> set password for 'root'@'localhost'=password('Aa@123456'); //重新为数据库设置密码
    Query OK, 0 rows affected, 1 warning (0.01 sec)
    //将MySQL设置为开机启动项
    [root@localhost /]# systemctl enable mysqld
    [root@localhost /]# systemctl daemon-reload
    //设置数据的默认字符集(非必须的)
    [root@localhost ~]# vim /etc/my.cnf
    //将下面两行配置代码加入到my.cnf最后面
    character_set_server=utf8
    init_connect='SET NAMES utf8'
    [root@localhost ~]# systemctl restart mysqld  //重启MySQL
    //进入MySQL数据库
    mysql> select version();    
    +-----------+
    | version() |
    +-----------+
    | 5.7.18    |
    +-----------+
    1 row in set (0.00 sec)
    mysql> show variables like '%character%';
    +--------------------------+----------------------------+
    | Variable_name            | Value                      |
    +--------------------------+----------------------------+
    | character_set_client     | utf8                       |
    | character_set_connection | utf8                       |
    | character_set_database   | utf8                       |
    | character_set_filesystem | binary                     |
    | character_set_results    | utf8                       |
    | character_set_server     | utf8                       |
    | character_set_system     | utf8                       |
    | character_sets_dir       | /usr/share/mysql/charsets/ |
    +--------------------------+----------------------------+
    8 rows in set (0.01 sec)
    

    安装PHP7

     
    php7.jpg
    //安装依赖文件
    yum install gcc-c++ libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel
    //安装php组新版本rpm
    [root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
    Retrieving https://mirror.webtatic.com/yum/el7/epel-release.rpm
    warning: /var/tmp/rpm-tmp.F1aZTS: Header V4 RSA/SHA1 Signature, key ID 62e74ca5: NOKEY
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:epel-release-7-5                 ################################# [100%]
    [root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
    Retrieving https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
    warning: /var/tmp/rpm-tmp.rnxYY3: Header V4 RSA/SHA1 Signature, key ID 62e74ca5: NOKEY
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:webtatic-release-7-3             ################################# [100%]
    [root@localhost ~]# yum search php71   //查看有哪些php最新版的安装包文件
    [root@localhost ~]# yum install mod_php71w php71w-mysqlnd php71w-cli php71w-fpm   //安装php7最新版
    [root@localhost ~]# php -v    //查看php版本
    PHP 7.1.5 (cli) (built: May 12 2017 21:54:58) ( NTS )
    Copyright (c) 1997-2017 The PHP Group
    Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    [root@localhost ~]# systemctl restart httpd    //重启Apache
    [root@localhost ~]# vim /var/www/html/index.php
    <?php
    phpinfo();
    ?>
    

    刷新浏览器

     
     

    作者:龚天元
    链接:https://www.jianshu.com/p/ed2d1820bd3e
    來源:简书

  • 相关阅读:
    ASP.NET core1.0 EF MYSQL搭建中碰到几个问题记录
    【小程序】---- input获得焦点时placeholder重影BUG
    【小程序】---- 基础知识汇总
    【vue】---- 图片懒加载
    【vue】---- v-model在自定义组件中的使用
    【工具】---- webpack简析
    【Vue】---- 手动封装on,emit,off
    【工具】---- json-server基本使用
    【Vue】----- 浅谈vue的生命周期
    【Vue】----- computed与watch的区别
  • 原文地址:https://www.cnblogs.com/ampl/p/9214393.html
Copyright © 2011-2022 走看看