DEVGET.NET Blog

How to run a command at startup in Linux 0

How to run a command at startup in Linux

There are two main ways to do this

  1. Put commands or program in the rc.local file
nano /etc/rc.local

or 2. Use the special crontab @reboot

so, access crontab with

crontab -e

and add your command following the layout below

@reboot command

 

 

How to create a python virtual environment in Linux 0

How to create a python virtual environment in Linux

Install pip

sudo apt-get install python3-pip
# replace apt-get with dnf or zypper or whatever your distro uses

Install the python virtualenv package

pip3 install virtualenv

Make your main virtualenv directory

mkdir ~/.virtualenvs

Create the Virtual Environment

virtualenv --python=`which python3` ~/.virtualenvs/myvenv

Activate the virtual Environment with

source ~/.virtualenvs/myvenv/bin/activate

 

How to fix no public key available for the following key IDs in debian 10

How to fix no public key available for the following key IDs in debian

On new debian servers, upon attempting to apt-get update you may see the following error

root@myserver:~# apt-get update
Get:1 http://security.debian.org wheezy/updates Release.gpg [1571 B]
Get:2 http://security.debian.org wheezy/updates Release [102 kB]
Get:3 http://ftp.debian.org wheezy Release.gpg [2390 B]
....
Reading package lists... Done
W: There is no public key available for the following key IDs:
9D6D8F6BC857C906
W: There is no public key available for the following key IDs:
7638D0442B90D010

The easiest way i’ve found to solve this problem is to do the following.

apt-get install debian-keyring debian-archive-keyring

Try to update again

apt-get update

And voilia! No more errors

2

How To Install Linux, Nginx, MySQL & PHP (LEMP) on Debian 8

As always we start off with

apt-get update
apt-get upgrade

Install MySQL Server

apt-get install mysql-server

You will be prompted to input a password, put anything “secure”

Now let’s secure our database.

mysql_secure_installation

This will ask you a few questions

– Enter “secure” password set previously
– Change Password : n
– Remove Anonymous Users : Y
– Disallow root login remotely : Y
– Remove test database : Y
– Reload privilege tables : Y

 

Install and Configure PHP (+optional modules)

Install php and a few important modules with the following command

apt-get install php5-fpm php5-mysqlnd php5-mcrypt

Now in /etc/php5/fpm/php.ini change the following lines (you need to search for each one)

;cgi.fix_pathinfo=1
upload_max_filesize = 2M
post_max_size = 8M

to

cgi.fix_pathinfo=0
upload_max_filesize = 12M
post_max_size = 16M

Install and Configure NGINX

apt-get install nginx

Nginx is now installed and if you go to your IP address you should see the welcome page

To configure nginx to work with php, edit /etc/nginx/sites-availiable/default with the following changes. (lines with edits are highlighted)

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php5-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
                # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
                deny all;
        }
}

Lets not forget to restart nginx

service nginx restart

 

Finishing off

Create a test page and try it out at http://my.ip.address/info.php

echo "<?php phpinfo(); ?>" > /var/www/html/info.php

 

 

How to enable autocompletion in screen 2

How to enable autocompletion in screen

You may have noticed that when you are using screen, auto-completion (bash-completion) stops working.

This can be remedied by creating a file called .screenrc in your home directory and adding to it “defshell -bash”.  You can also paste the following into your console and restart your server

echo "defshell -bash" >> ~/.screenrc
How to fix untrusted certificates error in ubuntu/debian 1

How to fix untrusted certificates error in ubuntu/debian

If you are experiencing the following error

ERROR: The certificate of `raw.github.com' is not trusted.
ERROR: The certificate of `raw.github.com' hasn't got a known issuer.

Then you simply need to install ca-certificates.. you can do that with the following:

apt-get install ca-certificates
How to undo last commit/push to git repository 0

How to undo last commit/push to git repository

Was faced with an issue recently where I ‘accidentally’ pushed a ‘bad’ commit to github. Luckily with git its easy to undo such mistakes.

In your working directory type

git push -f origin HEAD^:master

And voilia, your last push was removed.

Note. To sync local changes to match the previous head we can use

git reset HEAD~

Now, lets say you pushed a truckload of crappy commits to the repository. Well, thats not gonna be an issue either, just add more carets for each push you wish to remove.

eg. to remove the last 3 commits

git push -f origin HEAD^^^:master

Did it work for you? share your experience in the comments below.