ubuntu notes

Ubuntu server in VirtualBox

Basic setup taken from:
http://www.dividebyzero.co.za/blog/2011/11/setup-lamp-server-in-virtualbox/

1. Preparation
Before starting, you’ll need to download the following:
– VirtualBox (version 4.1.8 at the time of writing)
– Ubuntu Server 64-bit (11.10 at the time of writing)
– NetBeans IDE (7.0.1)
– PuTTY SSH Client
Begin by installing VirtualBox, NetBeans and PuTTY. Be sure to install the network host-adapters when prompted during the VirtualBox installation.

2. Create a new VirtualMachine
Open VirtualBox and create a New Virtual Machine.
When prompted, select the following:
Name and OS Type: You can call it anything you wish, I tend to name it after the distribution (e.g. UbuntuServer). Be sure to select Linux and Ubuntu (64-bit) as the Operating System.
Base Memory: The default is 512Mb but push this up to as much as your system can allow. I have 8Gb of RAM so I give the VirtualMachine between 2.5 and 3Gb.
Virtual Hard Disk: Ensure “Start-up Disk” is checked and “Create new hard disk” is selected
Virtual Disk File Type: Leave it as the default VDI unless you have other requirements
Storage Details: Set this to be Dynamically Allocated
Disk Size: This is down to your own preferences. I use a Dynamically Allocated storage type with a very spacious 50Gb maximum size limit.
Open the Settings of the new Virtual Machine and make the following changes:
System – Processor: Set this to an amount appropriate for your system. I have an i7 with 8 logical cores so I set this to 3 CPUs.
Display – Video: I tend to push the Video Memory up a bit but this isn’t strictly required for a Server setup.
Network – Adapter 1: Leave this set to NAT
Network – Adapter 2: Enable this Adapter and set to use “Host-only Adapter” / “VirtualBox Host-Only Ethernet Adapter” and set promiscuous mode = All.

3. Installing Ubuntu Server 64-bit

Now that all of the Virtual Machine settings are correct, it’s time to install Linux. Click on Start and when prompted, select the Linux Ubuntu Server ISO you previously downloaded.

Click Start to fire off the installation of the Server software:

  • Select your language and then select “Install Ubuntu Server”
  • Run through the setup by setting the language, region, and keyboard
  • Primary Network Interface: Select eth0
  • Hostname: you can enter anything you wish to uniquely identify the server. I usually call mine “thegrid”.
  • Partitioning Method: Select “Guided – use entire disk and set up LVM”.
    The next screen will give you one option so select that and then confirm that you want to “Write the changes to disks and configure LVM”. The screen after that asks you to confirm the maximum partition size. Use the entire partition so just leave the default value and select continue.
  • At this point the large part of the base installation will take place and may take a few minutes.
  • User Creation: Type in your full name on the first screen followed by the username that you will use to login on the next. Enter a password for your main user and finally confirm that you do not want to encrypt your home directory.
  • HTTP Proxy: This can be left blank.
  • You will be asked how you want to manage upgrades. Select “No Automatic updates” to ensure you have full control.
  • Software: When prompted, choose to install the following (use spacebar to select options):
    – OpenSSH Server
    – LAMP Server
    – Mail server
    – Samba file server
  • Postfix Configuration: You can leave the default “Internet Site” and then enter a system mail name (the hostname previously entered is used by default – use that and select continue).
  • The selected server software is now installed. This can take a few minutes to complete.
  • Install the GRUB boot loader? Select Yes

Installation is now complete.

Install php modules:
sudo apt-get install php-pear php5-dev make libpcre3-dev
sudo apt-get install php5-intl
sudo apt-get install php5-curl
sudo apt-get install php5-mysql
install apc
sudo apt-get install php-apc
sudo nano /etc/php5/apache2/php.ini
add to the end the extension:
extention=apc.so
restart apache
sudo service apache2 restart
Enable apache mod rewrite
sudo a2enmod rewrite

5. Assign a Static IP to Ubuntu Server

At this point, we assign a Static IP to the Ubuntu Server. This will allow you to SSH into the server from the Windows Host as well as to access VirtualHosts setup later.

Currently, only the first Ethernet Adapter 1 (eth0) has been setup within Ubuntu. This adapter bridges to the Host’s external connection and will allow the Ubuntu Server Guest to access the Internet.

Previously we changed the VirtualMachine’s settings to enable Ethernet Adapter 2 to use the VirtualBox Host-Only Adapter. It is through this Adapter that we can access the Guest OS from within the Host. VirtualBox always assigns “192.168.56.101? to this Adapter.

While logged into the Server, run:

1
sudo vi /etc/network/interfaces

Then add the following to the bottom of the file:

1
2
3
4
auto eth1
iface eth1 inet static
address 192.168.56.101
netmask 255.255.255.0

Finish by rebooting the system.

6. SSH into the Server using PuTTY

At this point I prefer to switch over to using PuTTY. SSH into the Static IP we have setup in the previous step.

We will use this terminal to finalise the setup of the Server.

7. Create SAMBA share

Firstly, we need to add a user to the www-data group group (replace “username” with your own):

1
sudo adduser username www-data

Now we give the group write permissions to /var/www

1
2
sudo chown -R root:www-data /var/www
sudo chmod -R 2775 /var/www

Now edit your smb.conf

1
sudo vi /etc/samba/smb.conf

And add the following (replacing username with your own):

1
2
3
4
5
6
7
8
9
10
11
12
[www]
comment = www
path = /var/www
public = yes
writable = yes
valid users = username
create mask = 0775
directory mask = 0775
force user = username
force group = www-data
follow symlinks = yes
wide links = yes

Create a SAMBA user with a password

1
sudo smbpasswd –a username

Now just restart samba and enjoy

1
sudo service smbd restart

You will now be able to Map a Network Drive in Windows Explorer and use \\hostname\www as the address.

8. Bind MySQL to the Static IP

In the SSH Terminal, run:

1
sudo vi /etc/mysql/my.cnf

Change bind-address from 127.0.0.1 to 192.168.56.101

9. Setup the Fully Qualified Domain Name

At this point if you restarted Apache, you would get the following error:

“apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName
… waiting .apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName”

To fix this, run:

1
sudo vi /etc/hosts

It should look like (replacing “thegrid” with your hostname):

1
2
3
4
5
6
7
8
9
10
127.0.0.1   localhost.localdomain localhost
::1     thegrid localhost6.localdomain6 localhost6
127.0.1.1       thegrid
 
# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

10. Setup a sandbox virtualhost

The default location for your websites on the Apache server is in /var/www/. We’ll setup a “sandbox” site but this procedure can be repeated for any other sites you need to create.

Firstly, create the site’s directory:

1
sudo mkdir /var/www/sandbox

Create a virtualhost configuration for the new site.

1
sudo vi /etc/apache2/sites-available/sandbox.localdev

Save the contents of the Apache config as:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 ServerAdmin webmaster@localhost
 ServerName sandbox.local.dev
 DocumentRoot /var/www/sandbox
 
 Options FollowSymLinks
 AllowOverride None
 
 Options Indexes FollowSymLinks MultiViews
 AllowOverride All
 Order allow,deny
 allow from all
 
 ErrorLog ${APACHE_LOG_DIR}/sandbox_error.log
 # Possible values include: debug, info, notice, warn, error, crit,
 # alert, emerg.
 LogLevel warn
 
 CustomLog ${APACHE_LOG_DIR}/sandbox_access.log combined

Enable the new Apache config:

1
sudo a2ensite sandbox.localdev

(You can disable sites by running a2dissite instead of a2ensite)

Restart Apache:

1
sudo service apache2 restart

Finally, enable access to the website from within your Windows Host by editing the C:\Windows\System32\drivers\etc\host file to include the line:

1
192.168.56.101     sandbox.local.dev

11. Setup Ftp

You must setup ftp in order Netbeans to workwith remote server.

Source: https://help.ubuntu.com/10.04/serverguide/ftp-server.html

vsftpd is an FTP daemon available in Ubuntu. It is easy to install, set up, and maintain. To install vsftpd you can run the following command:

1
sudo apt-get install vsftpd

after that configure vsftpd:

1
sudo vi /etc/vsftpd.conf

A working configuration is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
listen=YES
# no anonymous ftp
anonymous_enable=NO
# local users can ftp
local_enable=YES
write_enable=YES
# next 3 lines say that uploaded files will be writable by server
local_umask=002
chmod_enable=YES
file_open_mode=0775
dirmessage_enable=YES
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=YES
secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=vsftpd
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
# when ftp connected will have this a root folder
local_root=/var/www

Restart vsftp

1
sudo /etc/init.d/vsftpd restart

In some versions of ubuntu you have to rename pam_service_name to ftp

12. Setup NetBeans to use the remote server

You can access code in vbox via samba but it is very slow.

Open NetBeans and create a New Project (we’ll keep with the Sandbox example). Ensure you set it to be “PHP Application from Remote Server”

Under “Name and Location” type Sandbox for the Project Name. Select the appropriate Source Folder, set PHP Version to PHP5.3 and click Next.

Under “Remote Configuration” set the Project URL to http://sandbox.local.dev. Next click on Manage and setup the Remote Connection to use the new Ubuntu Server’s details. Set the Initial Directory to /var/www. If you don’t want to be asked to verify the connection each time specify a Known Hosts File (e.g. known_hosts.txt). This will save all trusted hosts so use the same file across all projects. Finally set the Upload Directory to “sandbox” and click Next.

Complete the New Project creation.

Lastly, click on File and select Project Properties. Under the “Run Configuration” ensure that the Upload Files setting is set to “On Save” and “Preserve Remote File Permissions” is ticked.

Now everytime you save the file it will be automatically synced with the Ubuntu Server. This means that you can continue to develop using NetBeans in Windows and immediately view these changes against your new LAMP server running locally on your laptop.


Comments are closed.