Categories
Uncategorized

It’s in my head it must be in yours. Why all documentation sucks ass!!!

Most documentation sucks. It seems most authors have this idiotic idea that whatever is in their head, all their knowledge etc. magically transfers to the user as they read it. These are the same kind of idiots you meet in society that drone on about shit they understand to the totally uninitiated like they are talking to a pro. These are the kind of idiots that while talking don’t even have the ability to notice their true live audiences eyes glazing over and heads shaking in confusion. Nope these idiots are comfortable being idiots and we have to suffer. I don’t get it.

Ever been reading along documentation and the author just keeps throwing out concepts/terms left and right without even giving a link, leaving you in the dark like WTF? Isn’t it fun?

Here is a tip to anyone who writes documentation. No matter how stupid simple a concept seems to you, there will be people, many people who have never come across the concept. Instead of being a snobby dickhead with an attitude like “Well you have to have a minimum idea of how blah blah blah works because I do”. You should provide information, links etc. to any concept that anyone may not have encountered.  It is not that damn hard and doesn’t take much time and it makes you look much smarter and much less conceited and narcissistic.

This is the exact reason I started this website. So much of the documentation for everything sucks ass. Most documentation I come across these days leaves me saying WTF. Look at openssl or openssh or example so many WTF’s in those docs.

And what is worse is the assholes who write blogs who just copy other blog posts. So you get entire search pages full of shit articles all repeating the same wrong shit that doesn’t work. Then that shit information ends up on stackxxxx.com sites from idiot kids who copy and paste shit for points and don’t care if the answer is right, they just want popular points. I often just avoid stack sites these days. Those sites are only handy if you are doing the most basic simple shit. Once you go into complex issues those sites are wrong answer land 100% of the time.

Categories
Uncategorized

symfony how to start encore watch

I use so many languages and tools I can never even remember the most simple shit about anything anymore . This is how you start symfony encore webpack.

yarn run encore dev --watch

Symfony docs how to start encore
https://symfony.com/doc/current/frontend/encore/simple-example.html#the-import-and-export-statements

Categories
Software Development Web Development Web Security

How to create ssh keys for admin user login without passwords

The idea is to have a way for an admins to SSH into a server without having to use passwords. This adds a level of security to your server setup. Without private keys you have to enter your user name and password. This can be less secure than generating SSH keys and adding your public key to SSH, plus with keys you don’t have to remember passwords.

First you need to generate the SSH keys. I prefer the ed25519 algorithm which is a newer one. You can get more info here.  

The code to create an ed25519 ssh key in the current users .ssh directory will look like this.


ssh-keygen -f ~/.ssh/key-name -t ed25519  

The -f flag tells ssh-keygen the name of the files you want to create. The above command would create key-name(private key) and key-name.pub(public) key, in the current users .ssh directory. The ~ is a Linux shortcut meaning /home/current_user/ so you don’t have to type all that.

The -t flag tells ssh-keygen what type of algorithm to use. If you don’t specify the -f flag and give the file a name, then both files are output in the current users .ssh directory as ed25519 and ed25519.pub

Categories
Software Development

Why doesn’t bash script recognize aliases

Here I won’t be doing much explaining, just listing links so people can read about this befuddling issue.

It often boggles my mind how differently you must write shell scripts vs the command line commands. It is often very inconsistent, I hate inconsistencies.

Basically Aliases within Linux shell are not recognized without some fancy hacky code, WOOHOO. So you will lose your mind if you are trying to set and use aliases in shell scripts.

You can set aliases all day long, but your scripts wont use them.

Yes you read that correctly. You can set aliases in your script, even right before you want to use it and Linux is like GTFO, I have no idea what that is. It even fails without a notice/error most times. What you can do is set a normal variable and use it in place of an alias though.

Say you had a script named do-this-thing.sh  and it was located deep in a directory like /etc/directory/directory/directory/directory/do-echo “$yarnBin” > /etc/profile.d/server-alias.shthis-thing.sh
You could do the following in BASH


not_alias=/etc/directory/directory/directory/directory/do-this-thing.shalias not working inside bash shell script

bash not_alias

The above would execute the do-this-thing.sh file. You can also permanently set aliases in your Shell script. This is handy even if you can’t use the aliases in your script directly, you can use them in the terminal command line later.

To permanently set aliases alias when not working inside bash shell script place them in your .bashrc file for the user you are logged in   This is usually located in /home/username/.bashrc  or you can put it in the user profile .profile file or other places.
How you do this varies by Linux shell.

Links to more info

Why doesn’t my Bash script recognize aliases?

Alias not working inside bash shell script

Creating permanent executable aliases

How to create permanent Linux Aliases

How to create a permanent Bash alias on Linux/Unix 

Categories
Resources Software Development Web Security

Stupid linux issues.

This is my collection of stupid.

Top of the list Debian/Ubuntu removes apt-key support and doesn’t tell anyone they did it, doesn’t give anyone a single hint as to what to do. No just remove/deprecate shit and don’t tell a single soul on earth. This kind of stupid makes me want to leave the industry entirely. I get so tired of messed up  and undocumented shit that wastes hours and hours and hours of my time. Someone needs kicked for this.

More info and links about the above issue or removing apt-key support. Yarn suggests using apt-key so this means hundreds of millions of people are having this issue or will or could.
Even more info about the stupid ideas from above.

Categories
Software Development Web Development

Where does symfony php framework hide the errors?

I kept saying this over and over and looking everywhere for answers. I finally found this page through googling tons of terms and combos until I found it. I kept thinking my errors would be in the logs I set in my Nginx configs, or even in my PHP configs. But they were continually empty, I was going insane. I seriously blew up on twitter.

BLOWING UP

I thought Symfony was simply suppressing or not passing the errors to Nginx. So the logs are located at the place in the link above from documentation and not in the location you set in the Nginx configs or PHP configs.

By default, log entries are written to the var/log/dev.log file when you’re in the dev environment. In the prod environment, logs are written to var/log/prod.log

What made this confusing was, the docs don’t have a logical link flow when you are reading them trying to learn Symfony. You later find the SymfonyCasts which are better. But what makes it  most confusing is in the docs about configuring Nginx, it even shows the following.

    error_log /var/log/nginx/project_error.log;
    access_log /var/log/nginx/project_access.log;

To me this was showing how to set the error log. This does nothing by the way, not unless nginx itself has an error I guess.

For months I’ve wondered WTF, where are my error logs. I kept putting my app in dev mode so I could debug it via the browser.

Don’t do that!!!!!

To be honest getting Symfony working with Nginx is a pain in the ballsocks. The reason is, Nginx doesn’t pass environmental variables through to php scripts like Apache does/can. If you want that kind of fancy feature you must hack nginx up and use some perl script or something similar. Otherwise with Nginx you must set the environment variables twice, once in nginx and once in shell.

Why would you do that?

Why two locations? Yeah this really angered me and blew my mind at first too. As mentioned above Nginx doesn’t have any easy way to pass the environment variables you set at the Linux server level. This is important with Symfony because you often need to run things like Doctrine on the command line.

So I was setting my Nginx Environmental variables, the app would see them just fine. I’d go to run doctrine or tests and BOOM missing environmental variables like WTF? Or I would set them in the Linux environment, view them with printenv load the app in the browser and Nginx didn’t pass the values to my script. It took a lot of googling to figure that out with lots of trial and failure. To make matters worse, you have to change the environmental variable names in order to run tests so that symfony loads them, otherwise it hides the values.

WTF is happening?

I then found out through experimenting that you had to set the variables for the command line in the Linux environment too. How to permanently set Linux environmental variablees covers how to do that. It’s easier to just Bash script or ansible the entire process with Hashicorp packer than to try to manually maintain it all, setting vars in two different places etc.

So for months I’ve been going insane trying to find my error logs. Today I found the error logs.

Problem solved

 

Categories
Software Development Web Development

How to switch users in Linux Bash Shell script and execute multiple commands as different user

If you search you will find different answers to this. You can do this in multiple ways, here I will talk about 2 ways, single command and multiple commands.

First the idea is to switch from say root user to a named user you created or was created for you on your Linux server to run commands as not the root user. The reason you want to do this is so that everything isn’t owned by the root user. Or you are installing something like PHP Composer which barfs on you if you run it as root user.

You will see some saying to use su others saying to use sudo (some bs options etc.) You will also see really wrong answers on Stack. I have no idea why you would use sudo over su, you can google that. But I do know that su switches users. Here is an article goes into more detail of su vs sudo and when you use both.

Single command syntax

So the first way is to run a single command directly inline. If you are the root user you simply use su The syntax to do so is as follows:


su - username "commandToExecute [command options and arguments]"

It has been my experience that the Double ” Quotes are required or else the shell gets confused. You may be able to use single quotes if you don’t use any variables within the quotes.

Multiple commands syntax

To more easily issue multiple commands or long commands you need to use Linux heredoc syntax.
Heredoc uses <


su - $username <<SHT
     cd $serverDir
     php $composerFile install
SHT

Like I said you can use any Delimiter you want. It is tradition to use all caps for the word, it makes it easier to spot. The ending word (EOF here) has to have no spaces or words before it. You can list any number of commands within that syntax and all will be executed by the user.

NOTE: After the ending EOF the shell returns the user to whatever user you were/are logged in as before the lines of code. If you are logged in as root, you are returned to root. Also when you issue the su command you are moved out of the directory you are in. That is why I used cd to move back to the directory I needed to be in.

More links

More info about changing users on stack here.

Here is a link to heredoc syntax explanation and examples

More information and examples about heredoc in bash

Bash how write large amounts of text to a file

Categories
Software Development Web Development

What does prototypical Javascript look like?

Way back before modern times, like 10 years ago. Javascript had a much funkier way of defining objects. It was called prototypical inheritance. This is still how Javascript works, the classes, modules etc. were all recent additions to the language to make it easier to work with. It is not a very fun way to program because it is like looking at a GIANT JSON more than a class with methods.

So what did/does prototype inheritance look like? Well this…



function JsCollection() {
    this.jsObject = new Object();

}
JsCollection.prototype = {
    constructor: JsCollection,
    addNamedProperty: function (property, value) {
        // only add the property if it doesn't exist, return true if it was created
        //return false if it was not, to allow for testing before adding a new property
        var returnBool = false;
        if (!this.jsObject.hasOwnProperty(property)) {
            returnBool = true;
            this.jsObject[property] = value;
        }
        return returnBool;
    },
    getElementCount: function () {
        var elementCount = 0;
        //loop through the object and add to the count
        for (var elem in this.jsObject) {
            //only add to the value if it is part of collection
            //https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects
            if(this.jsObject.hasOwnProperty(elem)){
                     elementCount++;
            }
           
        }
        return elementCount;
    },
    getElementValue: function (property) {
        var returnProp = null;

        if (this.jsObject.hasOwnProperty(property)) {

            returnProp = this.jsObject[property];
        }
        return returnProp;
    },
    removeNamedProperty: function (property) {

        if (this.jsObject.hasOwnProperty(property)) {
            delete this.jsObject[property];
        }
    },
    changePropertyValue: function (property, value) {

        if (this.jsObject.hasOwnProperty(property)) {
            this.jsObject[property] = value;
        }
    },
    getAllNamedProperties: function () {
        return this.jsObject;
    },
    namedPropertyExists: function (property) {
        var propExists = false;
        if (this.jsObject.hasOwnProperty(property)) {
            propExists = true;
        }
        return propExists;
    }
};

//var objProps = obj1.getAllNamedProperties();
// how to loop through object properties 
//for(var prop in objProps){
//    console.log("Property is " + prop + ' Property value is ' + objProps[prop]);
//}

As you can see this is an object with functions in old fashioned Javascript syntax. This was too confusing of a syntax for most people, plus you had to learn the inner workings of Javascript and how prototypical inheritance works.

I won’t try  to explain it here as it is pretty complicated to wrap your head around. Some videos may help better than an article.



Categories
Software Development Web Development

How to configure php 7.4+ on Linux Ubuntu 20.04+

Configuring php can be confusing. PHP uses multiple configuration files, but the main ones are both named php.ini. You see with php you can have separate configurations for the app and the command line aka cli.

Why would you do that?

This may sound stupid at first but it is due to the fact that your command line is a different environment from your app environment.  In Linux for example each user of the cli has their own environmental variables. These variables get passed to the php cli. This can drive you insane on linux. You think you set the configurations correctly, app works, try command line and BOOM all messed up.

But I set the damn configs WTF?

The two main files are located at

  1. /etc/php/7.4/cli/php.ini
  2. /etc/php/7.4/fpm/php.ini

Yes they have the same exact name. Yes they contain the same thing. However, one is used for the command line (cli) and the other is for apps (fpm). So you must set the settings in both. If you wanted to use 1 file for both you might be able to remove/rename 1 file such as the cli, set the fpm file. Then use a symlink from the fpm file to the cli directory. It would require some testing but it will probably work.

P.S. The php configuration file is the largest you will ever in your life see. I’m guessing a few thousand lines, it feels like that, but there is a ton of commenting and documentation to help you complete with links.

Categories
Resources Web Development

Linux su command not working, does nothing but show $ prompt

So you found the magic sauce did ya?  So you created a user with useradd or adduser and you try to switch over to that user in a terminal, probably logged in through ssh as root right.

You are trying to use the su – username command but all you get is a $. And not the good kind. The kind that no matter what you type all you get is another line with $ on it. This is a feature by the way so you can’t see files that don’t belong to the user…

Right now you are probably like

Wait. WTF is even happening?

As far as I can tell, if you are using Debian or Ubuntu, useradd/adduser defaults the users shell to /bin/sh but the skeleton files located in /etc/skel are all configured for bash.  I have no idea how the system gets the defaults, but it does no good to have your users default shell not pointing to bash.

How to fix this?

To fix it you need to change the users default shell to bash. Bash is usually located in /bin/bash or /usr/bin/bash For me it was /bin/bash. To change it you use usermod command like so


usermod -s /bin/bash username

That will change the shell your user gets when you type su – username. Now since Ubuntu/Debian and maybe other distros contain the configuration in the users .bashrc and .profile files everything will work as expected. When you switch to the user with the above command you are taken to their home directory.

Found more details!

More info

Ok I found more info while digging into the so called useradd docs.

-s–shell SHELLThe name of the user’s login shell. The default is to leave this field blank, which causes the system to select the default login shell specified by the SHELL variable in /etc/default/useradd, or an empty string by default.

So that is where Linux gets the default value for the user shell and apparently you can use the -s option when creating the user to specify the bash as the shell.

Digging deeper into the mystery sauce I find in my Mastering Ubuntu Server book ( awesome book ) the reason why. It states if you use adduser then their default shell is /bin/bash and if you use useradd (which I used) it defaults to /bin/sh

Links

how to change the default shell of an user in linux? – more info about usermod and changing the users default shell and how to figure out what shells you have installed and their locations.