Fastdfs (file server) installation tutorial and PHP extension installation

Source: Internet
Author: User

The LNMP Integration Pack has been installed before installing FASTDFS, so install Fastdfs directly before installing Fastdfs_nginx_model (Nginx extensions) Preparation: Download Fastdif install package to/home/soft directory: http ://pan.baidu.com/s/1jh59oo21, installing fastdfs# cd/home/softs/fastdfs# tar xzf fastdfs_v4.06.tar.gz# cd fastdfs# VI make.sh Remove Comment with_linux_service=1 #/make.sh#./make.sh Install 2 configuration tracker2.1 Create and configure tracker Data Catalog # Mkdir-p/home/fastdfs/tracker# Vi/etc/fdfs/tracker.confbase_path=/home/fastdfs/tracker 2.2 Start tracker# service Fdfs_trackerd start 2.3 View Start # Netstat-a NP | grep 22122 3 Configuration Storage 3.1 Create and configure storage directory # Mkdir-p/home/fastdfs/storage/storage0# vi/etc/fdfs/storage.conf parts that need to be modified:
http.server_port=80
Group_name=group1
Base_path=/home/fastdfs
STORE_PATH0=/HOME/FASTDFS/STORAGE/STORAGE0
tracker_server=175.22.14.205:22122
3.2 Start storage# service fdfs_storaged start 3.3 View Launch # NETSTAT-ANP | grep 23000 4 Install fastdfs_nginx_model4.1, first download good Fastdfs_nginx_model extension 4.2 configuration mod_fastdfs.conf# cp/home/softs/fastdfs/ fastdfs-nginx-module/src/mod_fastdfs.conf/etc/fdfs/# vi/etc/fdfs/mod_fastdfs.conf Modification:
Base_path=/home/fastdfs
tracker_server=175.22.14.205:22122
Group_name=group1
Url_have_group_name = True
STORE_PATH0=/HOME/FASTDFS/STORAGE/STORAGE0
4.3. Update Nginx
cd/home/softs/lnmp1.4
VI lnmp.conf (the main modification of the black line will be OK)
 
download_mirror= ' https://soft.vpser.net '
 
nginx_modules_options= '--add-module=/home/softs/fastdfs/fastdfs-nginx-module/src '
php_modules_options= "
 
# #MySQL/MARIADB database directory##
mysql_data_dir= '/usr/local/mysql/var '
mariadb_data_dir= '/usr/local/mariadb/var '
# #Default website Home directory##
default_website_dir= '/home/wwwroot/default '
 
enable_nginx_openssl= ' y '
~
 
Update Nginx
cd/home/softs/lnmp1.4
./upgrade.sh Nginx "will be required to enter an Nginx version after operation, the current version is 1.12.1"
4.5 Configuring Nginx.conf
# vi/usr/local/nginx/conf/nginx.conf
 
 
location/group2/m00 {
Root/home/fastdfs/storage/storage0/data;
Ngx_fastdfs_module;
}
4.6, start Nginxlnmp nginx Reload 5, configuration client.conf
# vi/etc/fdfs/client.conf
 
base_path=/home/tmp
tracker_server=175.22.14.205:22122
http.tracker_server_port=80
6, test/usr/local/bin/fdfs_test/etc/fdfs/client.conf upload test.txt upload pictures/usr/local/bin/fdfs_test/etc/fdfs/ client.conf upload 111.png upload mp3/usr/local/bin/fdfs_test/etc/fdfs/client.conf upload 123.mp3 Part II, PHP extension FASTDFS_CLI ENT installation 1, installation, into the/home/softs/fastdfs/fastdfs/php_client directory execution:
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config
Make
Make
Install
File changes after execution 2, test
CP.. /conf/client.conf/etc/fdfs/
cat Fastdfs_client.ini >>/usr/local/php/etc/php.ini
CP fastdfs_test.php/home/wwwroot/default/(test the PHP extension for successful installation)
This PHP extension fastdfs_client is ready to play ... php test Fastdfs upload with PHP upload code form submission HTML
<body>
<form action= "upload.php" method= "post" target= "_blank" enctype= "multipart/form-data" >
<label for= "file" >Filename:</label>
<input type= "file" Name= "Upfile"
id= "Upfile"/>
<br/>
<input type= "Submit" name= "Submit" value= "
submit"/>
</form>
 
</body>
upload.php file code <?php//upload attachment
function Uploadattach () {/* {{{* * *
$ret = Array ();
$ret [' errorcode '] = 0;
$ret [' errormsg '] = ';
if (!$_files | | false = = Isset ($_files["Upfile"])) {
$ret [' errorcode '] = 1;
$ret [' errormsg '] = "Error:upfile is not set";
return $ret;
}
 
$file = $_files["Upfile"];
if (false = = Isset ($file [' tmp_name ']) | | false = = Is_file ($file [' tmp_name ']) {
$ret [' errorcode '] = 2;
$ret [' errormsg '] = "Tmp_name is not file";
return $ret;
}
if (0 = = filesize ($file [' tmp_name '])) {
$ret [' errorcode '] = 3;
$ret [' errormsg '] = "Tmp_name filesize is 0";
return $ret;
}
 
$curlFile = new Curlfile ($file [' Tmp_name '], $file [' type '], $file [' name ']);
$fileSuffix = Getsuffix ($curlFile->getpostfilename ());
 
$ret [' file '] = $file;
$ret [' fileId '] = Uploadtofastdfs ($curlFile, $fileSuffix);
return $ret;
}
 
/* }}} */
 
//Get suffix
function Getsuffix ($fileName) {/* {{{* * *
preg_match ('/\. ( \w+) $/', $fileName, $matchs);
return Isset ($matchs [1]) $matchs [1]: ';
}
 
/* }}} */
 
//Upload files to Fastdfs
function Uploadtofastdfs (curlfile $file, $fileSuffix) {/* {{{* * *
$fdfs = new Fastdfs ();
$tracker = $fdfs->tracker_get_connection ();
$fileId = $fdfs->storage_upload_by_filebuff1 (file_get_contents ($file->getfilename ()), $fileSuffix);
$fdfs->tracker_close_all_connections ();
return $fileId;
}
 
/* }}} */
 
function Start () {
$ret = Uploadattach ();
if (!empty ($ret [' fileId '])) {
$host _file = ' http://175.22.14.205/'. $ret [' fileId '];
Header (' Location: '. $host _file);
}
Print_r ($ret);
}
 
start ();
?>
Fastdfs File server cluster configuration (simplified version configuration) file server: main: 175.22.14.205 "Group1" From: 175.22.14.208 "Group2" From: 175.22.14.211 "Group3"  Add the following code to the HTTP zone in the primary server Nginx configuration nginx.cof file upstream fdfs_group2 {server 175.22.14.208;} Server configuration Entry added: location/group2/m00 {proxy_next_upstream http_502 http_504 error timeout invalid_header; #proxy_cache Http-cache, #proxy_cache_valid 304 12h, #proxy_cache_key $uri $is_args$args;proxy_pass http://fdfs_group2;expires  30d;} From the server configuration, add a server configuration to test

Fastdfs (file server) installation tutorial and PHP extension installation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.