Installing Ubuntu Server 12.04
added by Johan 1/13/13
Initial Ubuntu Server 12.04 Installation
Note: The following steps were done on a Linux Mint Desktop system.
Downloaded Ubuntu Server 32 bit 12.04 LTS (Long Term Support)
So I can learn about installing/configuring Linux Server, I installed and used VMWare Player (a free program). I have also tested Virtualbox, and I prefer VMWare, the biggest reason being VMWare has a NIFTY feature where it quickly installs a given OS, and bypasses most of the tedious steps involved in doing an OS install. If I go down a given path of testing installation of various software packages on Linux, and I later decide I don't like it, rather than go through all the tedious steps to "uninstall" a given program/package/desktop I can simply delete the Virtual Machine, and quickly re-install another one.
Note: Later when I want to actually Install Linux on "bare metal" (ie the actual machine) I can use a program called Imagewriter to copy the .iso image to a USB stick, boot into that on the actual machine, and install Linux.
When the "hard drive setup" step was reached, I used Manual configuration.
I created a boot partition, of 100M (100 Megabytes).
I created a swap partition, equal to the size of the amount of RAM installed in the target machine, which in my case is 4G (4 Gigabytes).
I created a root (commonly referred to as "/") partition of 50 GB
The remaining space was assigned to an Ext4 Journaling partition, and assigned it var (which is where the websites, databases, and their log files will reside)
Create a username/password for the user account, which will be administering the system.
Note1: This account will be assigned privileges which enable this user to enter into administrative mode.
Once the system is installed, and after logging into this account, the default mode is to prohibit this user from having administrative capabilities.
To enter into the mode of administrative capabilities we can either
a) preface administrative commands with the "sudo" command, OR
b) enter into administrative mode by enterting the command "sudo su" (my personal preference).
Note2: Ubuntu Server installs a root account, and assigns it a password.
From what I have read on the web, it is possible to set a password for the root account after the installation of Ubuntu Server has been completed, and yet it is recommended NOT to do so.
At the packages prompt, even though we are given the opportunity to install several packages, I only installed OpenSSH.
At this point, until I learn more about Ubuntu Server, I prefer to install the other packages later ie Apache, PHP, MySQL etc so I can see what is being installed, one package at a time.
Once I gain more experience with installing Ubuntu Server, I may change my methods about installing these other packages, and install them along with the base OS.
You are free to do whichever method you prefer.
I rebooted the machine when it reached the end of the initial install.
Assign the System a Fixed IP Address
After the system rebooted, I logged back in using the username/password created during the install.
entered the following commands to update the system:
sudo su (which will enter into administrative mode)
The system will prompt for the password setup during installation. Once you enter your password the prompt changes from a "$" to a "#", to let you know you are in "super user"/administrtaive mode.
The first step was to give this server a fixed IP address. Edit the following file, with the following command:
Note1: I like nano as my basic command line text editor. You can use whichever text editor you prefer.
nano /etc/network/interfaces
you will see a section which looks like this:
auto eth0
iface eth0 inet dhcp
I changed mine to look like this:
auto eth0
iface eth0 inet static
address 192.168.0.5
netmask 255.255.255.0
gateway 192.168.0.1
dns-nameservers 192.168.0.7 192.168.0.6
Note1: Set your IP address according to your own network design.
Note2: the last line is set to use my own 2 nameservers, and using their internal IP addresses
Restart the network by typing:
/etc/init.d/networking restart
To make sure the above process worked enter:
ifconfig
I also like to ping an outside network to verify we have network connectivity like this:
ping google.com
Note: After doing the above, (in a virtual machine) a PING did not work. This had me stumped for over an hour.
I found I needed to change the network settings in Virtualbox/VMWare from "NAT" to "Bridged Network", then things started working!
Update the Base Operating System
Once the network has been assigned a fixed IP address, the next step is to update the system.
Note: While the installation .iso file for Ubuntu is kept fairly current, there is still the possibility that certain files/programs have been updated, which have not been "rolled" into the download ISO file. In order to make sure the system has the latest versions of the software, which was put in place at install time, we update the system with the following 2 commands:
apt-get update
apt-get upgrade
(Note: The above step can take a while to complete).
Synchronize the System Clock
It is a good idea to synchronize the system clock with an NTP (network time protocol) server over the Internet. Simply run
apt-get install ntp ntpdate
and your system time will always be in sync.
Disable Screensaver on Ubuntu Server
After I started working with Linux Server, I noticed the screen had a habit of "going dark" after a while. At first I thought it was a problem with VMWare. Out of curiosity I Googled it, and what do you know? Even though this system doesnt (yet) have any type of windowing system installed, it STILL has a screen saver active?!
I found this to be somewhat annoying, so I disabled it:
nano /etc/default/grub
After an initial install, the parameter which needed to be changed looked like this:
GRUB_CMDLINE_LINUX_DEFAULT=""
After the edit mine now looks like this:
GRUB_CMDLINE_LINUX_DEFAULT="consoleblank=0"
Then run
sudoupdate-grub
On the next reboot the screen saver will be gone.
In addition, if you want the server to not display any messages during boot up, make the above entry look like this:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash consoleblank=0"
The "quiet splash" sections of the above cause the server to not post any boot messages to the screen.
This server will most likely not be rebooted very often, and I think it's a good idea to SEE the output of the boot process, so for now I will leave mine as set in the 1st example above.
Install Apache
The Apache2 web server is available in Ubuntu Linux. To install Apache2:
At a terminal prompt enter the following command:
apt-get install apache2
Notes: Apache Configuration Files
Apache is configured by placing directives in plain text configuration files. The main configuration file is called apache2.conf
. In addition, other configuration files may be added using the Include directive, and wildcards can be used to include many configuration files. Any directive may be placed in any of these configuration files. Changes to the main configuration files are only recognized by Apache2 when it is started or restarted.
The server also reads a file containing mime document types; the filename is set by the TypesConfig directive, and is mime.types
by default.
The default Apache2 configuration file is /etc/apache2/apache2.conf
.
You can edit this file to configure the Apache2 server.
You can configure the port number, document root, modules, log files, virtual hosts, etc.
Install PHP
Install PHP and the module enabling Apache to work with PHP:
sudo apt-get install php5 libapache2-mod-php5
Install MYSQL
Install MySQL Server and set root MySQL user password with the following command
(it will automatically prompt you for the MYSQL Root password during installation):
apt-get install mysql-server
If you want to be able to connect to MySQL from another host in your network (as I often do), we need to edit the my.cnf file:
nano /etc/mysql/my.cnf
and change the line that says:
bind-address 127.0.0.1
to
bind-address 0.0.0.0
The above will tell MYSQL to allow remote connections.
In order to be able to connect to MYSQL Server from another machine on my local network, I did the following:
Log into MYSQL from a command prompt:
mysql -u root -p
Enter the password you entered at MYSQL install step above.
Note: This will change the prompt to "mysql >"
mysql > grant all on *.* to 'root'@'%';
mysql > flush privileges;
mysql > exit
Restart Apache with the following command to ensure everything works properly:
/etc/init.d/apache2 restart
Installing Samba to Share Folders and Files
In order to setup shared directories/files on Ubuntu one way is to use Samba.
To install the samba package,enter the following command:
apt-get install samba samba-common smbfs
If you have installed a desktop GUI, also install GUI for samba:
apt-get install system-config-samba
Backup the smb.conf file, then delete it and create the new one:
cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
rm /etc/samba/smb.conf
touch /etc/samba/smb.conf
nano /etc/samba/smb.conf
Put the following into the smb.conf file (or change it according to your requirement):
#========================== Global Settings ===========================
[global]
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = insert-your-server-name-here
security = user
map to guest = bad user
dns proxy = no
#============================ Share Definitions ========================
[insert-desired-share-name-here]
path = insert-linux-folder-path-here
browsable = yes
writable = yes
guest ok = yes
read only = no
Save the smb.conf file and restart the service:
service smbd restart
Now you can access the samba share from Windows.
In order for users to be able to write to the share, go back to the server and do:
chmod -R 0777 insert-your-shared-directory-path-here
Change The Default Shell
According to one of the web sites I have been following, it says the following:
/bin/sh is a symlink to /bin/dash, however we need /bin/bash, not /bin/dash. Therefore we do this:
dpkg-reconfigure dash
Use dash as the default system shell (/bin/sh)? No
Note: I have not done this yet. I need to know more about this before I make this change. I list this here mainly for notes to my self.
Disable AppArmor
One of the web sites I have been following said the following:
AppArmor is a security extension (similar to SELinux) that should provide extended security. In my opinion you don't need it to configure a secure system, and it usually causes more problems than advantages (think of it after you have done a week of trouble-shooting because some service wasn't working as expected, and then you find out that everything was ok, only AppArmor was causing the problem). Therefore I disable it.
We can disable it like this:
/etc/init.d/apparmor stop
update-rc.d -f apparmor remove
apt-get remove apparmor apparmor-utils
Note: I have not done this step as of yet, until I gather a little more information about this topic.
Add a User to Ubuntu Server
If you want to add another user to Ubuntu, post-installation, then enter:
adduser newuser
where "newuser" is the name of the new user.
This will prompt you for the password for the new user, as well as a couple of other parameters. Beyond the password, the other parameters are not required, so if you simply hit Enter on these additional prompts, the default values will be entered.
To grant the new user Administrative privileges, do the following:
/usr/sbin/visudo
Adding the user’s name and the same permissions as root under the the user privilege specification will grant them the sudo privileges.
# User privilege specification
root ALL=(ALL:ALL) ALL
newuser ALL=(ALL:ALL) ALL
Save the file after entering the above line to the appropriate section.
Delete a User from Ubuntu Server
userdel username
where username is the account name of the user to remove.