LAMP/LNMP环境(CentOS7+PHP7.1.5+Mysql5.7)搭建

1 篇文章 0 订阅

安装APACHE&NGINX

安装Apache

①.升级yum源

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地址,但是浏览器中没有显示有效的内容

通过检查防火墙排除问题

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

或者

防火墙上开启80端口

firewall-cmd --permanent --zone=public --add-port=80/tcp //开启80端口并且永久生效 success 
firewall-cmd --reload  //重新载入防火墙配置 success
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  //防火墙的状态是开启的 

安装Ngixn

yum search nginx  //搜索没有nginx这个安装包 很遗憾的是没有
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库中
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
[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安装包的
yum install nginx   //安装nginx
nginx -v     //查看nginx版本
nginx version: nginx/1.12.0
systemctl restart nginx     // 重启nginx

Apache与Nginx共存且使用不同端口

firewall-cmd --permanent --zone=public --add-port=8080/tcp   
success
firewall-cmd --reload
success
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 

安装MYSQL

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

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数据的原始密码文件   
mysql -u root -p     //进入数据库系统

输入密码后会发现无法登陆(提示密码错误),所以我们需要先绕过密码进入Mysql,再更改密码

vim /etc/my.cnf 
加入skip-grant-tables

重新启动mysql

/etc/init.d/mysqld restart
mysql -u root -p  //进入mysql
use mysql

由于Mysql5.7的mysql数据库下已经没有password字段,所以使用
update mysql.user set password=password(‘root’) where user=’root’时会提示ERROR 1054 (42S22): Unknown column ‘password’ in ‘field list’

mysql5.7更改密码应该采用命令

ALTER USER 'root'@'localhost'IDENTIFIED BY '********'

编辑my.cnf文件删掉skip-grant-tables 这一行,然后重启MySQL,/etc/init.d/mysqld restart,否则MySQL仍能免密码登录

mysql -u root -p

输入密码即可登录MySQL数据库

将Mysql设置为开机自启

systemctl enable mysqld
systemctl daemon-reload 
vim /etc/my.cn  //设置数据的默认字符集
//将下面两行配置代码加入到my.cnf最后面
character_set_server=utf8
init_connect='SET NAMES utf8'
systemctl restart mysqld  //重启MySQL

安装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
yum search php71   //查看有哪些php最新版的安装包文件
yum install mod_php71w php71w-mysqlnd php71w-cli php71w-fpm   //安装php7最新版
php -v    //查看php版本
systemctl restart httpd    //重启Apache
vim /var/www/html/index.php
<?php
phpinfo();
?>

刷新浏览器即可

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值