Centos6.9下 yum 安装 nginx1.10 + mysql5.6 + php5.6

一、准备工作
1、检查selinux是否为关闭状态,不为disable需要改为disable。
SELINUX=disabled

不为disabled 的话,则修改为 SELINUX=disabled。
2、检查环境下有没有安装过低版本的
rpm -qa|grep mysql
mysql-libs-5.1.73-8.el6_8.x86_64

rpm -qa|grep nginx

rpm -qa|grep php

从上可获知Linux下yum过一个 mysql-libs-5.1.73-8.el6_8.x86_64,等下安装MySQL5.6版本的时候,先做卸载就可以。

3、可以查看有没有mysql nginx php等相关的命令 ,有可能是源码安装过的,若有也需要卸载掉。

whereis nginx

whereis php
whereis mysql

4、防火墙上开启80端口的对外开放, 3306端口看你对外需求再开放了(安全考虑需要对外开放的话,也只能授权对应的信任IP访问才行)

刚刚新安装的系统默认的是关闭iptables的

vim /etc/sysconfig/iptables
加入以下内容
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [1:140]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp -m icmp --icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT

保存后重启iptables

service iptables restart

二、安装nginx
centos 6.9默认的是nginx1.10版本,想安装nginx更高的版本可以下载nginx官网yum源进行安装,这里省略自己查看其它版本安装的参考吧。
1、删除系统自带的软件包
yum remove httpd php
2、安装nginx
yum install -y nginx

3、设置nginx开机启动
chkconfig nginx on
4、启动nginx
service nginx start

三、安装MySQL5.6

1、检查MySQL是否有相关包

whereis mysql
mysql: /usr/lib64/mysql /usr/share/mysql

rpm -qa|grep mysql
mysql-libs-5.1.73-8.el6_8.x86_64

卸载mysql-libs-5.1.73-8.el6_8.x86_64
yum remove mysql-libs

2、清空dbcache
yum clean dbcache

3、下载MySQL rpm安装包

wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm

4、 安装MySQL安装源
使用rpm -ivh mysql-community-release-el6-5.noarch.rpm安装下载的rpm文件~
rpm -ivh mysql-community-release-el6-5.noarch.rpm

5、安装mysql-community-server
使用yum install mysql-community-server安装MySQL server。
yum install mysql-community-server

6、启动MySQL服务
service mysqld start

7、修改mysql密码
修改密码~

使用update user set password=PASSWORD("YOUR_PASSWORD") where user='root';修改root账号密码~

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set password=PASSWORD("YOUR_PASSWORD") where user='root';
Query OK,4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0

mysql> flush privileges;
Query OK,0 rows affected (0.00 sec)

mysql> quit

密码验证
重新登录mysql服务

至此,MySQL安装完毕~

四、安装PHP5.6

检查当前安装的PHP包
yum list installed | grep php

如果有安装的PHP包,先删除他们,如:
yum remove php.x86_64 php-cli.x86_64 php-common.x86_64

配置安装包源:,根据具体Linux系统版本安装源。

Centos 5.X

rpm -Uvh http://mirror.webtatic.com/yum/el5/latest.rpm

CentOs 6.x

rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm

CentOs 7.X

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

如果想删除上面安装的包,重新安装
rpm -qa | grep nginx
rpm -e [上面搜索到的包即可]

执行安装
yum -y install php56w.x86_64
yum -y --enablerepo=webtatic install php56w-devel
yum -y install php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64 php56w-opcache.x86_64

安装PHP FPM
yum -y install php56w-fpm

#设置php-fpm开机启动
chkconfig php-fpm on

#启动php-fpm
/etc/init.d/php-fpm start

五、配置

  1. 配置nginx
    vi /etc/nginx/conf.d/default.conf
    添加如下内容 :

server{
listen 80;
servername ;  //这里填写你的域名
index index.php index.html index.htm;
root /var/www/html;

location ~ .*\.(php|php5)?$
{

        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi.conf;  

 
方法二:
       //fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       //include fastcgi_params;

}

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

}
说明: /var/www/html 为web根目录,【location /】 ... 为url的rewrite,隐藏 index.php

  1. 配置php-fpm
    vi /etc/php-fpm.d/www.conf
    将用户和用户组设置为nginx,如:

#修改用户为nginx
user = nginx
#修改组为nginx
group = nginx
开始测试
cd /var/www
vi index.php
添加以下代码

<?php
echo phpinfo();
?>
:wq! 保存退出

#设置权限
chown nginx.nginx /var/www -R
#重启nginx
service nginx restart //(若fastcgi.conf没找到:,请参考上面配置的方法二)
#重启php-fpm
service php-fpm restart
在客户端浏览器输入服务器IP地址(如: 127.0.0.1),可以看到相关的配置信息!

如果是虚拟机,则使用ifconfig获取虚拟机ip,在浏览器输入:虚拟机IP/index.php,可以看到相关的配置信息!
说明配置成功!

3、更改MySQL编码为utf8
vim /etc/my.cnf 添加一下内容

character_set_server = utf8

4、设置开机启动项
chkconfig nginx on
chkconfig mysqld on
chkconfig php-fpm on

六、问题:
问题1 /etc/init.d/nginx restart
nginx: [emerg] socket() [::]:80 failed (97: Address family not supported by protocol)
nginx: configuration file /etc/nginx/nginx.conf test failed

解决方法: 编辑 /etc/nginx/conf.d/default.conf

注释掉 listen [::]:80 default_server;

问题2:网站注册页面报异常:field ‘id' doesn't have a default value

解决方法: 打开my.ini,查找 sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" 修改为 sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" 然后重启MYSQL

相关文章

文章浏览阅读903次。4.清除缓存目录(/var/cache/yum)下的软件...
文章浏览阅读1.5k次。Python 是一种高级解释性编程语言,已被...
文章浏览阅读2.6k次。打开终端或控制台,以root或具有sudo权...
文章浏览阅读744次,点赞24次,收藏26次。目标:通过AppSrv为...
文章浏览阅读1.1w次,点赞8次,收藏26次。chmod命令来自于英...
文章浏览阅读1.2k次。yum源的URL地址,本例中是文件系统的路...