CentOS 7 yum nginx MySQL PHP 简易环境搭建

用centos自带的yum源来安装nginx,mysql和php,超级方便,省去编译的麻烦,省去自己配置的麻烦,还能节省非常多的时间。

我们先把yum源换成国内的阿里云镜像源(当然不换也可以),先备份一下原来的源镜像文件,以免出错后可以恢复:

[root@192~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

下载新的CentOS-Base.repo 到/etc/yum.repos.d/,版本根据自己的系统版本选择下载:

CentOS5wget-O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repoCentOS6wget-O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repoCentOS7wget-O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

更改/etc/yum.repos.d/CentOS-Media.repo使其为不生效:

enabled=0

运行yum makecache生成缓存:

yum clean allyum makecache

yum update

安装Nginx

由于yum源中没有我们想要的nginx,那么我们就需要创建一个“/etc/yum.repos.d/nginx.repo”的文件,其实就是新增一个yum源。

[root@192yum.repos.d]# vi /etc/yum.repos.d/nginx.repo

把如下内容复制进去:

[nginx]

name=nginx repo

baseurl=http://nginx.org/packages/centos/$releasever/$basearch/gpgcheck=0enabled=1

然后保存退出,输入 yum list nginx 查看,

[root@192yum.repos.d]# yum list nginx

已加载插件:fastestmirror

nginx|2.9kB00:00:00nginx/7/x86_64/primary_db                                                      |18kB00:00:04Loading mirror speedsfromcached hostfile*base: mirrors.aliyun.com*extras: mirrors.aliyun.com*updates: mirrors.aliyun.com

可安装的软件包

nginx.x86_641:1.10.2-1.el7.ngx                                  nginx

[root@192yum.repos.d]# yum list |grep nginx

nginx.x86_641:1.10.2-1.el7.ngx          nginx

nginx-debug.x86_641:1.8.0-1.el7.ngx          nginx

nginx-debuginfo.x86_641:1.10.2-1.el7.ngx          nginx

nginx-module-geoip.x86_641:1.10.2-1.el7.ngx          nginx

nginx-module-geoip-debuginfo.x86_641:1.10.2-1.el7.ngx          nginx

nginx-module-image-filter.x86_641:1.10.2-1.el7.ngx          nginx

nginx-module-image-filter-debuginfo.x86_641:1.10.2-1.el7.ngx          nginx

nginx-module-njs.x86_641:1.10.2.0.0.20160414.1c50334fbea6-2.el7.ngx

nginx

nginx-module-njs-debuginfo.x86_641:1.10.2.0.0.20160414.1c50334fbea6-2.el7.ngx

nginx

nginx-module-perl.x86_641:1.10.2-1.el7.ngx          nginx

nginx-module-perl-debuginfo.x86_641:1.10.2-1.el7.ngx          nginx

nginx-module-xslt.x86_641:1.10.2-1.el7.ngx          nginx

nginx-module-xslt-debuginfo.x86_641:1.10.2-1.el7.ngx          nginx

nginx-nr-agent.noarch2.0.0-10.el7.ngx            nginx

pcp-pmda-nginx.x86_643.10.6-2.el7base[root@192yum.repos.d]#

如果执行命令是这样的显示效果,那么我们的nginx的yum源就配置成功啦!

然后要安装我们的nginx就直接执行:

yum -y install nginx

这样nginx的最新官网版本就安装好了!

启动nginx:

# nginx      #启动nginx

# curl127.0.0.1Welcome to nginx!body {

width: 35em;

margin:0auto;

font-family: Tahoma, Verdana, Arial, sans-serif;

}

Welcome to nginx!

If you seethispage, the nginx web serverissuccessfully installed and

working. Further configurationisrequired.

For online documentation and support please refer tonginx.org.
Commercial supportisavailable atnginx.com.

Thank youforusingnginx.

安装MySQL 5.7版本,官网http://dev.mysql.com/downloads/repo/yum/

rpm -Uvh  http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

可以看到已经有了,并且5.7版本已经启用,可以直接安装:

root@192yum.repos.d]# yum repolist all |grep mysql

mysql-connectors-community/x86_64 MySQL Connectors Community        启用:24mysql-connectors-community-source MySQL Connectors Community -Sourc 禁用

mysql-tools-community/x86_64      MySQL Tools Community              启用:38mysql-tools-community-source      MySQL Tools Community -Source    禁用

mysql-tools-preview/x86_64        MySQL Tools Preview                禁用

mysql-tools-preview-source        MySQL Tools Preview -Source      禁用

mysql55-community/x86_64          MySQL5.5Community Server        禁用

mysql55-community-source          MySQL5.5Community Server -Sourc 禁用

mysql56-community/x86_64          MySQL5.6Community Server        禁用

mysql56-community-source          MySQL5.6Community Server -Sourc 禁用

mysql57-community/x86_64          MySQL5.7Community Server        启用:146mysql57-community-source          MySQL5.7Community Server -Sourc 禁用

mysql80-community/x86_64          MySQL8.0Community Server        禁用

mysql80-community-source          MySQL8.0Community Server -Sourc 禁用

[root@192yum.repos.d]#

如果没有开启,或者你想要选择需要的版本进行安装,修改/etc/yum.repos.d/mysql-community.repo,选择需要的版本把enable改为1即可,其它的改为0:

修改好后查看可用的安装版本:

[root@192yum.repos.d]# yum repolist enabled |grep mysql

mysql-connectors-community/x86_64 MySQL Connectors Community24mysql-tools-community/x86_64      MySQL Tools Community38mysql57-community/x86_64          MySQL5.7Community Server146

不用犹豫,开始安装吧!

yum -y install mysql-community-server

……经过漫长的等待后,看到下图所示:

开始启动mysql:

service mysqld start

Redirecting to/bin/systemctl start  mysqld.service

看下mysql的启动状态:

[root@192yum.repos.d]# service mysqld status

Redirecting to/bin/systemctl status  mysqld.service

● mysqld.service-MySQL Server

Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)

Active: active (running) since 日2016-10-2322:51:48CST; 3min 14s ago

Process:36884ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)

Process:36810ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)

Main PID:36887(mysqld)

CGroup:/system.slice/mysqld.service

└─36887/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

10月2322:51:45192.168.0.14systemd[1]: Starting MySQL Server...

10月2322:51:48192.168.0.14systemd[1]: Started MySQL Server.

10月2322:52:24192.168.0.14systemd[1]: Started MySQL Server.

开机启动设置:

systemctl enable mysqld

systemctl daemon-reload

mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:

[root@192yum.repos.d]# grep'temporary password'/var/log/mysqld.log2016-10-23T14:51:45.705458Z1[Note] A temporary passwordisgeneratedforroot@localhost: a&sqr7dou7N_

mysql -uroot -p

修改root密码:

ALTER USER'root'@'localhost'IDENTIFIED BY'NewPassWord!';

注意:mysql5.7默认安装了密码安全检查插件,默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误,如下图所示:

通过msyql环境变量可以查看密码策略的相关信息:

mysql> show variables like'%password%';+---------------------------------------+--------+| Variable_name                        | Value  |+---------------------------------------+--------+| default_password_lifetime            |0|| disconnect_on_expired_password        | ON    || log_builtin_as_identified_by_password | OFF    || mysql_native_password_proxy_users    | OFF    || old_passwords                        |0|| report_password                      |        || sha256_password_proxy_users          | OFF    || validate_password_check_user_name    | OFF    || validate_password_dictionary_file    |        || validate_password_length              |8|| validate_password_mixed_case_count    |1|| validate_password_number_count        |1|| validate_password_policy              | MEDIUM || validate_password_special_char_count  |1|+---------------------------------------+--------+14rowsinset(0.00sec)

validate_password_policy:密码策略,默认为MEDIUM策略

validate_password_dictionary_file:密码策略文件,策略为STRONG才需要

validate_password_length:密码最少长度

validate_password_mixed_case_count:大小写字符长度,至少1个

validate_password_number_count :数字至少1个

validate_password_special_char_count:特殊字符至少1个

上述参数是默认策略MEDIUM的密码检查规则。

修改密码策略

如果想修改密码策略,在/etc/my.cnf文件添加validate_password_policy配置:

# 选择0(LOW),1(MEDIUM),2(STRONG)其中一种,选择2需要提供密码字典文件

validate_password_policy=0

配置默认编码为utf8

修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:

[mysqld]

character_set_server=utf8

init_connect='SET NAMES utf8'

重新启动mysql服务使配置生效:

systemctl restart mysqld

添加远程登录用户

默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须修改root允许远程连接,或者添加一个允许远程连接的帐户,为了安全起见,我们添加一个新的帐户:

mysql> GRANT ALL PRIVILEGES ON *.* TO'evai'@'%'IDENTIFIED BY'@evai2016'WITH GRANT OPTION;

mysql> FLUSH PRIVILEGES;

这样远程就可以用账户名为evai,密码为@evai2016来登录数据库了,运行 select host, user from mysql.user 查看下:

mysql>selecthost,userfrommysql.user;+-----------+-----------+| host      | user      |+-----------+-----------+| %        | evai      || localhost | mysql.sys || localhost | root      |+-----------+-----------+3rowsinset(0.00sec)

安装PHP7

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpmrpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

执行命令安装php7:

yum install php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-mysql.x86_64 php70w-pdo.x86_64

安装php-fpm:

yum install php70w-fpm php70w-opcache

启动php-fpm:

systemctl start php-fpm

修改 /etc/nginx/conf.d/default.conf 文件,找到下面这段并改为如下所示:

location ~\.php$ {

root/usr/share/nginx/html;

fastcgi_pass127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

include        fastcgi_params;

}

接着到 /usr/share/nginx/html 目录下创建一个test.php文件,内容为phpinfo():

vi /usr/share/nginx/html/test.php

#内容

phpinfo();

保存退出。接着重启nginx:

nginx -s reload

打开浏览器,看到如下图说明运行成功:

至此环境搭建完成。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,736评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,167评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,442评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,902评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,302评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,573评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,847评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,562评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,260评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,531评论 2 245
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,021评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,367评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,016评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,068评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,827评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,610评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,514评论 2 269

推荐阅读更多精彩内容