Linux系统安装 memcached
1.首先要先安装libevent库。
yum install libevent libevent-devel
2.源码安装memcached
wget 在线下载工具
yum install -y wget# 在线下载源码
wget http://memcached.org/files/memcached-1.5.16.tar.gz
tar xf memcached-1.5.16.tar.gz
cd memcached-1.5.16、# 配置
./configure --prefix=/usr/local/lamp/memcached
make
make install
- 运行memcached
/usr/local/lamp/memcached/bin/memcached -d -m 64M -u root -p 11211 -c 256
4.查看memcached是否运行
ps aux | grep memcached
使用PHP代码操作memcached
- 下载并安装libmemcached
cd /root/software
wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
tar xf libmemcached-1.0.18.tar.gz
cd libmemcached-1.0.18
./configure --prefix=/usr/local/libmemcached --with-memcached
make
make install
2.安装memcached扩展
cd /root/software
wget https://pecl.php.net/get/memcached-3.1.3.tgz
tar xf memcached-3.1.3.tgz
cd memcached-3.1.3
/usr/local/lamp/php/bin/phpize
./configure --with-php-config=/usr/local/lamp/php/bin/php-config \
--with-libmemcached-dir=/usr/local/libmemcached --disable-memcached-sasl
make
make install
3.修改php.ini添加memcached扩展
echo "extension=memcached.so" >> /usr/local/lamp/php/lib/php.ini
4.重启apache服务器
service httpd restart
5.写PHP代码操作memcached
查看php手册:https://www.php.net/manual/zh/book.memcached.php
<?php
$m = new Memcached();
$m->addServer('localhost', 11211);
$m->set("username","张三");
$username = $m->get("username");echo $username;
Linux系统安装mongodb
- 下载并安装mongo
官网:https://www.mongodb.com/download-center/community
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.10.tgz
tar xf mongodb-linux-x86_64-4.0.10.tgz# 拷贝到指定目录
mv mongodb-linux-x86_64-4.0.10 /usr/local/lamp/mongodb
2.创建MongoDB数据存放文件夹和日志记录文件夹
cd /usr/local/lamp/mongodb
mkdir -p data/db
mkdir -p data/logs
3.创建MongoDB运行时使用的配置文件
cd /usr/local/lamp/mongodb/bin
vim mongodb.conf
添加以下内容
dbpath = /usr/local/lamp/mongodb/data/db #数据文件存放目录
logpath = /usr/local/lamp/mongodb/data/logs/mongodb.log #日志文件存放目录
port = 27017 #端口
fork = true #以守护程序的方式启用,即在后台运行#auth=true #需要认证。如果放开注释,就必须创建MongoDB的账号,使用账号与密码才可远程访问
bind_ip=0.0.0.0 #允许远程访问,或者直接注释,127.0.0.1是只允许本地访问
4.启动mongodb
cd /usr/local/lamp/mongodb/bin
./mongod -f mongodb.conf
查看mongodb是否运行
ps aux | grep mongodb
关闭mongodb
./mongod --shutdown -f mongodb.conf
5.连接mongo并操作
官网:https://docs.mongodb.com/manual/crud/
cd /usr/local/lamp/mongodb/bin
./mongo
使用PHP代码操作mongodb
1.安装mongodb扩展
wget https://pecl.php.net/get/mongodb-1.5.5.tgz
tar xf mongodb-1.5.5.tgz
cd mongodb-1.5.5
/usr/local/lamp/php/bin/phpize
./configure --with-php-config=/usr/local/lamp/php/bin/php-config
make
make install
echo "extension=mongodb.so" >> /usr/local/lamp/php/lib/php.ini
service httpd restart
2.写PHP代码操作mongodb
官网:https://docs.mongodb.com/manual/crud/
https://docs.mongodb.com/ecosystem/drivers/php/
1.将php环境保存到环境变量中
vim /etc/profile # 最后一行添加
export PATH=$PATH:/usr/local/lamp/php/bin/ # 保存退出 # 重写加载环境变量文件
source /etc/profile
1.安装php的openssl扩展(访问https连接)
安装扩展依赖
yum install openssl openssl-devel# 进入到扩展文件源码目录
cd /root/software/php-7.2.1/ext/openssl# 使用phpize生成configure文件
/usr/local/lamp/php/bin/phpize# 配置
./configure --with-openssl --with-php-config=/usr/local/lamp/php/bin/php-config# 编译安装
make
make install# 添加扩展到php.ini
echo "extension=openssl.so" >> /usr/local/lamp/php/lib/php.ini
1.安装git(PHP扩展包放在git上的)
yum install -y git
1.安装composer
安装依赖
yum install zip unzip# 下载
php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"# 移动 composer.phar,这样 composer 就可以进行全局调用:
mv composer.phar /usr/local/bin/composer# 配置中国镜像
composer config -g repo.packagist composer https://packagist.phpcomposer.com# 查看镜像设置
composer config -gl
1.下载mongodb扩展
composer require mongodb/mongodb
1.写PHP代码操作mongodb
$client = new MongoDB\Client();
$db = $client->test;
crud操作
Linux下的Redis安装和使用
Redis服务安装
1.下载redis源码
wget http://download.redis.io/releases/redis-5.0.3.tar.gz
1.安装redis
tar xf redis-5.0.3.tar.gz //解压
cd redis-5.0.3//不需要配置参数不需要执行./configure
make && make install//编译&&安装
1.将redis设置为系统服务
cp ./utils/redis_init_script /etc/init.d/redis
vim /etc/init.d/redis //修改红框处的代码
修改redis.conf配置文件
mkdir /etc/redis //创建/etc/redis目录
cp ./redis.conf /etc/redis/redis.conf
vim/etc/redis/redis.conf
//将redis配置文件复制到redis
//设置为守护进程,以后台方式运行
使用service redis start命令启动redis服务.
1.将redis服务设置为开机启动
chkconfig --add redis
chkconfig --level 345 redis on
(本文由源码时代技术老师撰写,转载请注明出处)