美文网首页
安装最新LAMP环境(CentOS7+PHP7.1.5+Mysq

安装最新LAMP环境(CentOS7+PHP7.1.5+Mysq

作者: 1367bfee4461 | 来源:发表于2018-07-10 14:00 被阅读0次

    安装Apache&Nginx

    nginx_Apache.jpg

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

    yum update

    ②. 安装Apache

    yumlist|grep httpd//查看有哪些Apache可以安装yum install -y httpd//安装Apache指令http -v//安装完成后查看Apache版本指令显示内容如下Server version: Apache/2.4.6(CentOS)Server built:  Apr12201721: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 Sun2017-06-1113:08:10CST;8s ago//防火墙的状体是开启的

    刷新浏览器依旧能访问到Apache的默认页面

    ④.安装Ngixn

    [root@localhost /]# yum search nginx//搜索没有nginx这个安装包 很遗憾的是没有[root@localhost /]# yum install nginx//尝试安装Loaded plugins: fastestmirrorLoading mirror speeds from cached hostfile * base: mirrors.tuna.tsinghua.edu.cn * extras: mirrors.tuna.tsinghua.edu.cn * updates: mirrors.tuna.tsinghua.edu.cnNo 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 nginxnginx-debuginfo.x86_64 : Debug informationforpackage nginxnginx-module-geoip.x86_64 : nginx GeoIP dynamic modulesnginx-module-geoip-debuginfo.x86_64 : Debug informationforpackage nginx-module-geoipnginx-module-image-filter.x86_64 : nginx image filter dynamicmodulenginx-module-image-filter-debuginfo.x86_64 : Debug informationforpackage nginx-module-image-filternginx-module-njs.x86_64 : nginx nginScript dynamic modulesnginx-module-njs-debuginfo.x86_64 : Debug informationforpackage nginx-module-njsnginx-module-perl.x86_64 : nginx Perl dynamicmodulenginx-module-perl-debuginfo.x86_64 : Debug informationforpackage nginx-module-perlnginx-module-xslt.x86_64 : nginx xslt dynamicmodulenginx-module-xslt-debuginfo.x86_64 : Debug informationforpackage nginx-module-xsltnginx-nr-agent.noarch : New Relic agentforNGINXandNGINX Plusnginx-release-centos.noarch : nginx repo configurationandpgppublickeyspcp-pmda-nginx.x86_64 : Performance Co-Pilot (PCP) metricsforthe Nginx Webservernginx.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 --reloadsuccess[root@localhost /]# firewall-cmd --zone=public --list-ports//查看所有打开的端口80/tcp8080/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 generatedforroot@localhost: uvrpXRuul6/h    [root@localhost /]# mysql -u root -p    //进入数据库系统mysql>setpasswordfor'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=utf8init_connect='SET NAMES utf8'[root@localhost ~]# systemctl restart mysqld  //重启MySQL//进入MySQL数据库mysql> select version();    +-----------+| version() |+-----------+| 5.7.18    |+-----------+1 rowinset(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 rowsinset(0.01 sec)

    如果报错 以下是解决办法

    mysql> show datbases;

    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'datbases' at line 1

    mysql> alter user 'root'@'%' identified by 'roots';

    Query OK, 0 rows affected (0.00 sec)

    mysql> flush privileges;

    Query OK, 0 rows affected (0.00 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.rpmRetrieving https://mirror.webtatic.com/yum/el7/epel-release.rpmwarning: /var/tmp/rpm-tmp.F1aZTS: Header V4 RSA/SHA1 Signature, key ID62e74ca5: NOKEYPreparing...################################# [100%]Updating / installing...1:epel-release-7-5################################# [100%][root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpmRetrieving https://mirror.webtatic.com/yum/el7/webtatic-release.rpmwarning: /var/tmp/rpm-tmp.rnxYY3: Header V4 RSA/SHA1 Signature, key ID62e74ca5: NOKEYPreparing...################################# [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版本PHP7.1.5(cli) (built: May12201721:54:58) ( NTS )Copyright (c)1997-2017The PHP GroupZend Engine v3.1.0, Copyright (c)1998-2017Zend Technologies[root@localhost ~]# systemctl restart httpd    //重启Apache[root@localhost ~]# vim /var/www/html/index.php

    刷新浏览器

    2017-06-11.png

    作者:龚天元

    链接:https://www.jianshu.com/p/ed2d1820bd3e

    來源:简书

    简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

    相关文章

      网友评论

          本文标题:安装最新LAMP环境(CentOS7+PHP7.1.5+Mysq

          本文链接:https://www.haomeiwen.com/subject/sfbfpftx.html