Samba setup on the webroot in Ubuntu


What this is about:
LAMP, MAMP or WAMP… there are lots of packages out there you can install to enable you as a developer to set up a development environment on your machine. Products such as easyPHP, XAMP or Wampserver will get the job done with varying levels of difficulties and annoyance…

In my opinion the best environment to develop a web app is on a closer replication to your production server as possible. So, why not just use VMware? (guide to come on setting up a vm)

Download an iso of you OS of choice (for myself that would by Ubuntu), create a new Virtual Machine with you OS image and configure accordingly as you would do on your production server… simple.

There is then left one issue, how to access the files on the virtual machine as if local to the computer you working on.. well one answer is SAMBA.


How to install and configure Samba to your local apache webroot
1 – First install Samba:

apt-get install samba smbfs

2 – Configure the config file:
Set the workgroup and access, create a ‘share’ and create the respective users and groups for the samba and var/www.
As per usual make a copy of the config file before you start working (it is a lot easier to rollback to safe file than reinstall or write from scratch).

cp /etc/samba/smb.conf /etc/samba/smb.conf.original

3 – Now open the original to edit

nano /etc/samba/smb.conf

4 – Set the work group (this can be anything you choose) and the security within the [global] section:

[global]
workgroup = Ubuntu Precise Group
security = user

5 – Now create the share (add it to the bottom of the file). A ‘share’ is basically a block with some set params, ie the path to the shared folder.. etc ect. You can have mutliple ‘share’ blocks in your config file:

[share-www]
comment = Precise File
Serverpath = /var/www
browsable = yes
guest ok = no
read only = no
create mask = 0755

6 – Now the trickiest bit, although still quite straight forward:
Create a new group for the var/www directory

groupadd webdev

7 – Change owner of the var/www to be apache ‘www-data’, add the new group you created to the var/www directory (make sure you are in var here)

chown  www-data:webdev www

8 – Change the permissions of var/www to 0775

chmod 0755 www

(For more on permissions see this guide)

9 – Now, create a ‘samba’ user.

adduser samba

10 – Now create a password for the ‘samba’ server/program for the user:

smbpasswd -a samba

11 – Restart the samba server:

/etc/init.d/smbd restart

You should now be able to connect to you VM from you mac, ‘cmd’ + k: smb://yourvmdomain

Enter the samba username and password and away you go.

If you are having write issues (as in it asks for another password), ensure the permissions are ok as this is usually the issue..

Leave a Reply

Your email address will not be published. Required fields are marked *