PHP7 yum安装redis的方法:1、安装yum源和Nginx;2、启动Nginx并设置开机自动运行;3、查看PHP7 yum组件,并安装PHP7.2;4、启动PHP并设为开机启动;5、使用指定的yum源安装Redis即可。
本文操作环境:centos7系统、PHP7.2版、Dell G3电脑。
centos7 Nginx+PHP7yum安装,及yum安装redis的方法:
一.安装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
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
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文件会给系统带来安全隐患,以下为权限配置示例
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
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
【推荐学习:PHP教程】
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。