Install wordpress on ubuntu 20.04 Lamp

I’m using Linode hosting my blog ,I just upgrade ubuntu from 14.04 to 20.04 ,so I reinstalled wordpress ,below is the step I was using.

Install Lamp using tasksel

sudo apt update
sudo apt install tasksel
sudo tasksel --list
sudo tasksel install lamp-server
sudo apt remove tasksel

Virtual host setup

1.Create a apache configuration file for your wordpress site(Replace example.com with your domain name)

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf

2.Edit the conf file created above and set your ServerName and DocumentRoot.Eg:

<VirtualHost *:80>
        ServerName ubuntututorials.org
        ServerAlias www.ubuntututorials.org
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/ubuntututorials.org/public_html

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
 

Note: It’s better to add and “www” ServerAlias if you are using the base domainname

3.Create required directory

sudo mkdir -p /var/www/html/example.com/public_html

4.Enable your site and disable the apache default one

sudo a2ensite example.com
sudo a2dissite 000-default.conf
sudo systemctl reload apache2

Mysql Setup

1.Login into mysql using root

sudo mysql -u root

2.Create a database instance for you wordpress site.Eg:

CREATE DATABASE wordpress;

3.Create a mysql user and grant it the full access to the db create in step 2

CREATE USER 'wpuser' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser';
quit

WordPress installation and setup

1.Download the latest wordpress package somewhere and extract it

sudo wget http://wordpress.org/latest.tar.gz
sudo tar -xf latest.tar.gz

2.Move wordpress files to your public_html directory

sudo mv wordpress/* /var/www/html/example.com/public_html/

3.Chown the owner and group to www-data

sudo chown www-data:www-data -R /var/www/html/example.com/public_html/

4.Configure WordPress , open your wordpress site now ,you should be able to see the configuration page

Use the database name / username/password created above

Some Optional setup

1.Enable Permalinks for your wordpress site , you can add below lines into your wordpress’s apache site configure file

<Directory /var/www/html/example.com/public_html>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
sudo systemctl reload apache2

2.Install phymyadmin

sudo apt install phpmyadmin

3.Enable https for your wordpress site

Move your wordpress from http to https for free lamp

I just migrated my blog from http to https , I’m using linode ubuntu 20.04 ,below is the steps to move wordpress to https for free (using Let’s Encrypt)

Note: Please backup your wordpress in advance

1.Ssh to your wordpress server and install snapd using command below

sudo apt update ; sudo apt install snapd

2.Install the latest core of snapd

sudo snap install core; sudo snap refresh core

3.Remove old Certbot for your OS if any

sudo apt-get remove certbot

4.Install the latest Certbot

sudo snap install --classic certbot

5.Make a link for certbot so that you can invoke it directly

ln -s /snap/bin/certbot /usr/bin/certbot

6.Run below command to get a ssl certificate from Let’s Encript and enabled it for your apache

sudo certbot --apache

7.Test if automatic ssl renewal works or not

sudo certbot renew --dry-run

8.Go to your wp-admin web portal and change your website address from http to https

9.Verify your site is with https enabled now

10.(Optional) if you are getting posts images not with ssl enabled ,consider to run below sql to enable ssl for images(replace ubuntututorials.org with your domain name )

UPDATE wp_posts SET post_content = replace(post_content, 'http://ubuntututorials.org/wp-content/uploads','https://ubuntututorials.org/wp-content/uploads') 

Refference: https://letsencrypt.org/getting-started/

Linux command to create out of memory killer (OOM)

In linux ,when virtual memory(physical memory + swap) is used up ,OOM will kill one process to free memory.You can try below command to simulate an OOM

tail /dev/zero

After a while above command will use up all your virtual memory and been killed by OOM ,like below

user01@host01$ tail /dev/zero
Killed
user01@host01$

All you can get the relevant log messages via command dmesg

Out of memory: Kill process 15297 (tail) score 947 or sacrifice child
Killed process 15297, UID 1000001 (tail) total-vm:21404752kB, anon-rss:15804388kB, file-rss:4kB

Shell command to create physical memory usage

No matter for what reason ,we as admin sometimes want to simulate memory usage . There have many ways to do this ,below one is to use shell command ,so we don’t need additional tools or code by specific program language.

yes |tr \\n a |head -c $((1024*1024*100)) | grep x

Above command will create 100M memory usage . 1024*1024 means M , and 1024*1024*1024 means G , you can specify what you want

In case you want to simulate use up all physical memory you can specify a number which is bigger than your total physical memory.

If you wan to let this occurs for period , you can try below command.

cat <(yes |tr \\n a |head -c $((1024*1024*1024*2)) ) <(sleep 100) |grep x

This command will simulate occupying 2G physical memory for 100 seconds.

Note: There is no SPACE between the “<” and “(“

Linux command to create 100% cpu loading

We can use below command to generate cpu loading in linux

yes > /dev/null &

Notes:

  • “yes” is a command to print “yes” to screen repeatedly
  • /dev/null is data sink ,which means the output of command “yes” will be discareded
  • “&” means let this command to be running in background
  • One above command will use up one cpu core (or Hyper Thread)

You can use command “cat /proc/cpuinfo” to check how many cpus you have, eg: if you have 4 cpus (probably 1 cpu with 2 cores and each core have 2 threads) , then you need to run 4 above command to make your cpu 100% busy

You can use below command to kill these commands

killall yes

Equivalent Solairs mkfile command in Linux

If you have Solaris administrator experience , you may know we can use mkfile to create a big empty file for some purpose.In linux there are some equivalent commands.

1 .truncate

For example ,we can use below command to make a 10G empty file

truncate -s 10G 10gfile

2. dd

Below command does the same thing as above truncate command

dd if=/dev/zero of=10gfile bs=1G seek=10 count=0

3. fallocate

Note: this command only been supported by some file systems like ext4 , xfs

fallocate -l 10G 10gfile