Centos6.8 PHP7+MYSQL5.7

1.安装nginx

修改yum源

[plain] view plain copy
  1. vim /etc/yum.repos.d/nginx.repo  
  2. ##################写入如下源内容#######################  
  3. [nginx]  
  4. name=nginx repo  
  5. baseurl=http://nginx.org/packages/centos/$releasever/$basearch/  
  6. gpgcheck=0  
  7. enabled=1  

查看yum源中的nginx版本
[plain] view plain copy
  1. yum list nginx  
Centos6.8 PHP7+MYSQL5.7
安装nginx
[plain] view plain copy
  1. yum -y install nginx  
查看安装的版本是否为1.12
[plain] view plain copy
  1. nginx -v  
Centos6.8 PHP7+MYSQL5.7
打开80端口
[plain] view plain copy
  1. ################################ CentOS7  
  2. ############## 查看防火墙状态   running为运行  
  3. firewall-cmd --state  
  4. ############## 查看已经开放的端口  
  5. firewall-cmd --list-ports  
  6. ############## 永久开启80端口   
  7. firewall-cmd --zone=public --add-port=80/tcp --permanent  
  8. ############## 重启firewall防火墙  
  9. firewall-cmd --reload  
  10. ############## 停止firewall防火墙  
  11. systemctl stop firewalld.service  
  12. ############## 禁止firewall防火墙开机启动  
  13. systemctl disable firewalld.service  
  14.   
  15. ########################## CentOS6  
  16. ### 查看防火墙状态  
  17. service iptables status  
  18. ### 开启80端口  
  19. /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT  
  20. ### 保存修改  
  21. /etc/rc.d/init.d/iptables save  
  22. ### 重启防火墙  
  23. service iptables restart  
  24. ### 停止防火墙  
  25. service iptables stop  
  26. ### 永久关闭防火墙  
  27. chkconfig iptables off  
启动nginx
[plain] view plain copy
  1. service nginx start  
  2. #重启  
  3. service nginx restart  
  4. #停止  
  5. service nginx stop  
设置开机启动

nginx配置文件在 /etc/nginx/conf.d 里面

[plain] view plain copy
  1. chkconfig nginx on  
2.安装php

安装php yum源

[plain] view plain copy
  1. #################### CentOS 6  
  2. rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm  
  3.   
  4. #################### CenOS 7  
  5. rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm  
入报以下错误

Centos6.8 PHP7+MYSQL5.7
请键入如下代码

[plain] view plain copy
  1. ############################ CentOS 7  
  2. rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm  
  3.   
  4. ############################ CentOS 6  
  5. wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm  
  6. wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm  
  7. rpm -ivh epel-release-6-8.noarch.rpm  
  8. rpm -ivh remi-release-6.rpm  
再进行第一步操作

修改yum源

[plain] view plain copy
  1. vim /etc/yum.repos.d/remi.repo  
将 [remi] 段中的 enabled=0 改为 enabled=1

Centos6.8 PHP7+MYSQL5.7
/etc/yum.repos.d下面有php54/php70/php71/php72安装哪个就修改哪个

我这里安装php71

Centos6.8 PHP7+MYSQL5.7

[plain] view plain copy
  1. vim /etc/yum.repos.d/remi-php71.repo  
将 [remi-php71] 段中的 enabled=0 改为 enabled=1

Centos6.8 PHP7+MYSQL5.7
查看将要yum安装的php版本

[plain] view plain copy
  1. yum list php  
Centos6.8 PHP7+MYSQL5.7
安装php及一些常用扩展
[plain] view plain copy
  1. yum -y install php php-fpm php-cli php-pdo php-mysql php-gd php-bcmath php-xml php-mbstring php-mcrypt php-redis  
查看php版本及扩展
[plain] view plain copy
  1. # 版本  
  2. php -v  
  3. # 扩展  
  4. php -m  
修改php配置
[plain] view plain copy
  1. vim /etc/php.ini  
[plain] view plain copy
  1. # 时区修改  
  2. date.timezone = PRC  
  3. # 上传文件大小修改  
  4. upload_max_filesize = 20M  
  5. # 提交文件大小  
  6. post_max_size = 20M  
  7. # 隐藏 HTTP Header 中的php信息  
  8. expose_php = Off  
  9. # 打开php错误提示  
[plain] view plain copy
  1. display_errors = On  
启动php-fpm
[plain] view plain copy
  1. # 启动  
  2. service php-fpm start  
  3. # 重启  
  4. service php-fpm restart  
  5. # 停止  
  6. service php-fpm stop  

设置开机启动

[plain] view plain copy
  1. chkconfig php-fpm on  

3.安装mysql

########################  CenOS 6

[plain] view plain copy
  1. ## 下载yum源  
  2. wget http://dev.mysql.com/get/mysql57-community-release-el6-7.noarch.rpm  
[plain] view plain copy
  1. ## rpm安装yum源  
  2. rpm -Uvh mysql57-community-release-el6-7.noarch.rpm  
[plain] view plain copy
  1. ## 编辑yum源文件  
  2. vim /etc/yum.repos.d/mysql-community.repo  

确认 [mysql57-community] 下面的 enable 为 1

Centos6.8 PHP7+MYSQL5.7

[plain] view plain copy
  1. ##安装 mysql  
  2. yum -y install mysql-community-server  

######################## CentOS 7

[plain] view plain copy
  1. ## 下载yum源  
  2. wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm  
  3. rpm -ivh mysql57-community-release-el7-11.noarch.rpm  
  4. ## 安装mysql  
  5. yum -y install mysql-community-server  

启动mysql

[plain] view plain copy
  1. service mysqld start  

查看自动生成的密码

[plain] view plain copy
  1. grep "password" /var/log/mysqld.log  

Centos6.8 PHP7+MYSQL5.7
[email protected]:后面即为随机的密码 delsqxooB5>g

修改初始密码

[plain] view plain copy
  1. mysql_secure_installation  

Centos6.8 PHP7+MYSQL5.7

先输入随机密码,然后进行新密码的修改

新密码必须含有 大小写字母数字和字符

登录看是否修改成功

Centos6.8 PHP7+MYSQL5.7

设置mysql开机自启

[plain] view plain copy
  1. chkconfig mysqld on  

mysql的配置文件默认在 /etc/my.cnf