Increasing the PHP-FPM Memory Limit

Some PHP applications require the memory limit to be increased above the default value. When running PHP via FPM, this requires specific files to be changed. Crucially, after the configuration change, the correct service needs to be restarted. In my case, I thought restarting the webserver (apache2 in my case) would be required, but instead the PHP-FPM service needs to be restarted.

The commands below are for PHP-FPM version 8.1. Replace 8.1 with your specific version accordingly.

1
2
3
cd /etc/php/8.1/fpm
sudo nano php.ini
sudo systemctl restart php8.1-fpm.service

Synchronizing Files with Seafile Using the Linux Command Line Client

Today I managed to get a seafile client running on a Linux server and decided to write the necessary steps down in the hope that this will be helpful.

Installing the Command Line Client

Instructions on how to install seafile-cli: can be found here. For Ubuntu 20.04, the commands are:

1
2
3
4
sudo wget https://linux-clients.seafile.com/seafile.asc -O /usr/share/keyrings/seafile-keyring.asc
sudo bash -c "echo 'deb [arch=amd64 signed-by=/usr/share/keyrings/seafile-keyring.asc] https://linux-clients.seafile.com/seafile-deb/focal/ stable main' > /etc/apt/sources.list.d/seafile.list"
sudo apt update
sudo apt install seafile-cli

Initializing the Configuration Directory

Seafile needs a directory in which configuration data is stored. It is created and initialized as follows:

1
2
3
mkdir ~/seafile-client
seaf-cli init -d ~/seafile-client
seaf-cli start

Synchronizing the Files

The hardest part is to construct the command line for the sync command. It should look like this:

seaf-cli sync -l '1b71943d-392a-d9f2-c336-a2d681956ace' -s 'https://myserver.org' -d '/path/to/local/directory' -u 'user@domain.org' [-p 'MyPassword' -e 'MyLibraryPassword']

Possible pitfalls:

  • The library ID must be provided (as opposed to the library name). To find out the library ID, browse the contents on the Seafile web interface. The ID is part of the URL.
  • Although the documentation states that a user name is required, it is actually the user’s email address that has to be provided. When providing user names, the program fails with the error Bad request
  • If your password contains special characters (and it should!) then it has to be enclosed in single quotes (double quotes do not work)

Note: if passwords are not provided on the command line, the program asks for them during program execution, that’s why they are marked as optional.

That should be it hopefully 😉 Now you can check what the client does in the background with

1
seaf-cli status

How to Clone a HD/SSD to a Larger HD/SSD on Linux Systems

For an Ubuntu 20.04 server, I bought a new SSD and wanted to replace the existing SSD. Of course I wanted to keep all the existing data and replicate it to the new drive. In my case, the old SSD had a cpacity of 250 GB and the new one 500 GB. I decided to summarize how I achieved this for future reference and hope that it might be useful to someone else as well.

Make Backups

Before doing anything, make backups of everything because the following operations are not trivial and might damage the file system.

Connect the New Drive

Shut down the server and connect the new HD/SSD to your mainboard. Once connected, the new drive should show up when entering the command lsblk on the console.

Create a Clonezilla Live USB Stick

To clone the SSDs, I used the excellent tool Clonezilla. The instructions how to create a bootable USB stick can be found here. Once the stick is ready, plug it into your server and reboot. While rebooting, press the key for your mainboard’s boot menu (this is mainboard-specific, in my case it was F11) and choose the USB stick. Alternatively, reconfigure the sequence of the boot devices in your BIOS. The key to get into the BIOS configuration on startup is also mainboard-specific, but in most cases it is the DEL (delete) key.

Clone the Existing Drive to the New Drive

Once clonezilla is started, follow these instructions.

My clonezilla initially wouldn’t start up because it hung at the step Configuring keyboard. I could solve this by editing the command line for the clonezilla option. For that, highlight the option Clonezilla live (to RAM) and then press e. Now you should be able to edit the command line. Locate the parameter keyboard-layouts= and set a value, for example in my case keyboard-layouts=de (an American keyboard layout would be keyboard-layouts=us). Then press Ctrl + X to start Clonezilla.

For reference, I chose the following options:

  • Ask which action to take after finishing the clone operation
  • No file system checks

I am aware that this could also be achieved using dd, but this is not the best solution because this will result in a lot of unnecessary write operations on the new drive. Background: dd copies every single byte, even from areas on the source drive that don’t contain any data (zero bytes). Refer to this askubuntu page for more details.

After clonezilla finished, disconnect the new drive and then reboot the machine with only the new drive connected. If everything worked fine, your server should start up exactly as before.

Adjust the Partition Size

Run the command lsblk again. You will notice that the new drive still shows the capacity like the old drive. The reason is that the partition tables were also copied, and these now still contain the values for the old drive.

To update the partition table, run the command parted with the partition to be altered as parameter. For example, if the new drive has the device name /dev/sdc and the second partition is the one to be altered, run parted /dev/sdc2. In parted, enter print to show the partitions again and verify the number of the partition to be altered (in my case 2).

In the next step, enter resizepart 2 (if 2 is the partition number). You will be promted for the new size of the partition. Because I wanted the partition to take all the remaining space, I entered the complete size of the new SSD (in my case 500GB). Because of the boot partition, which takes about 512 MB and some additional space needed for the file system, the effective size of the partition is smaller (about 465 GB), but higher values can be entered, resulting in the remaining available space automatically.

The last step is to make the whole partition size available to the filesystem. This is done with the command resize2fs /dev/sdc2 (adjust device and partition name accordingly), which works for ext2, ext3 and ext4 file systems. I found the essential information about this part on this stackexchange page.

That’s all. I hope this will help you to upgrade your Linux system drives.

List of Useful Linux Commands

This post contains a collection of useful Linux commands for the Ubuntu distribution. The list is extended every time I find a new handy command. Most of the commands are also applicable to other Linux distributions. Use commands in red with caution.

File System Commands

Description Example
Display Current Working Directory pwd
Change Current Working Directory cd /path/to/directory
Show All Files in Current Directory (Including Hidden Ones) ls -la
Show Sizes of All Files and Directories in Current Directory du -sh *
Show Available Disk Space df -h
Copy File cp /source/file /destination/file
Move or Rename File mv /source/file /destination/file
Create Directory mkdir myDirectory
Delete File rm /path/to/file
Delete Directory Recursively rm -rf /path/to/directory
Create Symbolic Link ln -s /path/to/target /path/to/symlink
Change File Permissions (non-recursive) sudo chmod 644 /path/to/file
Change File Permissions (recursive) sudo chmod -R 644 /path/to/directory
Change Owner of File (non-recursive) sudo chown user:group /my/path
Change Owner of Symbolic Link (non-recursive) sudo chown -h user:group /my/symlink
Change Owner of Files / Directories (recursive) sudo chown -R user:group /my/path
Count Files (recursive) find /my/path -type f | wc -l
List Number of Files (recursive) for Each Subfolder find . -type f | cut -d/ -f2 | sort | uniq -c
Find Files Older Than a Specified Number of Days (non-recursive) find /path/to/directory -maxdepth 1 -mtime +60 -type f -print
Find Files Older Than a Specified Number of Days (recursive) find /path/to/directory -mtime +60 -type f -print
Delete Files Older Than a Specified Number of Days (non-recursive) find /path/to/directory -maxdepth 1 -mtime +60 -type f -delete
Delete Files Older Than a Specified Number of Days (recursive) find /path/to/directory -mtime +60 -type f -delete
Show All Disks and Partitions lsblk
Show File Systems for all Disks and Partitions lsblk -f
Format Partition with File System sudo mkfs -t ext4 /dev/sdf2
Mount Drive sudo mount /dev/sdc1 /mnt/mountpoint/
Unmount Drive sudo umount /dev/sdc1
Mount USB Stick pmount /dev/sdf1
Unmount USB Stick pumount /dev/sdf1
Check File System sudo fsck -p /dev/sdc1
File System Commands

Viewing, Editing and Comparing Files

Description Example
Display File Contents cat /path/to/file
Edit File sudo nano /path/to/file
View End of File less +G /path/to/file
View End of File and Update Automatically tail -f /path/to/file
Compare Files in Two Directories Recursively diff -rq /path/to/dir1 /path/to/dir2
Viewing, Editing and Comparing Files

User Management

Description Example
List All Users cut -d: -f1 /etc/passwd
List All Groups cut -d: -f1 /etc/group
Add New User sudo adduser john
Show Groups a User is Assigned to groups john
Add User to Group usermod -a -G examplegroup john
User Management

Package Management Commands

Description Example
Update Package Index sudo apt update
List Upgradable Packages apt list --upgradable
Upgrade Installed Packages sudo apt upgrade
Install Security Updates sudo unattended-upgrade -v
List All Installed Packages apt list --installed
Show Version of Installed Package apt list <package name>
Show All Versions of a Package apt list -a <package name>
Package Management Commands

Network / Internet / Firewall Commands

Description Example
Check Host Availability ping [IP or hostname]
Download File curl -O [URL]
List Open Ports sudo lsof -i -P -n | grep LISTEN
Open Firewall to Specific Port from Local Subnet sudo ufw allow from 192.168.1.0/24 to any port 22
Delete Firewall Rule by Number sudo ufw status numbered
sudo ufw delete 42
Connect to FTP Server ftp myserver.org
Connect to SFTP Server sftp user@myserver.org
Network and Firewall Commands