Categories
Software Development Web Development

How to install and configure Golang development environment on Ubuntu Linux

I am still working on this article as all information I’ve found about how to set PATH system wide in Ubuntu is totally wrong. I’ve yet to find a way to set Go in the PATH system wide on Ubuntu. The info in Golang Docs is even wrong for Ubuntu. This article will be updated when I discover the secret of Ubuntu PATH.

I wanted to know why Go documentation suggested saving PATH as it did, I get tired of not knowing why things are suggested. In this article I dig a little into setting PATH on Ubuntu and Linux in general.

First off go to the Golang website and download the latest version of Go. It doesn’t matter if it is in your Downloads folder, the following command unpacks it to the proper location.

Follow the instructions to unpack it for example

tar -C /usr/local -xzf go1.15.6.linux-amd64.tar.gz

but with your version number you downloaded.

Now here is where I explain some things. The next step where it talks about setting the PATH environmental variable let me explain some things.

Where it says the following in the docs:

Add /usr/local/go/bin to the PATH environment variable.
You can do this by adding the following line to your $HOME/.profile or /etc/profile (for a system-wide installation):

These are the locations Linux usually will get environmental variables from.  Here is a link to explain /etc/profile I wanted to know what it did. Here is another link with more details. As you can see /etc/profile is one of he locations where linux gets things such as Environmental variables for the entire system.

The other $HOME/.profile refers to the logged in users home directroy .profile file. This is another location Linux looks for user environmental information. This article explains more about users profile files.

You can set the PATH there with this as they show :

export PATH=$PATH:/usr/local/go/bin

You put that in one of those files and what Linux does is it is adding that value to the current value for PATH you can also add it to the PATH variable for your entire system (not on ubuntu), located at /etc/environment  environment is a file. Open it with vim and you will see a really long string PATH=”longlines”

You can add to it by putting this at the end

:/usr/local/go/bin

So you will end up with something like
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/go/bin"

The way above using /etc/environment apparently isn’t system wide  on Ubuntu because of the way it disables the root account and uses something else a file called /etc/sudoers to store the PATH variable for the root user. Do not edit that directly you can destroy your login and system. User a tool called visudo.

The other ways work fine. If you add the path only to your regular user account in .profile then go won’t be available to root if you somehow need it.

/etc/profile (for a system-wide installation) is a little better because all users will have access. Otherwise each user you create you will have to add the PATH info to their .profile file, it gets to be a pain.

WARNING :
Doing it this way makes golang only available to the logged in regular user, at least on Ubuntu. /etc/environment is supposed to set PATH system wide but it doesn’t   on ubuntu.

I just wanted to dig and see why the docs suggested what it did. I get tired of everything in tech just telling people to do things without any explanation or links to info.

Next up setting configuration values, especially GOPATH – not so necessary from what I’ve been told. But the link explains the GOPATH and how to set it. I would do this because you will see many examples refer to GOPATH and you need to know what it is.

Categories
Resources Web Development

How to list and install php modules on ubuntu linux

I always, always forget how to do this and it takes an hour of googling to figure this out again. Basically I often need to see not just what php modules are installed on my system, but also what can be installed.

For example you can see what is already installed and available to you on your current system you simply type php -m in your command line. This command will list all of what is installed currently on your system.

But that is not what I want and probably not what you want if you are reading this. What I want is to know what is available for installing, or better what are the exact names of the packages. For this information you need a different command.

sudo apt-cache search php7*

This command searches the apt cache for packages that contain php7* the * is a wildcard meaning anything that looks like php7 such as php7.4-mysql. Try the command above and you will get a list of all of the php modules specifically for version 7.4. Not all modules will be listed. You can use another command to see all of the available php modules even if they don’t contain 7.4 in the name you can install them.

To see all php modules available use this command.

sudo apt-cache search php*

Minus the 7 and it will return every last module that contains the word php.

Then to install anything you need you use a command like the following

sudo apt install php7.4-mysql php7.4-curl php7.4-json php7.4-cgi php7.4-xsl

And that is how you list and install php modules/extensions.

Here is an interesting article about how apt-cache works on linux
Here is a link to some more resources about this topic.

Categories
Resources Web Development

How to get TinyMCE to not destroy image upload URL’s

Came across a weird not so feature of TinyMCE where it munges the URL your upload script returns when it uploads an image. For example if your upload script returns a url of http://example.com/folder/image.jpg. TinyMCE takes it upon itself to rewrite that URL breaking it to ../../folder/image.jpg  I am not sure why but I think it is trying to help you in some way.

The best clue I could find in the docs as to why this happens is at the bottom of the page in the CORS section here. It appears TinyMCE is removing the domain you add to the url then it cuts from the current page. The problem I encountered was if my page was blog it would remove the http://example.com part and replace it with ../../blog/folder/image.jpg which is not what I wanted.

I was about to replace TinyMCE but I decided to try something else. I did some googling and found this in the docs.  

I included this in my tinymce configs.

relative_urls : false,
remove_script_host : false,
document_base_url :  "{{ prependURL }}"

Those 3 lines of code fixed it all. Totally didn’t expect TinyMCE to munge the URL’s I returned. This ate up an entire day as I kept thinking the reason the image didn’t display was because my code wasn’t creating the URL’s correctly. Then I thought it was my Nginx configs. Then before giving up on TinyMCE  I did this last thing.

prependURL is a variable that contains the url of website hosting the image such as https://example.com TinyMCE prepends that to the url you return to it, even if https://example.com is already part of it. Otherwise it removes https://example.com and replaces it with a relative URL such as ../../folder/image.jpg

I hope this saves someone else time.

Categories
Resources Web Development

Server Environmental variables resources and info

About environmental variables – an introduction to environmental variables and how they work on the server.

Categories
Resources Web Development

Single page apps suck links and resources

Single page apps built with Javascript are the super hyped rage these days. This design goes against all of the hard learned lessons of the past 30 years.

The main reason SPA’s suck is networks are unreliable and SPA require large amounts of Javascript to be transferred to a users device. Most devices are mobile these days. If a users has a slow connection the app will take for ever to load or timeout and not load at all.

Another reason SPA’s suck is they assume all users are using the latest greatest highest powered device. This leaves out more than half the planet and is a very arrogant approach basically saying you are not important to us because you are poor and have a crappy device and slow connection go elsewhere you peasant.

I’ll post links here as I get time. The first one is an excellent piece covering much of why SPA’s are not a good choice.

Why you should not build your start-up as Single-Page Application?

Categories
Software Development Web Development

PHP tools for CI CD testing etc.

7 Continuous Integration Tools for PHP Laravel Developers

Categories
Web Development Web Security

How to permanently set Linux environmental variablees

This is a giant subject. I’ll continue updating this article as I find and understand more about how Linux does all of this.

Most articles show how to set them in the terminal, then when you close the terminal and try to use a variable it doesn’t exist leaving you confused.

Well those posts are how to set a temporary environmental variable accessible in your terminal until it closes only.  To set a lasting Environmental variable you need to use a file.

This is often needed to store sensitive api key secrets, passwords etc. You should never put any of that information in a file for your project directly, meaning don’t put it in a file that is stored in your code repository.

Developer App Variables

The idea is to create environmental variables to hold this info on your local machine, then when you put your code into production you add the necessary environmental variables to whatever controls them for your app. You can use kubernetes secrets or Hashicorp vault or if you are using something like Gitlab or Openshift continuous integration/delivery pipeline workflow will have a way to enter these values securely.

One problem you will run into with apps is how Nginx or Apache either pass or don’t pass the variables to your scripts. It can be confusing. Apache gladly passes values from the environment to our scripts, but Nginx not so much. With nginx you need to set your vars in 2 locations or run a hacky feeling 3rd party Perl script which takes your variables and passes them to Nginx. Nginx has better performance than Apache though. The story is an entire article for later though, back to the subject.

Overall Environment variables

There are many ways to set environment variables in linux and each depends on what needs to be done. Each user has their own files that set variables for them. There are also other files that set variables for programs that run on your computer like cronjob. There are also files to set variables system wide, but it depends on what is operating whether it can access it.

You can create a file with any name you want with extension .sh like example-app.sh and place it in /etc/profile.d directory.

As described in this link Linux will read all of the files in that directory and create the environmental variables.

This is basically what I have in a simple text file

You simply add a new line for each variable you want to have created for your app.

Other locations

Each user on your Linux system has a .bashrc file  the root, regular user etc. all have one. On Ubuntu root is disabled so settings in that .bashrc file are probably ignored. But the user you usually login as, the default name that shows in your terminal when you open it, that home directory has a .bashrc file. Located at /home/username/.bashrc If you set a variable in this file you must log out and log back into your system for them to take effect or restart your computer.

As mentioned in this article, the shell looks in several places when the terminal is invoked.  Where to place it depends on what you need to do.

There are login shells, interactive shells, non interactive shells, each looks in different locations. This article has a good discussion of interactive vs non interactive. Basically interactive is when you type into the terminal, non interactive is when you run a shell script or other program that does the interaction with bash ( or other shell ) for you.

This article describes the many locations and files used to set environment variables. Not all versions of Linux will have all of these or use them, each version is different and you should read the documentation for your specific distribution. The bottom of that article gives you a better idea of where to set the variables.

For scripts like shell scripts set the environmental variables in .bashrc files. For interactive use in the terminal where the user or their commands need the variables set them in the .profile file or profile.d directory as mentioned above.

Here is a much more in depth article about Linux Environment variables.

As you can see in this link, this whole process depends on many things.

Here is another good, long explanation of Environment and Variables by digital ocean.

Categories
Resources Web Development

Serverless computing resources

Economics of serverless – a great article if you are interested in going serverless.

Categories
Random Resources Web Development

PHP random links and resources

PHP the Right way – a website/book full of the most useful information you will find about PHP

Categories
Resources Web Development

PHP Namespace information, links and resources

It is important to understand what namespaces are in PHP and how to use them. Otherwise you will be lost and have many pains.

Videos

Below is a series of great videos explaining PHP namespaces little by little in easy to find and digest chunks.\
PHP namespaces 1/10: What is a namespace in PHP?









Everything about PHP namespaces – OOP in PHP | Part 10