安装最新LAMP环境(CentOS7+PHP7.1.5+Mysql5.7)

 

安装Apache&Nginx

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

yum update

②. 安装Apache

yum list |grep httpd    //查看有哪些Apache可以安装
yum install -y httpd    //安装Apache指令

  安装成功后,查看httpd版本信息:

httpd -v

// 返回结果 Server version: Apache
/2.4.6 (CentOS) Server built: Oct 19 2017 20:39:16

  查看ip地址:

ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:26:76:68 brd ff:ff:ff:ff:ff:ff
    inet 192.168.141.128/24 brd 192.168.141.255 scope global dynamic ens33
       valid_lft 1276sec preferred_lft 1276sec
    inet6 fe80::64ac:2f45:101a:63b3/64 scope link 
       valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN qlen 1000
    link/ether 52:54:00:ef:b4:30 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 1000
    link/ether 52:54:00:ef:b4:30 brd ff:ff:ff:ff:ff:ff

  启动httpd服务:

systemctl start httpd

  通过IP(192.168.141.128)访问浏览器发现无法访问,需要关闭防火墙或者添加80端口

 

systemctl systemctl stop firewalld   //关闭防火墙
systemctl systemctl status firewalld //查看防火墙状态
systemctl systemctl restart httpd    //重启Apache

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

firewall-cmd --permanent --zone=public --add-port=80/tcp //开启80端口并且永久生效
firewall-cmd --reload  //重新载入防火墙配置
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 Tue 2018-04-17 20:31:14 PDT; 20min ago

  再次刷新浏览器后,如下图:

 

   此时Apache已经可以访问

 

设置Apache开机自启动

systemctl enable httpd

 

 ④.安装Nginx

rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm    
// 将nginx放到yum repro库中
yum install nginx   //安装nginx
nginx -v     //查看nginx版本

// 返回结果
nginx version: nginx/1.14.0
systemctl restart nginx     // 重启nginx

// Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

 

   我希望通过80端口访问的是Apache服务器,通过8080端口访问的是nginx服务器,做如下配置

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

  然后访问192.168.141.128:8080就可以看到如下页面了

  到这里,说明我们的nginx安装完成,顺便设置一下开机自启动

systemctl enable nginx

 

安装MySql

 

 

 CetOS7已使用了MariaDB替代了默认的MySQL

MySQL之父Widenius先生离开了Sun之后,觉得依靠Sun/Oracle来发展MySQL,实在很不靠谱,于是决定重新开发代码全部开源免费关系型数据库,这就是MariaDB。
在navicat中操作mariaDB的界面和提示符还是mysql端口也是3306 外人看起来除了数据库名字改了其他和mysql完全一致,但是看一下性能比较,最近在美国mariaDB很火。
mariaDB在各方面都是mysql创新和提高版本 而不是简单的替代品,mysql和mariaDB开发团队一致,区别在于mysql已经被oracle闭源了而mariaDB是开源的。

 

 

yum install wget   //安装wget
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm    //下载mysql5.7的rpm文件
yum localinstall mysql57-community-release-el7-8.noarch.rpm    //安装rmp文件
yum install mysql-community-server  //安装MySQL数据库 约190M左右
systemctl start mysqld   //启动数据库
grep 'temporary password' /var/log/mysqld.log  //查看MySQL数据的原始密码文件 
2018-04-18T05:41:47.319685Z 1 [Note] A temporary password is generated for root@localhost: stM4VCG9&pUK // 此处是默认的初始密码
mysql -u root -p     //进入数据库系统
set password for 'root'@'localhost'=password('Abc@123456'); //重新为数据库设置密码
systemctl enable mysqld   // 将MySQL设置为开机启动项
systemctl daemon-reload

 

   

设置数据的默认字符集(非必须的)

vim /etc/my.cnf
//将下面两行配置代码加入到my.cnf最后面

character_set_server=utf8
init_connect='SET NAMES utf8'

//保存后重启mysql
systemctl restart mysqld


//进入MySQL数据库
mysql> select version();    
+-----------+
| version() |
+-----------+
| 5.7.21    |
+-----------+
1 row in set (0.02 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.00 sec)

 

安装PHP7

//安装依赖文件 
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
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

//如果以上安装失败,需要开启VPN后再次安装
yum search php71   //查看有哪些php最新版的安装包文件
yum install mod_php71w php71w-mysqlnd php71w-cli php71w-fpm   //安装php7最新版

php -v    //查看php版本

PHP 7.1.14 (cli) (built: Feb  4 2018 09:05:29) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
systemctl restart httpd    //重启Apache
vim /var/www/html/index.php

// 在index.php文件中输入一下内容
<?php
phpinfo();
?>

刷新浏览器,如下图:

 

 

 到这里PHP也安装完成啦!

 以上内容,本人已亲测安装

 

原文出处:https://www.jianshu.com/p/ed2d1820bd3e

posted @ 2018-04-18 00:34  凯kyne  阅读(452)  评论(0编辑  收藏  举报