Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Separate file server for a php website

I have two servers for a website. One server will have php code and database and another less speed server to store files only. I need to implement these in a way that file uploaded through the website must store at another server and also then can be downloaded from there.

Can anyone suggest me best way to achieve that. I know the files can be transferred to another server by FTP functions of php just after uploading through website but doesn't seems a correct way.

Or two server can be used for static media content like images only.

Thanks

like image 687
phpian Avatar asked Aug 19 '11 12:08

phpian


4 Answers

The best idea is to just have ALL the files, including the websites files on the "storage server". Basically what you do is mount the "shared folder", this means the websites files and other files you will be needing. (Most of the times you just have a /var/www-local/ folder on the storage server, which you mount in /var/www/ on the webserver).

Make sure you mount it using NFS by adding it in the /etc/fstab file on the webserver. (More info on NFS)

The advantage of this idea is that when you want to expand, this is easily possible by putting a software loadbalancer (like HAProxy), adding as much webservers as you like and you will have your data in sync.

like image 161
Kenny Avatar answered Sep 21 '22 10:09

Kenny


I've used something called Gluster which allows for things like this. The situation I use it for is more for load balancing than for alternate content distribution.

Also, sites like Stack Overflow use Content Distribution Network services for certain pieces of information on their site. A solution like this might actually be more cost effective than buying/setting up/maintaining a whole new server.

like image 25
afuzzyllama Avatar answered Sep 18 '22 10:09

afuzzyllama


May be you can mount the upload directory to your web server. Check Linux NFS

like image 43
xdazz Avatar answered Sep 17 '22 10:09

xdazz


Don't know if this is the best way, but why not simply have the file server a separate subdomain? That way it can handle all of the file download minutia and you can connect to it via FTP or SFTP from the main server.

Basically, here is a process you could use:

  1. Point your subdomain at the secondary server. I found some information on that here.
  2. Have an upload form on your main server which processes and validates the file.
  3. When the file is deemed acceptable, send it to the other server via FTP or SFTP. If you can't get the PHP tools working for this, phpseclib might help. You may want to make this step multi-threaded.
like image 25
cwallenpoole Avatar answered Sep 18 '22 10:09

cwallenpoole