- 软件安装
前提:服务器已配置好LNMP环境
安装libfastcommon
见FastDFS服务器安装文档(http://www.cnblogs.com/Mrhuangrui/p/8316481.html)
安装FastDFS
wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz -O FastDFS-5.1.1.tar.gz
tar -xf FastDFS-5.1.1.tar.gz
cd fastdfs-5.11
./make.sh
./make.sh install
安装php客户端
cd fastdfs-5.11/php_client/
phpize
# 获取php-config路径(which php-config),如果没有php-config命令,则需要安装php-devel
./configure --with-php-config=/usr/bin/php-config
make && make install - 配置文件修改
vim /etc/fdfs/client.conf
# 添加下面的配置, 注意修改tracker服务器地址为实际地址
connect_timeout=30 network_timeout=60 base_path=/fastdfs/FastDFSdata tracker_server=10.10.24.237:22122 #tracker_server=10.10.24.238:22122 log_level=info use_connection_pool = false connection_pool_max_idle_time = 3600 load_fdfs_parameters_from_tracker=false use_storage_id = false storage_ids_filename = storage_ids.conf http.tracker_server_port=80
- php.ini配置文件修改
# 编辑php.ini文件,开启文件上传功能,参数大小按实际需求设置
file_uploads = On
upload_max_filesize = 5M
max_file_uploads = 20
添加fastdfs_client默认配置(php.ini)
# extension = fastdfs_client.so # fastdfs_client.base_path = /tmp # fastdfs_client.connect_timeout = 2 # fastdfs_client.network_timeout = 60 # fastdfs_client.log_level = info # fastdfs_client.log_filename = # fastdfs_client.http.anti_steal_secret_key = # fastdfs_client.tracker_group_count = 1 # fastdfs_client.tracker_group0 = /etc/fdfs/client.conf # fastdfs_client.use_connection_pool = true # fastdfs_client.connection_pool_max_idle_time = 3600
pkill php-fpm
php-fpm
# 检测是否成功安装fastdfs php client
php -m|grep fastdfs - PHP测试
# 新建phptest.php文件
vim phptest.php
<?php
var_dump(function_exists('fastdfs_storage_upload_by_filename'));
$ret = fastdfs_storage_upload_by_filename('test.txt');
var_dump($ret);
?>
# 同级新建test.txt文件,内容随意
echo `date` > test.txt
php phptest.php
# 如成功返回信息中的bool为true
# 将返回信息的group_name和filename拼接起来就是完整的地址
转载于:https://www.cnblogs.com/Mrhuangrui/p/8318476.html