Skip to main content

Senior Web Engineer. Open web / music. Remote DJ. Tall Dutch guy. #3million

micro.blog/sander

svandragt

mixcloud.com/cloudseer

 

Howto setup Python in Pop!_OS 19.10 or Ubuntu

A new OS, another two hours wasted. Pop!_OS 19.10 comes with Python3.7rc5, which is nice but my project requires 3.6 just now. As you know we've gone through this before, but this time we can setup multiple python version support.

Let's setup pyenv, pip, pipenv and then install another python version.

# Setup pip.
curl
https://bootstrap.pypa.io/get-pip.py | python

# Pip can setup pipenv.
pip install pipenv --user

# Manage multiple python versions through pyenv.
# @see https://github.com/pyenv/pyenv/wiki/Common-build-problems

sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \ libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \ xz-utils tk-dev libffi-dev liblzma-dev python-openssl git
curl https://pyenv.run | bash

Follow the instructions to add pyenv to the path. Now we can do stuff like:

# install another python version.
pyenv install 3.6.9

# OR let pipenv do it.
cd ~/dev/myproject
pipenv install --dev

Leave a comment if you have any issues, as this was written retrospectively.

 

Trying an Ubuntu 18.04 setup with XFCE, plank, albert, Ubuntu fonts and unsplash.

 

How to install the NVIDIA drivers on Ubuntu 18.04

sudo ubuntu-drivers autoinstall

If this fails because of a dependency that won't be installed, use apt for both the driver and the dependencies.

 

PHPStorm font rendering on OpenSUSE

On Ubuntu LTS the font rendering on 2019.1 looked great by default, but on Tumbleweed I needed to tweak the settings a little to get the editor to look good. There is conflicting information out there for out of date versions of OpenSUSE and PHPStorm and it took a bit of research to figure out what works for me.

Under Help | Edit Custom VM Options... I added the following lines:

-Dswing.aatext=true
-Dawt.useSystemAAFontSettings=on

I also set antialiasing (within the main PHPStorm Settings | Appearance menu) to greyscale.

Finally, I added the Dreamweaver CC colour scheme to the editor by saving the xml file in ~/.PhpStorm2019.1/config/colors/.

Restart the application and select the color scheme from File | Settings | Editor | Color Scheme

Sources: sheelahb.com

 

 

I'm taking the opportunity of Dropbox no longer supporting the Ubuntu 18.04 recommended file system (?!) to try out Antergos with KDE.

 

So you want to become a neckbeard?

Having wasted too much time installing Ubuntu on a laptop recently, I thought it would be helpful for the future self to document the issues.

Issues

I'm seeing one or more of the following issues with Ubuntu 18.04 LTS:
  • Missing text on the login screen
  • second monitor switching off
  • Hangs
  • Won't boot  directly into the OS
Install Ubuntu 16.04 LTS which is not a piece of garbage.
Migrate SSH keys from Putty to OpenSSH https://askubuntu.com/questions/818929/login-ssh-with-ppk-file-on-ubuntu-terminal/818932
What are the correct permissions for the .ssh folder? Typically you want the .ssh directory permissions to be 700 (drwx------) and the public key (.pub file) to be 644 (-rw-r--r--). Your private key (id_rsa) should be 600 (-rw-------). Lastly, your home directory should not be writeable by the group or others (at most 755 (drwxr-xr-x)).
How do I connect to our team networkshare automatically on startup?
sudo su
apt install cifs-utils
echo "//path/to/windows-share /mnt/team cifs credentials=/etc/samba/credentials,uid=1000 0 0" >> /etc/stab
cat > /etc/samba/credentials <<EOC
username=UserName
password=PassWord
EOC
chown root.root /etc/samba/credentials && chmod 400 /etc/samba/credentials
Change the username and password appropriately verify your userid is 1000 with id -u UserName
I skipped  creating a passphase for my encrypted home directory, how do I do it now?  run "ecryptfs-unwrap-passphrase" in the terminal
How to stop the mouse sticking to the edges of the display https://askubuntu.com/questions/119281/what-is-the-function-of-the-sticky-edges-on-off-setting-in-di...
Can't install vagrant plugins Download vagrant from vagrantup.com
nfsd is not installed sudo apt-get install nfs-kernel-server
vagrant booting vms reports a timetout delete (rm) the IdentityFile mentioned in vagrant ssh-config

This document will get updated as I stumble and fix other issues.

App Alternatives

Clipboard manager https://hluk.github.io/CopyQ/
Remote connection manager https://snapcraft.io/pac-vs
Google Drive https://www.howtogeek.com/196635/an-official-google-drive-for-linux-is-here-sort-of-maybe-this-is-al...
Phrase Expansion https://leehblue.com/ubuntu-text-expander/ https://github.com/leehblue/texpander
Screen Recorder Kazam (https://askubuntu.com/a/29954), installs well with apt. Alternatively Simple Screen Recorder.

 

Fix slow DNS responses on Ubuntu

I've been finding that browsing has been slow for me lately on my linux box, which has Ubuntu 16.04 installed. After some investigation it seemed worthwhile to try to install a DNS cache to speed up DNS queries. This has sped up successive DNS queries from 21ms to 0ms, removing sluggishness.

sudo apt install bind9
cd /etc/resolvconf/resolv.conf.d
sudo echo "nameserver 127.0.0.1" >> head

Apply the configuration as follows:

sudo resolvconf -u

The improvement can be seen by using dig to query a domain and looking at the Query time output. After the first dig, subsequent digs return in 0 ms.

 

How to install pip and pipenv properly on Ubuntu 17.10

Ubuntu 17.10 comes with python3 3.6.3 installed by default but not pip and pipenv. We can install install pip systemwide and pipenv into the user local bin so we can use all the convenience when working with our python projects:

wget https://bootstrap.pypa.io/get-pip.py -O /tmp/get-pip.py
sudo python3 /tmp/get-pip.py
pip3 install --user pipenv
echo "PATH=$HOME/.local/bin:$PATH" >> ~/.profile
source ~/.profile

Sources: Installing Python 3 on Linux; pip installation; Installing pipenv; How to permanently set PATH on Linux

Update 9 Nov 2017: replaced curl with wget, thanks Peter

 

Painless Lektor Setup in Less Than 5 Minutes

Two technologies that I have can really recommend you try out - Lektor and Cloud9 - can be used together to start a static site or blog in a matter of minutes. If you want to try out the power of Lektor without leaving a trace on your machine then follow this quick setup.

Lektor is a flexible and powerful static content management system for building complex and beautiful websites out of flat files — for people who do not want to make a compromise between a CMS and a static blog engine.

Cloud9 combines a powerful online code editor with a full Ubuntu workspace in the cloud.

Because every Cloud9 workspace is also a Docker container, you have full access to a ubuntu system with terminal access. We can use this to install a development Lektor install and work on our static website as follows:

  1. Create a new Cloud9 workspace with the Python template, as Lektor is written in Python.
  2. Delete the ex50 folder
  3. In the bash tab of the new workspace, install lektor by running: curl -sf https://www.getlektor.com/install.sh | sh
  4. Once this completes, start a new project: lektor quickstart
  5. Create a new runner (Run > Run With > New Runner) with the following contents (replace myproject):
    {
    "cmd" : ["lektor", "server", "-p", "8080", "-h", "0.0.0.0"],
    "info" : "Started $project_path",
    "working_dir": "/home/ubuntu/workspace/myproject"
    }
  6. Press the Run button to start the server, and Preview > Preview Running Application to browse the Lektor site.

That's all there is to it, you can continue with the Lektor Quickstart instructions.

 

 

 

Setting up a VM based development system - Part 1

I recently set up a local development server running Ubuntu on VMware player. I thought it would be interesting to document the process and instructions so that it will be useful to others, and you can follow along / correct / improve this guide. On completion of this series you will end up with a complete LAMP local development system..

Installing Ubuntu

You will need:

Install VMware player (VMP). Restart the pc if necessary.

I’m installing the virtual machine on my USB harddisk, this way I can take my whole development with me on the go (home/work) - this is great because you only have to set all this up once, instead of on every machine you plan to use it on.

Start VMP and “Create a New Virtual Machine” and browse to the downloaded .iso. As part of the Easy Install Information write down the login:

username: __________ password: __________ 

Store the VM on your removable drive.

On the Specify Disk Capacity screen you will want to go higher than the recommended disk size, I chose double (40GB). Make sure you have enough free space available, check this before continueing. I went for double the recommended amount as I want to avoid to repartition later. Accept the other defaults and Ubuntu will start. Keep waiting as Easy Install is installing Ubuntu on your behalf.

If you are a chmod 777 user (jackpot settings), this is a great time to read up on file system permissions by reading the article series starting with “Linux File Permission Concepts” (click next in the summary, there are 5 articles in total): http://articles.slicehost.com/2010/7/17/linux-file-permission-concepts

After a restart the login screen appear and after a successful login you will see the desktop. Because we are going to install a bunch of software let’s make sure everything we already have is up to date. Start the update manager > Settings > Ubuntu Software > Other > Select Best Server. This will speed up downloads. Check again and install updates.

Time to read some more, btw have you created a new tag for all these bookmarks yet? When you are finished reading the above articles, here are some really good resources to read later:

You should now have a running Ubuntu system.

(Source: donationcoder.com)

 

Why MySQL does not start

The other day I was provided with a new Ubuntu server with a large data drive. It seemed a good idea to move (among other things) the mysql data folder onto this drive.

[code language="bash"]

sudo mv /var/lib /var/media/lib
sudo ln -s /var/media/lib /var

[/code]

However when trying to start MySQL it will no longer start:

[code language="bash"]

service mysql start
start: Unable to connect to system bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory

[/code]

The whole reason I did use a symbolic link was to avoid issues like this. What to do? It turns out AppArmor does not allow mysql to read out of the new /var/media/lib location, as noted in the my.conf file:

[code language="bash"]

# * IMPORTANT
# If you make changes to these settings and your system uses apparmor, you may
# also need to also adjust /etc/apparmor.d/usr.sbin.mysqld.

[/code]

Simply open the mentioned file, duplicate the /var/lib/mysql lines and correct the path to the new locations. Restart AppArmor (or reboot) and Mysql can be started. Verify this by running:

[code language="bash"]
ps -ef | grep mysql
[/code]

 

Rotate PHP logs

Our php.log was nearing 550MB so I was investigating how to rotate the logs. The easiest solution seems to be using logrotate (ubuntu linux) with a script like follows.

sudo nano /etc/logrotate.d/php5
/var/log/php5/*.log {
   daily
  daily
   14 days
  rotate 14
  missingok
  nocompress
  sharedscripts
  postrotate
  apache2ctl graceful
  endscript
}

You can check the configuration by running logrotate --force /etc/logrotate.d/php5