LAMP Install steps
- Install Ubuntu LTS release.
- Install apache2/httpd
- Install mysql-server
- Install PHP
Ubuntu LTS release
Download latest version from ubuntu.com - prefarably live CD/USB version. Create a USB boot drive (Rufus, UNetbootin or other options depending on OS). Try live version and install. Mine was a fresh install and accepted default partitions overwriting the entire disk.
Apache Install
Steps:
$ sudo apt update
$ sudo apt-get install apache2
# Check apache2 status
$ sudo service apache2 status
Visit http://localhost in a browser to check if default page is served.
Check Firewall status
# List Firewall
$ sudo ufw app list
# Get "Apache info"
$ sudo ufw app info "Apache Full"
# This should produce 80,443/tcp as output. If modifying default port, adjust settings accordinlgy. If this server is behind a router and needs to be accessed from outside, add port-forwarding in router and preferably assign a static ip.
Install MySQL server
Get the latest version from repository.
# update package index on server
$ sudo apt update
# Install mysql
$ sudo apt-get install mysql-server
# Perform secure installation steps
$ sudo mysql_secure_installation
# Test connectivity
$ mysql -uroot -p
Enter password:
mysql> show databases;
mysql> exit;
# Modify config files if changing default locations and restart.
# Create a new user
mysql> CREATE USER 'user1'@'localhost' IDENTIFIED BY 'password';
mysql> GRANT SELECT on `db1`.* TO 'user1'@'localhost';
# -- WITH GRANT OPTION to allow user to GRANT those privileges.
# Change password
mysql> ALTER USER 'user1'@'localhost' IDENTIFIED BY 'new-password';
# Change authentication to mysql_native_password
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new-password';
mysql>
# Start/Stop MySQL service
$ sudo service mysql stop
$ sudo service mysql start
# Default port is 3306.
Install PHP
$ sudo apt-get install php php5-mysql
# Restart Apache server
# Test php
$ vi /var/www/html/info.php
<?php phpifo(); ?>
# Visit http://localhost/info.php to verify#
Install openssh-server
# Install openssh server for ssh connectivity
$ sudo apt update
$ sudo apt install openssh-server
# search for service
$ ps -ef |grep ssh # should see sshd in the listing.
# Start/stop/restart service
$ sudo service sshd start (stop / restart)
# Change default port (22)
$ sudo vi /etc/ssh/sshd_config [ and modify port number, restart sshd]
# connecting to server from other box
$ ssh user@server -p<new_port_number>
Using MDADM create RAID5 Array (creation done once - assemble used for subsequent reinstall of OS)
I wanted to create a RAID5 array using three 3TB (WD Red) hard drives to serve as NAS for sharing media and files. RAID5 requires 3 disks minimum.
# Partition the drives. For > 2TB drives, use "parted" command to create the initial partition in GUID (GPT) format [reference: askubuntu]. My first attempt were with normal partitions (< 2TB) and the expected Raid disk size was way lower - around 4.2TB instead of 5.8TB expected.
Identify the disks:
$ sudo fdisk -l (or)
$ lsblk -o NAME, SIZE, TYPE...
# Create the Array (/dev/sda used by root disk)
$ sudo mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/sdb /dev/sdc /dev/sdd
# Monitor progress every couple of minutes
$ cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md0 : active raid5 sdd1[3] sdc1[1] sdb1[0]
5860267008 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [UU_]
[>....................] recovery = 1.7% (50472964/2930133504) finish=368.9min speed=130096K/sec
unused devices: <none>
$ cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md0 : active raid5 sdd1[3] sdc1[1] sdb1[0]
5860267008 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
# With the older partition (MBR style) the final result was:
$ cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md0 : active raid5 sdd1[3] sdc1[1] sdb1[0]
"4294702080" blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
# Create the file system
$ sudo mkfs.ext4 /dev/md0
# Create mount point
$ sudo mkdir -p /media/raiddsk
# Mount the file system
$ sudo mount /dev/md0 /media/raiddsk
# Add fstab entry (/etc/fstab)
UUID=xyz.... /media/raiddsk ext4 defaults 0 0
# Save Array layout
$ sudo mdadm --detail --scan --verbose > /etc/mdadm.conf
Raid disks scan using “mdadm”
After initial setup of raid disks using mdadm, reinstall of OS requires only assembling them.
# Install mdadm
$ sudo apt install mdadm
# Examine disks
$ sudo mdadm --examine --scan
# Assemble disks
$ sudo mdadm --assemble --scan
# Verify disks
$ lsblk # List block devies
$ lsblk -o NAME,UUID # List only those parameters
Output will be similar to:
sdb
└─sdb1 e658...
└─md0 4eed...
sdc
└─sdc1 e658...
└─md0 4eed...
# Recreate the directories and mount point.
# Add to /etc/fstab for persistence
$ sudo vi /etc/fstab
# Add /dev/md0 UUID. UUID can be obtained from "sudo mdadm --examine --scan"
UUID=xyz.... /media/raiddsk ext4 defaults 0 0
# Mount the file system
$ sudo mount /dev/md0 /media/raiddsk
# Get Details
$ sudo mdadm --detail --scan --verbose
will produce raid level, number of devices, uuid, name, and devices.
Install SAMBA for windows share
Install SAMBA and configure the directory to share. Secure access by permitting specific users.
# Install Samba
$ sudo apt install samba
# Modify config file to list shares
$ sudo vi /etc/sambsa/smb.conf
---------------------------------------
# Add directory entry. user1 is the only user who can access.
[myshare]
path = /media/raiddsk/sharedfolder
valid users = user1
writeable = yes
public = no
directory mode = 777
create mask = 0644
directory mask = 0755
force user = user1
browseable = yes
---------------------------------------
# Samba needs separate user account created
$ sudo smbpasswd -a user1
# Modify UFW firewall rules to allow Sambsa
# sudo ufw allow 'Samba'
# Restart service
# sudo systemctl restart smbd
# Assuming a static IP or DNS mount the share on a windows box.
# File Explorer -> Map Network Drive.
# Enter user name and password and connect.