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 and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

The future of PHP will be achieved by adapting to new technology trends and introducing innovative features: 1) Adapting to cloud computing, containerization and microservice architectures, supporting Docker and Kubernetes; 2) introducing JIT compilers and enumeration types to improve performance and data processing efficiency; 3) Continuously optimize performance and promote best practices.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

The reasons why PHP is the preferred technology stack for many websites include its ease of use, strong community support, and widespread use. 1) Easy to learn and use, suitable for beginners. 2) Have a huge developer community and rich resources. 3) Widely used in WordPress, Drupal and other platforms. 4) Integrate tightly with web servers to simplify development deployment.
