How to set up php environment redis
一、下载
1、http://download.redis.io/releases/redis-6.0.9.tar.gz
下载到本地,文件传输上传到 /usr/local/src/
2、wget -P /usr/local/src/ http://download.redis.io/releases/redis-6.0.9.tar.gz
二、解压,编译,安装
> cd /usr/local/src > tar xzf tar xzf redis-6.0.9.tar.gz > cd redis-6.0.9 > make
编译完会默认将软件安装在当前目录,这里将整个解压缩文件移至local目录
mv /usr/local/src/redis-6.0.9 /usr/local/redis-6.0.9
三、更改配置 /usr/local/redis-6.0.9/redis.conf
1、更改默认端口为16379
2、设置redis服务以守护进程运行
3、设置redis可供远程访问
4、设置密码
> vim /usr/local/redis-6.0.9/redis.conf # 打开redis服务启动配置文件, # vim中命令模式下输入“/关键字” # 类似于windows的文件中查询,字符n代表下一个,N代表上一个。 # 设置参数值 no 为 yes 并在命令模式下输入 “:wq” 代表保存并退出 > /port # 匹配到端口 改为16379,该配置是用来限制端口访问的 > /pid #匹配pid文件,改为redis_16379,该配置是用来存储pid信息,主要是为了命名风格统一,与端口一致,如果不改默认端口,这里也不用改 > /daemonize # 匹配到守护进程配置,设置yes会以守护进程模型常驻 > /bind 127.0.0.1 #注释掉该行,或者注释掉所有的bind配置,改为bind 0.0.0.0,意味着允许任何ip访问,该配置是用来限制IP访问的 > /protected-mode yes #把yes改为no > /requirepass #去除前面的#打开注释,并更改默认的密码为自定义密码【最好复杂点,以免暴力破解】
redis在开放远程访问,又不设置密码的情况下,相当于谁都可以访问redis服务器,且非常容易被服务器探针攻击,被注入挖矿木马或者勒索木马,如果服务器没有备份基本GG,所以开放远程访问,一定要更改默认密码,即requirepass参数后面的字符串
开放远程访问,一定要更改默认密码,即requirepass参数后面的字符串
开放远程访问,一定要更改默认密码,即requirepass参数后面的字符串
四、设置开机自启动
vim /etc/init.d/redis
将如下配置复制粘贴保存
#!/bin/sh # # Simple Redis init.d script conceived to work on Linux systems # as it does use of the /proc filesystem. #chkconfig: 2345 80 90 #description:auto_run REDISPORT=16379 EXEC=/usr/local/redis-6.0.9/src/redis-server CLIEXEC=/usr/local/redis-6.0.9/src/redis-cli PIDFILE=/var/run/redis_${REDISPORT}.pid CONF="/usr/local/redis-6.0.9/redis.conf" case "$1" in start) if [ -f $PIDFILE ] then echo "$PIDFILE exists, process is already running or crashed" else echo "Starting Redis server..." $EXEC $CONF fi ;; stop) if [ ! -f $PIDFILE ] then echo "$PIDFILE does not exist, process is not running" else PID=$(cat $PIDFILE) echo "Stopping ..." $CLIEXEC -p $REDISPORT shutdown # 有设置密码要加 -a “密码” 参数,如下 # $CLIEXEC -a "自定义的密码" -p $REDISPORT shutdown while [ -x /proc/${PID} ] do echo "Waiting for Redis to shutdown ..." sleep 1 done echo "Redis stopped" fi ;; *) echo "Please use start or stop as first argument" ;; esac
设置命令可被执行
> chmod -R 0777 /etc/init.d/redis
检验自启动脚本
> service redis start # 检验服务启动 > service redis stop # 检验服务关闭 // 均正常提示 > chkconfig redis on # 设置开机自动执行redis开机自启动脚本 > reboot # 重启,ssh重连 # 重启后 > netstat -ntlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:16379 0.0.0.0:* LISTEN 839/redis-server 0. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1056/sshd
验证开机自启动成功
安装完毕
五、服务器上使用
> /usr/local/redis-6.0.9/src/redis-cli -p 16379 -a "配置文件里设置的密码"
The above is the detailed content of How to set up php environment redis. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.
