Using PHP and MySQL to build web pages
Before we begin, let’s allow the user george
to connect to MySQL/MariaDB from any host, including the server that hosts php and the web server.
We will use %
to allow connection from all hosts:
MariaDB [(none)]> GRANT ALL PRIVILEGES ON `publications`.* TO "george"@"%";
Query OK, 0 rows affected (0.010 sec)
We will be creating the login.php
file which we will be using in other php
files.
This code will help us connect to the MySQL database with the user and password, and the publications
database will be selected.
This code is visible and executed only by the server, it is not visible by the web browser.
MySQL database tutorial
In this article we will work with MySQL databases - creation, adding records, etc..
To connect to a MySQL /MariaDB instance:
# mariadb -u user -p'user_password'
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 11.7.2-MariaDB-ubu2404 mariadb.org binary distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
To show current user’s rights/grants:
Use ZIP and SCP to archive and copy files remotely
We have a folder that we want to archive into a .zip
file and copy it to a linux server via scp
(secure copy, which uses the ssh
protocol).
Let’s add the files to a zip archive first, we can use the zip
utility with the -r
parameter to recursively add all files (*
) in the current folder and subfolders:
$ zip docker-1.zip -r *
adding: compose.yml (deflated 66%)
adding: config.inc.php (deflated 63%)
adding: docker-compose.yml-old (deflated 57%)
adding: Dockerfile.mariadb (deflated 19%)
adding: Dockerfile.nginx (deflated 18%)
adding: Dockerfile.php (deflated 30%)
adding: Dockerfile.phpmyadmin (deflated 24%)
adding: Dockerfile.php-old (deflated 30%)
adding: html/ (stored 0%)
adding: html/index.php (stored 0%)
adding: html/test.php (deflated 4%)
adding: html/mariadb.php (deflated 50%)
adding: html/404.html (stored 0%)
adding: nginx.conf (deflated 48%)
We can then supply parameters to the scp
command, to copy the resulting archive.
We use an alternate port via the -P
parameter, and a ssh
keypair with the -i
parameter.
Docker containers - LAMP stack to host a site with SQL and PHP
Introduction
Example of a LAMP stack to host a website
Introduction
Docker is set of technogies that allows us to run applications. It uses images that are built according to docker-compose.yml
. These images are deployed to containers, each including the software needed to run a web server, database, etc..
Dockerfile → (Build) → Image → (Run) → Container.
-
Dockerfile: contains a set of Docker instructions that installs and configures the software you specify.
Ansible - automating infrastructure and applications
Setting up VMs
Creating the git repository
Installing ansible with basic configuration and testing
Using YAML playbooks
Conditional statement when
Consolidating the playbook
Using groups and tags
Activating and enabling systemd services
Troubleshooting ansible commands and results
Setting up the virtual machines
Ansible does not need an agent installed on the target machines; it needs ssh acccess to the VMs.
For this tutorial, we will need a few VMs to test and ssh keys for a local user on the machines and for ansible acccess.
You can use VirtualBox for example, to create one VM and link clone it, so that you can save disk space.
You should also use bridged adatper for networking and assign static IP addresses in your router’s network settings. This way, the router will assign the IPs to the VMs and they will also access the internet.
I have created a VM, debian-1
, IP 192.168.1.105
, and created the same user and password from my main machine; this is to quickly ssh into the VM without entering additional credentials:
Create a new K8s deployment/cluster on MS Azure
First create the cluster in Azure Kubernetes, with the appropriate resource group and name.
We will be using the commandline tool az
from the Azure Cloudshell.
george [ ~/k8s ]$ az group create --location ukwest --resource-group myaksrg
{
"id": "/subscriptions/629a8f44-c84d-459e-bc17-64c887c78ced/resourceGroups/myaksrg",
"location": "ukwest",
"managedBy": null,
"name": "myaksrg",
"properties": {
"provisioningState": "Succeeded"
},
"tags": null,
"type": "Microsoft.Resources/resourceGroups"
}
Create a new cluster with 1 node and ssh key for accessing it.
az aks create \
--resource-group myaksrg \
--name myakscluster \
--node-count 1 \
--generate-ssh-keys
Run the below from the cloudshell to access the cluster:
Troubleshoot - Debian system not suspending
The below is shown in the virtual console:
Jan 08 18:24:04 dom kernel: Freezing user space processes failed after 20.006 seconds (1 tasks refusing to freeze, wq_busy=0):
Searching the sytemd
logs reveals more details, including the line fuse_simple_request
which points to the FUSE
layer.
Use journalctl -r
to list the most recent log entries, and the /
key followed by freeze
to search for the relevant log entry.
Jan 08 18:24:24 dom kernel: Freezing user space processes failed after 20.006 seconds (1 tasks refusing to freeze, wq_busy=0):
Jan 08 18:24:24 dom kernel: Freezing user space processes
Jan 08 18:24:04 dom kernel: Filesystems sync: 0.012 seconds
Jan 08 18:24:04 dom kernel: PM: suspend entry (s2idle)
Jan 08 18:24:04 dom kernel: PM: suspend exit
[..]
Jan 08 18:24:04 dom kernel: </TASK>
Jan 08 18:24:04 dom kernel: R13: 000056426d10c080 R14: 000056426c6d4100 R15: 000056426d10cc80
[..]
Jan 08 18:24:04 dom kernel: RIP: 0033:0x7fddceb1e52a
Jan 08 18:24:04 dom kernel: entry_SYSCALL_64_after_hwframe+0x76/0x7e
[..]
Jan 08 18:24:04 dom kernel: vfs_fstatat+0x80/0xb0
Jan 08 18:24:04 dom kernel: vfs_statx+0xa3/0x100
Jan 08 18:24:04 dom kernel: vfs_statx_path+0x9f/0xe0
-----------------------
Jan 08 18:24:04 dom kernel: fuse_do_getattr+0xf1/0x2c0
Jan 08 18:24:04 dom kernel: fuse_simple_request+0x17e/0x2c0
-----------------------
Jan 08 18:24:04 dom kernel: ? __pfx_autoremove_wake_function+0x10/0x10
Jan 08 18:24:04 dom kernel: request_wait_answer+0xd0/0x2a0
Jan 08 18:24:04 dom kernel: schedule+0x27/0xf0
Jan 08 18:24:04 dom kernel: __schedule+0x3ec/0xb00
Jan 08 18:24:04 dom kernel: <TASK>
Jan 08 18:24:04 dom kernel: Call Trace:
Jan 08 18:24:04 dom kernel: task:df state:D stack:0 pid:28146 tgid:28146 ppid:28145 flags:0x00004006
Jan 08 18:24:04 dom kernel: Freezing user space processes failed after 20.006 seconds (1 tasks refusing to freeze, wq_busy=0):
It is the file system in user space (FUSE) that uses the SSH File Transfer Protocol (SFTP) to mount a remote file system.
In the /etc/fstab
there is a mountpoint wich uses sshfs
to mount a remote filesystem.
Quicktip # Use alternate SSH port and private key to connect to a server
To connect to your VM via SSH custom port, and with a private key, use the below:
ssh -p 4123 -i /home/user/my-keypair1.pem admin@host.com
Use -p
for the custom SSH port (the default port is 22), and use -i /path/to/ssh-key
.
Debian log rotation for apache web server
To enable log rotation on Debian, you can use the logrotate
package, which is already installed.
You should enable and start the systemd service with this command - sudo systemctl enable --now logrotate.timer
.
You can use systemctl status logrotate.timer
to show the status of the logrotate.timer
unit, which is now active.
● logrotate.timer - Daily rotation of log files
Loaded: loaded (/lib/systemd/system/logrotate.timer; enabled; preset: enabled)
Active: active (waiting) since Sun 2025-01-05 21:38:02 UTC; 11s ago
Trigger: Mon 2025-01-06 00:00:00 UTC; 2h 21min left
Triggers: ● logrotate.service
Docs: man:logrotate(8)
man:logrotate.conf(5)
Jan 05 21:38:02 ip-172-31-27-178 systemd[1]: Stopped logrotate.timer - Daily rotation of log files.
Jan 05 21:38:02 ip-172-31-27-178 systemd[1]: Stopping logrotate.timer - Daily rotation of log files...
With the command systemctl list-timers
, you can list the enabled timers, which are equivalent to cron
jobs.
Debian APT Update System
This article will show you how to update your Debian system with the APT package manager.
To update the list of Debian packages, use apt update
.
george@dom:/media/george$ sudo apt update
[sudo] password for george:
Hit:1 http://deb.debian.org/debian sid InRelease
Hit:2 http://deb.playonlinux.com stretch InRelease
Hit:3 https://download.docker.com/linux/debian bookworm InRelease
Hit:4 https://packages.microsoft.com/repos/code stable InRelease
Hit:5 https://updates.signal.org/desktop/apt xenial InRelease
Hit:6 https://repo.steampowered.com/steam stable InRelease
Hit:7 https://dl.google.com/linux/chrome/deb stable InRelease
Get:8 https://apt.fury.io/wez * InRelease
Fetched 5,721 B in 7s (838 B/s)
884 packages can be upgraded. Run 'apt list --upgradable' to see them.
Use apt list
to see which packages can be upgraded on your system.
Useful console linux commands
Introduction
Below are some linux commands you might find useful.
They can be run from any terminal emulator (xterm, konsole, etc.) or from a virtual console by pressing Ctrl+Alt+F{1..12}
.
The uptime
console command shows the time (days) the computer has been up without a reboot.
admin@ip-172-31-27-178:~/quickstart$ uptime
15:11:49 up 42 days, 19:50, 1 user, load average: 0.00, 0.00, 0.00
For disk usage by filesystem, use the df
console command.
admin@ip-172-31-27-178:~/quickstart$ df -hT
Filesystem Type Size Used Avail Use% Mounted on
udev devtmpfs 475M 0 475M 0% /dev
tmpfs tmpfs 98M 544K 97M 1% /run
/dev/xvda1 ext4 7.7G 1.9G 5.4G 27% /
tmpfs tmpfs 486M 0 486M 0% /dev/shm
tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/xvda15 vfat 124M 12M 113M 10% /boot/efi
tmpfs tmpfs 98M 0 98M 0% /run/user/1000
If you want to see the memory usage in the Linux console:
Hello everyone
Thank you for visting this site.
It contains posts about using admin tools in the cloud and on your computer.