• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

yum安装php、nginx、redis的方法

武飞扬头像
PHP中文网
帮助46

一.安装nginx

1.安装yum源

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

2.安装nginx

yum install -y nginx

3.启动nginx并设置开机自动运行

 systemctl start nginx  #启动,restart-重启,stop-停止
 systemctl  enable nginx  #开机启动

4.查看版本及运行状态

 nginx -v  #查看版本
 
 ps -ef | grep nginx  #查看运行状态

二.安装php7

1.安装yum源

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

2.查看php7 yum组件,示例安装php7.2

 yum search php72w

3.选择自己需要的组件安装,php72w.x86_64 和 php72w-fpm.x86_64 为核心程序必装

yum install php72w.x86_64 php72w-fpm.x86_64 php72w-cli.x86_64 php72w-common.x86_64 php72w-gd.x86_64 php72w-ldap.x86_64 php72w-mbstring.x86_64 php72w-mcrypt.x86_64 php72w-mysql.x86_64 php72w-pdo.x86_64 php72w-pecl-redis.x86_64

4.启动php并设为开机启动

 systemctl start php-fpm  #启动,restart-重启,stop-停止
 
 systemctl  enable php-fpm  #开机启动

5.查看版本及运行状态

 php-fpm -v  #查看版本
 
 ps -ef | grep php-fpm  #查看运行状态

进行完以上步骤之后,读者自行在nginx中配置web目录,已经可以正常运行了,但是此时nginx和php是以root身份运行,以最高权限运行web文件会给系统带来安全隐患,以下为权限配置示例

三.修改nginx配置

vi /etc/nginx/conf.d/default.conf

找到第一个location中的这一行

index  index.html index.htm;

修改为:

index  index.php index.html index.htm; #添加index.php

2.把FastCGI server这行下面的location的注释去掉,并修改成下面这样子

 

   # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
     #
     location ~ .php$ {
         root            /usr/share/nginx/html;  #网站根目录
         fastcgi_pass   127.0.0.1:9000;
         fastcgi_index  index.php;
         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
         include        fastcgi_params;
 }
service nginx restart   #重启nginx
service php-fpm start   #开启php-fpm

3. 在网站根目录新建index.php文件

vim /usr/share/nginx/html/index.php

输入内容:

<?php phpinfo();

5. 在浏览器中输入虚拟机ip,已经可以看到phpinfo的信息了 在windows上修改hosts文件,添加一行 192.168.6.114 www.test1.com \#配置虚拟机ip对应域名

6. 现在就可以在windows上用www.test1.com访问虚拟机配置的服务器了

四.yum安装redis

  yum安装redis时,建议使用Remi repository源。因为Remi源提供了目前最新版本的Redis,可以通该源使用YUM安装目前最新版本的Redis。另外还提供了PHP和MySQL的最新yum源,以及相关服务程序。

 1)Remi repository源依赖于epel源,因此需要先安装epel源

[root@youxi1 ~]# yum -y install epel-release

 2)安装Remi repository源

[root@youxi1 ~]# yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
[root@youxi1 ~]# ls /etc/yum.repos.d/  //下载完成后会出现许多remi的yum源,这里要用到的是remi.repo这个源
CentOS-Base.repo CentOS-Sources.repo remi-glpi92.repo remi-php70.repo remi-safe.repo
CentOS-CR.repo CentOS-Vault.repo remi-glpi93.repo remi-php71.repo
CentOS-Debuginfo.repo epel.repo remi-glpi94.repo remi-php72.repo
CentOS-fasttrack.repo epel-testing.repo remi-modular.repo remi-php73.repo
CentOS-Media.repo remi-glpi91.repo remi-php54.repo remi.repo

 3)使用指定的yum源安装Redis

[root@youxi1 ~]# yum --enablerepo=remi install -y redis  //--enablerepo指定yum源
[root@youxi1 ~]# redis-cli --version  //安装完成后使用命令查看一下版本
redis-cli 5.0.5

  注意:remi源安装完成后,默认为不启动,在需求使用remi repository源安装程序时,需求--enablerepo=remi选项指定使用remi repository源是可以被使用的,然后进行安装。

 4)启动Redis并设置开机自启

[root@youxi1 ~]# systemctl start redis
[root@youxi1 ~]# systemctl enable redis
Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /usr/lib/systemd/system/redis.service.

  注意:Redis的端口号是6379

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanfcaie
系列文章
更多 icon
同类精品
更多 icon
继续加载