What are we doing here?

This blog includes a series of videos and references to help new users or enthusiasts better understand how to use open source and free technology tools. The quick links includes more information for accessing many of the tools covered along with other references to learn more for taking advantage of these tools.

Click HERE to see the full list of topics covered!

LAMP stack setup on Alpine Linux



This video covers setting up a LAMP stack (Linux+Apache+MySQL(Maria)+PHP) in Alpine Linux. Alpine is a super lightweight distro popular with developers using Docker, but also a valid choice for VM work or standalone implementation. 

This video walks through the process of setting up the various components of LAMP, though omits the Alpine install (it takes minutes if you know what you want and what your doing - select sys). Overall I'm quite impressed with Alpine, though there would certainly be conveniences just running Ubuntu Server, Alpine does the job with a fraction of the CPU/memory/capacity/cruft so if you can figure out how it can work for you, I think its worth a look.

Here are the steps shown in the video:
Alpine LAMP deployment

apk add apache2

apk add mariadb mariadb-client

rc-service start apache2

Check the homepage at the machine's IP, confirm you see 'It works'

Source files are located in /var/www/localhost/htdocs#

Ensure repositories are added - /etc/apk/repositories  <- uncomment commmunity and edge

apk add php7 php7-mysqli phpmyadmin php7-apache2

service restart apache2

Create php test doc - nano phpinfo.php

service mariadb start

Setup Maria

Error message appears, need to first run the /etc/init.d/mariadb setup

Re-run service mariadb start

Then we change the password for mariadb root user (this gets created on the system by the mariadb-client).
Run mysql_secure_installation

Walk through the prompts to set a root user password

Setup phpmyadmin

chmod -R 777 /usr/share/webapps/phpmyadmin
chmod 755 /etc/phpmyadmin/config.inc.php
ln -s /usr/share/webapps/phpmyadmin/ /var/www/localhost/htdocs/phpmyadmin


Setup phpmyadmin user in MariaDB
mysql -u root -p
 - enter password

>CREATE USER 'pmauser'@'%' IDENTIFIED BY '<password of choice>';
>GRANT ALL PRIVILEGES ON *.* TO 'pmauser'@'%' WITH GRANT OPTION;
>FLUSH PRIVILEGES;

Open page server IP/phpmyadmin.

Enter the pmauser and given password.

Now phpmyadmin can be used to manage the mariadb and create new databases

<missed this in the video>
To ensure services start on boot need to run 
rc-update add <service name>

The last line are steps to ensure apache2 and mariadb are started if the system reboots, an 'auto-restart' or 'start on boot' behavior. 

References I found helpful for setting this up are below:

I do understand that this stack isn't necessarily the best in terms of performance or security, its simply the 'bare-minimum' to start developing. For optimization I'd suggest reading more on general Apache or NGINX settings, as well as looking to additional 3rd party sources about the various ways to integrate PHP with a web server. 

Setting a Samba (SMB / CIFS) share in Ubuntu



This video is designed to run through the steps for setting up an SMB share in Ubuntu. All steps are shown as based on the Ubuntu tutorial blog, but I wanted to explain some of the steps - like adding a user who can act as the dedicated SMB login account.
https://ubuntu.com/tutorials/install-and-configure-samba#1-overview

The process of using the command line to interact with a remote system is very important for more advanced Linux usage, and we spend a lot of time in the command line using SSH, and that can be setup when first installing Ubuntu Server. Of course with Linux everything can be done, undone, and redone using the command line, so important to get your feet wet if you really want to delve into Linux.

Previously, I ran through similar steps using FreeNAS which has a useful GUI for setting up the share. FreeNAS with its ZFS file system is definitely useful for robust data protection which may or may not apply depending on how the underlying Ubuntu install is set up. FreeNAS is also very useful for advanced shares like NFS, iSCSI, S3, AFP, and SMB. Essentially it saves users from having to install services and config files for each type of share.

Where this is useful is for creating file shares on systems not designed for FreeNAS. For example in a virtual machine, on smaller systems like the Raspberry Pi, or even an old laptop which only has 1 hard drive where FreeNAS typically will need at least 2~3 drives (one for boot and another 2 for data with mirroring).

Beyond setting an SMB share itself, the end of the video mentions additional steps to help protect data. Personally I have a simple SMB share on an old notebook sharing a folder/directory on the boot drive, then to protect that I backup the files to an external drive using over a USB cable. In Ubuntu, a USB drive gets mounted under the system folder /media and users can schedule a nightly backup using a cron job.

In the terminal, run crontab -e.

The file will open and scroll to the bottom. The first five spaces represent: 
  • m - minute
  • h - hour
  • dom - day of month
  • mon - month
  • dow - day of the week (0-6, 1-7 - 0 & 7 both are Sunday)

The picture is an example that runs the copy command, cp -uR, at midnight and 12 noon everyday with the * symbol representing 'any'.

Note there are many other commands and ways to back up using cron jobs, just cp -uR is likely one of the easiest and is quite performant.

Use other distros?
I also recently in reading up on Docker, stumbled upon a very lightweight distro called AlpineLinux. It can be set to host an SMB share and a host of other things just like Ubuntu - steps are largely the same.

TIP: In AlpineLinux, ensure when running 'apk add samba' you also add the samba-common-tools, which are needed to run smbpasswd. 

What Alpine is useful for is just being small. To compare, Ubuntu desktop .iso is around 2.1~2.5 GB in size now; Ubuntu server that doesn't have the desktop runtime and graphical elements - is around 800 MB; Alpine is only around 120 MB. Of course, Ubuntu has things like firewall ufw and other features baked in out-of-the-box to make it quick and easy to get up and running, but I like Alpine for portability and makes a good test environment for running in a VM, on a Raspberry Pi, or something else.

Finally, I wanted to say THANK YOU to the Ubuntu Podcast who were kind enough to mention this blog in a recent episode. I hope these tutorials are useful, and while I am having trouble keeping a regular cadence, I hope the blog itself helps to consolidate the material so its available anytime for anyone. 

Thank you for reading this far. Hope to have some more on creating a web server and basic PHP tips soon.