Category Archives: Linux Ubuntu

Linux Ubuntu

Install Apache, MySQL, PHP (LAMP) Stack On Ubuntu 18.04 LTS

1. Install Apache web server

First of all, update Ubuntu server using commands:

$ sudo apt update
$ sudo apt upgrade

Next, install Apache web server:

$ sudo apt install apache2

Check if Apache web server is running or not:

$ sudo systemctl status apache2

Sample output would be: Continue reading

Configure Apache With TLS/SSL Certificate on Ubuntu 18.04

  • Apache server configured and installed

Step 1:  Generate Certificate

  1. Create a directory place to store the file
  1. $ mkdir ~/certificates
  2. $ cd ~/certificates

2. Generate a CSR and private key using following command

  1. $ openssl req -x509 -newkey rsa:4096 -keyout apache.key -out apache.crt -days 365 -nodes

After successfully running the command it will ask for the information of certificate request. Complete it using the appropriate information.

Continue reading

How To Set Permanent DNS Nameservers in Ubuntu and Debian

The /etc/resolv.conf is the main configuration file for the DNS name resolver library. The resolver is a set of functions in the C library that provide access to the Internet Domain Name System (DNS). The functions are configured to check entries in the /etc/hosts file, or several DNS name servers, or to use the host’s database of Network Information Service (NIS).

On modern Linux systems that use systemd (system and service manager), the DNS or name resolution services are provided to local applications via the systemd-resolved service. By default, this service has four different modes for handling the Domain name resolution and uses the systemd DNS stub file (/run/systemd/resolve/stub-resolv.conf) in the default mode of operation.

The DNS stub file contains the local stub 127.0.0.53 as the only DNS server, and it is redirected to the /etc/resolv.conf file which was used to add the name servers used by the system.

If you run the following ls command on the /etc/resolv.conf, you will see that this file is a symlink to the /run/systemd/resolve/stub-resolv.conf file.


$ ls -l /etc/resolv.conf

lrwxrwxrwx 1 root root 39 Feb 15  2019 /etc/resolv.conf -> ../run/systemd/resolve/stub-r

Unfortunately, because the /etc/resolv.conf is indirectly managed by the systemd-resolved service, and in some cases by the network service (by using initscripts or NetworkManager), any changes made manually by a user can not be saved permanently or only last for a while.

In this article, we will show how to install and use the resolvconf program to set permanent DNS name servers in /etc/resolv.conf file under Debian and Ubuntu Linux distributions.

Why Would You Want to Ddit /etc/resolv.conf File?

The main reason could be because the systems DNS settings are misconfigured or you prefer to use specific name servers or your own. The following cat command shows the default name server in the /etc/resolv.conf file on my Ubuntu system.

$ cat /etc/resolv.conf
Check DNS Name Servers

Check DNS Name Servers

In this case, when local applications such as the APT package manager try to access FQDNs (Fully Qualified Domain Names) on the local network, the result is a “Temporary failure in name resolution” error as shown in the next screenshot.

Temporary Failure Resolving

Temporary Failure Resolving

The same happens when you run a ping command.

$ ping google.com
Temporary Failure in Name Resolution

Temporary Failure in Name Resolution

So when a user tries to manually set the name servers, the changes do not last for long or are revoked after a reboot. To resolve this, you can install and use the reolvconf utility to make the changes permanent.

To install the resolvconf package as shown in the next section, you need to first of all manually set the following name servers in the /etc/resolv.conf file, so that you access the FQDMs of Ubuntu repository servers on the internet.

nameserver 8.8.4.4
nameserver 8.8.8.8

Read AlsoHow to Setup Local DNS Using /etc/hosts File in Linux

Installing resolvconf in Ubuntu and Debian

First, update the system software packages and then install resolvconf from the official repositories by running the following commands.

$ sudo apt update
$ sudo apt install resolvconf

Once the resolvconf installation is complete, systemd will trigger the resolvconf.service to be automatically started and enabled. To check if it is up and running issues the following command.

$ sudo systemctl status resolvconf.service

If the service is not started and enabled automatically for any reason, you can start and enable it as follows.

$ sudo systemctl start resolvconf.service
$ sudo systemctl enable resolvconf.service
$ sudo systemctl status resolvconf.service
Check Resolvconf Service Status

Check Resolvconf Service Status

Set Permanent DNS Nameservers in Ubuntu and Debian

Next, open the /etc/resolvconf/resolv.conf.d/head configuration file.

$ sudo nano /etc/resolvconf/resolv.conf.d/head

and add the following lines in it:

nameserver 8.8.8.8 
nameserver 8.8.4.4
Set Permanent DNS Name Servers in Resolvconf

Set Permanent DNS Name Servers in Resolvconf

Save the changes and restart the resolvconf.service or reboot the system.

$ sudo systemctl start resolvconf.service

Now when you check the /etc/resolv.conf file, the name server entries should be stored there permanently. Henceforth, you will not face any issues concerning name resolution on your system.

Permanent DNS Name Servers

Permanent DNS Name Servers

I hope this quick article helped you in setting the permanent DNS nameservers in your Ubuntu and Debian systems. If you have any queries or suggestions, do share it with us in the comments section below.

Installing Webmin on Ubuntu 18.04

  1. Start by updating the packages list and installing the dependencies:
    sudo apt updatesudo apt install software-properties-common apt-transport-https wget
  2. Next, import the Webmin GPG key using the following wget command:
    wget -q http://www.webmin.com/jcameron-key.asc -O- | sudo apt-key add -

    And enable the Webmin repository by typing:

    sudo add-apt-repository "deb [arch=amd64] http://download.webmin.com/download/repository sarge contrib"
  3. Install the latest version of Webmin by typing:
    sudo apt install webmin

    Once the installation finishes, the following output will be displayed:

    Webmin install complete. You can now login to https://your_server_ip_or_hostname:10000/
    as root with your root password, or as any user who can use sudo
    to run commands as root.

    The Webmin service will start automatically.

Continue reading

วิธีการทำ Redirect HTTP to HTTPS โดย .htaccess หรือ php

การเรียกใช้งานเว็บไซต์ทั่วไป จะเรียกผ่าน Protocal HTTP แต่เมื่อมีการติดตั้ง SSL สำหรับเว็บไซต์แล้ว ควรจะต้องทำการตั้งค่าการใช้งานให้บังคับใช้ SSL ซึ่งก็คือ บังคับให้ใช้งาน HTTPS นั่นเอง ดังนั้น หากลูกค้าไม่ได้ทำการ Redirect การเรียกใช้ Website ทั่วไป ก็จะชี้ไปที่ HTTP ที่เป็นค่าเริ่มต้น ไม่ใช่ HTTPS เพราะฉะนั้นทางทีมงาน SSL.in.th จึงแนะนำให้ทำ Redirect สำหรับ Website ของลูกค้าด้วยเช่นกัน เพื่อความปลอดภัย และเรียกใช้ SSL Certificate ทุกครั้งที่ถูกเรียกใช้งานโดยเราแนะนำอยู่ 2 วิธีต่อไปนี้ คือ ใช้ .htaccess และ php

 

PHP Code redirect

function redirectTohttps()
{
 if($_SERVER['HTTPS']!=”on”)
 {
 $redirect= “https://”.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
 header(“Location:$redirect”);
 }
 } 
?>

 

.htaccess file code (หากไม่มีไฟล์ให้สร้างไฟล์ .htaccess ขึ้นมา)

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


หรือ บังคับ Redirect ให้มี www เท่านั้น

<IfModule mod_rewrite.c>
RewriteEngine On
# ensure redirect to https://www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

วิธี Generate Private Key และ CSR สำหรับ Apache OpenSSL Linux

1. ทำการเปิด Terminal ขึ้นมาแล้วทำการเข้าใช้งานโดยใช้สิทธิ์ root

2. ทำการ Generate Private Key ด้วยการพิมพ์คำสั่งต่อไปนี้

openssl genrsa -out /[Path]/privatekey.key 2048

โดยให้แก้ไข [Path] เป็นค่าสถานที่เก็บไฟล์ที่ท่านต้องการ

Continue reading

Ubuntu Linux restart network interface

To restart network interface, enter:
sudo /etc/init.d/networking restart
To stop and start use the following option (do not run them over remote ssh session as you will get disconnected):
sudo /etc/init.d/networking stop
sudo /etc/init.d/networking start

Debian/Ubuntu Linux with systemd, run:
$ sudo systemctl restart networking

mysql Port 3306 Ubuntu server all ip connet

configuration file in the terminal,

I fixed this by changing bind-address 127.0.0.1 to bind-address 0.0.0.0 in /etc/mysql/mysql.conf.d/mysqld.cnf,  (so that MySQL listens on all ports).

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
 bind-address 127.0.0.1 to bind-address 0.0.0.0

save file   exit and restart mysql 

/etc/init.d/mysql restart 

OK Work  

Read Gmail messages on other email clients using POP

You can open your messages from Gmail in other mail clients that support POP, like Microsoft Outlook.

Step 1: Make sure POP is the best way to read your emails

IMAP and POP are both ways to read your Gmail messages in other email clients.

IMAP can be used across multiple devices. Emails are synced in real time.

POP can only be used for a single computer. Emails aren’t synced in real time. Instead, they’re downloaded and you decide how often you want to download new emails.

Continue reading