Self-Signed SSL Certificate for Apache in Ubuntu 20.04

ติดตั้ง Apache

sudo apt update
sudo apt install apache2

Enabling mod_ssl

Before we can use any SSL certificates, we first have to enable mod_ssl, an Apache module that provides support for SSL encryption.

Enable mod_ssl with the a2enmod command:

$ sudo a2enmod ssl
[sudo] password for jack:
Considering dependency setenvif for ssl:
Module setenvif already enabled
Considering dependency mime for ssl:
Module mime already enabled
Considering dependency socache_shmcb for ssl:
Enabling module socache_shmcb.
Enabling module ssl.
See /usr/share/doc/apache2/README.Debian.gz on how to configure SSL and create self-signed certificates.
To activate the new configuration, you need to run:
  systemctl restart apache2

Restart Apache to activate the module:

sudo systemctl restart apache2

Creating the SSL Certificate

Now that Apache is ready to use encryption, we can move on to generating a new SSL certificate. The certificate will store some basic information about your site, and will be accompanied by a key file that allows the server to securely handle encrypted data.

We can create the SSL key and certificate files with the openssl command:

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
     -keyout /etc/ssl/private/apache-selfsigned.key \
     -out /etc/ssl/certs/apache-selfsigned.crt

private key ที่ได้จะอยู่ที่ /etc/ssl/private/apache-selfsigned.key

Configuring Apache to Use SSL

ที่ไฟล์ 000-default.conf เพิ่ม VirtualHost *:443

$ sudo nano /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

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

<VirtualHost *:443>
   DocumentRoot /var/www/html

   SSLEngine on
   SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
   SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
</VirtualHost>

Next, let’s test for configuration errors:

sudo apache2ctl configtest

Let reload apache2

sudo systemctl reload apache2

ทดลองเรียกไปที่ https://localhost

Redirecting HTTP to HTTPS

$ sudo nano /etc/apache2/sites-available/000-default.conf

To use Redirect to match any requests and send them to the SSL VirtualHost. Make sure to include the trailing slash:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        Redirect / https://jack5.com/

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

<VirtualHost *:443>
   DocumentRoot /var/www/html

   SSLEngine on
   SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
   SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
</VirtualHost>

ตอนนี้พอเรียกไปที่ http://localhost ก็จะ redirect ไปที่ https://localhost ละ

Install Mautic on Ubuntu 20.04

ก่อนติดตั้ง Mautic ต้องมี

  • Apache2
  • Mysql

Step 1: Download Mautic onto Your Ubuntu 20.04 Server

ดู release ของ Mautic ที่ github.com/mautic/mautic/releases/

Download the latest stable version by executing the following command on your server.

wget https://github.com/mautic/mautic/releases/download/4.2.1/4.2.1-update.zip
wget https://github.com/mautic/mautic/releases/download/4.4.7/4.4.7-update.zip

Install the unzip utility and unzip it to /var/www/mautic/ directory.

sudo apt install unzip

sudo mkdir -p /var/www/mautic/

sudo unzip 4.4.7-update.zip -d /var/www/mautic/

Then make the web server user (www-data) as the owner of this directory.

sudo chown -R www-data:www-data /var/www/mautic/

Step 2: Create a MariaDB Database and User for Mautic

Log in to MariaDB console.

sudo mysql

Next, create a new database for Mautic using the following command. This tutorial names it mautic, you can use whatever name you like for the database.

CREATE DATABASE mautic DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

จะมี warning ประมาณนี้

CREATE DATABASE mautic DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci	1 row(s) affected, 2 warning(s):
 3719 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
 3778 'utf8mb3_unicode_ci' is a collation of the deprecated character set UTF8MB3. Please consider using UTF8MB4 with an appropriate collation instead.

ให้เปลี่ยนเป็นใช้คำสั่งนี้แทน

CREATE DATABASE mautic DEFAULT CHARACTER SET UTF8MB4 COLLATE utf8mb4_unicode_ci;

The following command will create a database user and password, and at the same time grant all permission of the new database to the new user so later on Mautic can write to the database. Replace red texts with your preferred database name, username and password.

CREATE USER 'jack'@'localhost' IDENTIFIED BY 'password';
GRANT ALL ON mautic.* TO 'jack'@'localhost' IDENTIFIED BY 'password';

Flush privileges table and exit MariaDB console.

FLUSH PRIVILEGES;

EXIT;

Step 3: Install Required and Recommended PHP Modules.

Run the following command to install PHP modules required or recommended by Mautic

sudo apt install php-imagick php7.4-fpm php7.4-mysql php7.4-common php7.4-gd php7.4-imap php7.4-imap php7.4-json php7.4-curl php7.4-zip php7.4-xml php7.4-mbstring php7.4-bz2 php7.4-intl php7.4-gmp

เราใช้ PHP-FPM แทน PHP – PHP: FastCGI Process Manager (FPM) – Manual

If you use Apache web server, then you need to disable the PHP module for Apache.

sudo a2dismod php7.4

You also need to disable the prefork MPM module in Apache.

sudo a2dismod mpm_prefork

Now you need to run the following command to enable three modules in order to use PHP-FPM in Apache, regardless of whether mod_php is installed on your server.

sudo a2enmod mpm_event proxy_fcgi setenvif

Then restart Apache.

sudo systemctl restart apache2

Step 4: Create Apache Virtual Host for Mautic

If you use Apache web server, create a virtual host for Mautic.

sudo nano /etc/apache2/sites-available/mautic.conf

Put the following text into the file. Replace mautic.example.com with your real domain name and don’t forget to set DNS A record for it.

<VirtualHost *:80>
  ServerName mautic.example.com
  DocumentRoot /var/www/mautic/

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

  <Directory />
    Options FollowSymLinks
    AllowOverride All
  </Directory>

  <Directory /var/www/mautic/>
    Options FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
  </Directory>

</VirtualHost>

Save and close the file. Then enable this virtual host with:

sudo a2ensite mautic.conf

enable PHP-FPM – How to Install PHP-FPM with Apache on Ubuntu 20.04 (cloudbooklet.com)

sudo a2enconf php7.4-fpm

สามารถทดสอบ PHP-FPM ได้ด้วย

<?php phpinfo(); ?>

Reload Apache for the changes to take effect.

sudo systemctl reload apache2

แก้ไฟล์ /etc/hosts

sudo nano /etc/hosts
127.0.0.1       localhost
127.0.1.1       jack5.com       jack5
192.168.1.142   mautic.example.com

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

ถ้าจะเรียกจาก Windows ให้แก้ไขไฟล์ C:\Windows\System32\drivers\etc\hosts

192.168.1.142        jack5.com
192.168.1.142        mautic.example.com

Now you should be able to see the Mautic web-based install wizard at http://mautic.example.com/installer.

แก้ไขไฟล์ php.ini ของ fpm ที่ /etc/php/7.4/fpm/php.ini
(ของ php ที่ /etc/php/7.4/apache2/php.ini ไม่ต้องแก้)

$ sudo nano /etc/php/7.4/fpm/php.ini
date.timezone = Asia/Bangkok
...
memory_limit = 512M

เสร็จแล้ว reload php7.4-fpm

sudo systemctl reload php7.4-fpm

Step 5: Enabling HTTPS

sudo a2enmod ssl
sudo systemctl restart apache2
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/apache-selfsigned.key -out /etc/ssl/certs/apache-selfsigned.crt
sudo nano /etc/apache2/sites-available/mautic.conf
<VirtualHost *:443>
  ServerName mautic.example.com
  DocumentRoot /var/www/mautic/

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

  SSLEngine on
  SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
  SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key

  <Directory />
    Options FollowSymLinks
    AllowOverride All
  </Directory>

  <Directory /var/www/mautic/>
    Options FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
  </Directory>

</VirtualHost>

<VirtualHost *:80>
   ServerName mautic.example.com
   Redirect / https://mautic.example.com
</VirtualHost>
sudo a2ensite mautic.conf
sudo apache2ctl configtest
sudo systemctl reload apache2

Step 6: Finish Mautic Installation in Web Browser

  1. ใส่ข้อมูลดาต้าเบส
  2. ใส่ข้อมูล admin
  3. ใส่ข้อมูล SMTP Server , เราใช้ sendgrid.com แบบ API Key

ติดตั้ง เสร็จแล้ว login ไม่ได้ ฟ้องว่า

Unable to resolve binding type, invalid or unsupported http request

ให้แก้ไขด้วยคำสั่ง – Mautic 3. Can not login for first time – Support / Mautic 3 – Install/Upgrade Support – Mautic Community Forums

sudo a2enmod rewrite
sudo systemctl reload apache2

เมื่อ login สำเร็จจะได้หน้านี้

ติดตั้ง MySQL บน Ubuntu 20.04

ติดตั้ง MySQL

sudo apt update
sudo apt install mysql-server

ตรวจสอบสถานะ

systemctl status mysql

ลองใช้งาน

$ sudo mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.32-0ubuntu0.20.04.2 (Ubuntu)

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

สร้าง user

CREATE USER 'jack'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'jack'@'localhost';
FLUSH PRIVILEGES;
SELECT user,authentication_string,plugin,host FROM mysql.user;

ทดสอบที่ local จะเข้าได้ละ

$ sudo mysql -u jack  -p

เข้าจากเครื่องอื่น

1 Access mysqld.cnf File

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

2 Change Bind-Address IP

You now have access to the MySQL server configuration file. Scroll down to the bind-address line and change the IP address. The current default IP is set to 127.0.0.1. This IP limits MySQL connections to the local machine.

The new IP should match the address of the machine that needs to access the MySQL server remotely. For example, if you bind MySQL to 0.0.0.0, then any machine that reaches the MySQL server can also connect with it.

bind-address            = 0.0.0.0
sudo systemctl restart mysql

สร้าง remote user โดย remote ไปจากเครื่อง 192.168.1.124

CREATE USER 'jack'@'192.168.1.124' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'jack'@'192.168.1.124';
FLUSH PRIVILEGES;

Apache Virtual Hosts on Ubuntu 20.04

Step 1 — Creating the Directory Structure

sudo mkdir -p /var/www/your_domain_1/public_html
sudo mkdir -p /var/www/your_domain_2/public_html

Step 2 — Granting Permissions

sudo chown -R $USER:$USER /var/www/your_domain_1/public_html
sudo chown -R $USER:$USER /var/www/your_domain_2/public_html

หรือ

sudo chown -R www-data:www-data your_domain_1/public_html
sudo chown -R www-data:www-data your_domain_2/public_html
sudo chmod -R 755 /var/www

Step 3 — Creating Default Pages for Each Virtual Host

nano /var/www/your_domain_1/public_html/index.html
<html>
  <head>
    <title>Welcome to your_domain_1!</title>
  </head>
  <body>
    <h1>Success! The your_domain_1 virtual host is working!</h1>
  </body>
</html>
nano /var/www/your_domain_2/public_html/index.html
<html>
  <head>
    <title>Welcome to your_domain_2!</title>
  </head>
  <body>
    <h1>Success! The your_domain_2 virtual host is working!</h1>
  </body>
</html>

Step 4 — Creating New Virtual Host Files

sudo nano /etc/apache2/sites-available/your_domain_1.conf
<VirtualHost *:80>
        ServerAdmin admin@your_domain_1
        ServerName your_domain_1
        ServerAlias www.your_domain_1
        DocumentRoot /var/www/your_domain_1/public_html

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
sudo nano /etc/apache2/sites-available/your_domain_2.conf
<VirtualHost *:80>
        ServerAdmin admin@your_domain_2
        ServerName your_domain_2
        ServerAlias www.your_domain_2
        DocumentRoot /var/www/your_domain_2/public_html

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

Step 5 — Enabling the New Virtual Host Files

sudo a2ensite your_domain_1.conf
sudo a2ensite your_domain_2.conf
sudo apache2ctl configtest
sudo systemctl restart apache2
sudo systemctl status apache2

Step 6 — (Optional) Setting Up Local Hosts File

sudo nano /etc/hosts
%windir%\system32\drivers\etc\hosts
127.0.0.1   localhost
127.0.1.1   guest-desktop
your_server_IP your_domain_1
your_server_IP your_domain_2

Step 7 — Testing Your Results

http://your_domain_1
http://your_domain_2

Hostname (computer name) ของ Ubuntu 20.04

ดู Hostname

ดู Hostname ด้วยคำสั่ง hostname

$ hostname
jack5

ดู Hostname ด้วยคำสั่ง hostnamectl

$ hostnamectl
   Static hostname: jack5
         Icon name: computer-vm
           Chassis: vm
        Machine ID: d38e601ed3104707bc3b33c7058533e0
           Boot ID: afa54862c8be4726a7b75fc1e24ec4d1
    Virtualization: oracle
  Operating System: Ubuntu 20.04.6 LTS
            Kernel: Linux 5.15.0-67-generic
      Architecture: x86-64

ดู Hostname ที่ไฟล์ /etc/hostname

$ cat /etc/hostname
jack5

ดู Hostname ที่ไฟล์ /etc/hosts

$ cat /etc/hosts
127.0.0.1       localhost
127.0.1.1       jack5.com       jack5

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

ลอง ping jack5 จะได้ IP 127.0.1.1

$ ping jack5
PING jack5.com (127.0.1.1) 56(84) bytes of data.
64 bytes from jack5.com (127.0.1.1): icmp_seq=1 ttl=64 time=0.018 ms
64 bytes from jack5.com (127.0.1.1): icmp_seq=2 ttl=64 time=0.028 ms
64 bytes from jack5.com (127.0.1.1): icmp_seq=3 ttl=64 time=0.031 ms
$ ping jack5.com
PING jack5.com (127.0.1.1) 56(84) bytes of data.
64 bytes from jack5.com (127.0.1.1): icmp_seq=1 ttl=64 time=0.019 ms
64 bytes from jack5.com (127.0.1.1): icmp_seq=2 ttl=64 time=0.027 ms
64 bytes from jack5.com (127.0.1.1): icmp_seq=3 ttl=64 time=0.027 ms

ลอง ping localhost จะได้ IP 127.0.0.1

$ ping localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.587 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.025 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.025 ms

เปลี่ยน Hostname

แก้ไขไฟล์ /etc/hostname และไฟล์ /etc/hosts

sudo nano /etc/hostname
sudo nano /etc/hosts

reboot เครื่อง

sudo reboot

ติดตั้ง VirtualBox 7.0 บน Windows 11

ถ้าติดตั้ง VirtualBox 7.0 เลย อาจเจอปัญหา “Missing Dependencies Python Core / win32api”

วิธีแก้ไข “Missing Dependencies Python Core / win32api” ให้ทำดังนี้ – Fix “Python win32api” in VirtualBox – SYSNETTECH Solutions

อัพเดท pip

python.exe -m pip install --upgrade pip

เปิด Command Prompt หรือ PowerShell ด้วยสิทธิ Administrator แล้ว install pywin32

py -m pip install pywin32

ติดตั้ง VirtualBox 7.0 ด้วยสิทธิ Administrator ก็จะได้ละ – How to Install VirtualBox 7.0 – SYSNETTECH Solutions

ตอนสร้าง Guest เลือก

  • เลือก Skip Unattended Installation
  • เลือก Enable EFI

command hostname

ดูชื่อเครื่องด้วย hostname

$ hostname

ดู help

$ hostname --help
Usage: hostname [-b] {hostname|-F file}         set host name (from file)
       hostname [-a|-A|-d|-f|-i|-I|-s|-y]       display formatted name
       hostname                                 display host name

       {yp,nis,}domainname {nisdomain|-F file}  set NIS domain name (from file)
       {yp,nis,}domainname                      display NIS domain name

       dnsdomainname                            display dns domain name

       hostname -V|--version|-h|--help          print info and exit

Program name:
       {yp,nis,}domainname=hostname -y
       dnsdomainname=hostname -d

Program options:
    -a, --alias            alias names
    -A, --all-fqdns        all long host names (FQDNs)
    -b, --boot             set default hostname if none available
    -d, --domain           DNS domain name
    -f, --fqdn, --long     long host name (FQDN)
    -F, --file             read host name or NIS domain name from given file
    -i, --ip-address       addresses for the host name
    -I, --all-ip-addresses all addresses for the host
    -s, --short            short host name
    -y, --yp, --nis        NIS/YP domain name

Description:
   This command can get or set the host name or the NIS domain name. You can
   also get the DNS domain or the FQDN (fully qualified domain name).
   Unless you are using bind or NIS for host lookups you can change the
   FQDN (Fully Qualified Domain Name) and the DNS domain name (which is
   part of the FQDN) in the /etc/hosts file.

set hostname เป็น example.org

$ sudo hostname example.org
$ hostname
example.org

ดู IP ของเครื่องด้วย hostname -I

$ hostname -I
10.0.2.15 192.168.1.142

คำสั่ง AzCopy

AzCopy is a command-line utility that you can use to copy blobs or files to or from a storage account.

Download AzCopy

First, download the AzCopy V10 executable file to any directory on your computer. AzCopy V10 is just an executable file, so there’s nothing to install.

These files are compressed as a zip file (Windows and Mac) or a tar file (Linux). To download and decompress the tar file on Linux, see the documentation for your Linux distribution.

ตรวจสอบเวอร์ชันบน Command prompts

> azcopy --version
azcopy version 10.17.0

ตรวจสอบเวอร์ชันบน PowerShell

> .\azcopy --version
azcopy version 10.17.0

ดู help

> azcopy --help
AzCopy 10.17.0
Project URL: github.com/Azure/azure-storage-azcopy

AzCopy is a command line tool that moves data into and out of Azure Storage.
To report issues or to learn more about the tool, go to github.com/Azure/azure-storage-azcopy

The general format of the commands is: 'azcopy [command] [arguments] --[flag-name]=[flag-value]'.

Usage:
  azcopy [command]

Available Commands:
  bench          Performs a performance benchmark
  completion     Generate the autocompletion script for the specified shell
  copy           Copies source data to a destination location
  doc            Generates documentation for the tool in Markdown format
  env            Shows the environment variables that you can use to configure the behavior of AzCopy.
  help           Help about any command
  jobs           Sub-commands related to managing jobs
  list           List the entities in a given resource
  login          Log in to Azure Active Directory (AD) to access Azure Storage resources.
  logout         Log out to terminate access to Azure Storage resources.
  make           Create a container or file share.
  remove         Delete blobs or files from an Azure storage account
  set-properties (Preview) Given a location, change all the valid system properties of that storage (blob or file)
  sync           Replicate source to the destination location

Flags:
      --cap-mbps float                      Caps the transfer rate, in megabits per second. Moment-by-moment throughput might vary slightly from the cap. If this option is set to zero, or it is omitted, the throughput isn't capped.
  -h, --help                                help for azcopy
      --log-level string                    Define the log verbosity for the log file, available levels: INFO(all requests/responses), WARNING(slow responses), ERROR(only failed requests), and NONE(no output logs). (default 'INFO'). (default "INFO")
      --output-level string                 Define the output verbosity. Available levels: essential, quiet. (default "default")
      --output-type string                  Format of the command's output. The choices include: text, json. The default value is 'text'. (default "text")
      --skip-version-check                  Do not perform the version check at startup. Intended for automation scenarios & airgapped use.      --trusted-microsoft-suffixes string   Specifies additional domain suffixes where Azure Active Directory login tokens may be sent.  The default is '*.core.windows.net;*.core.chinacloudapi.cn;*.core.cloudapi.de;*.core.usgovcloudapi.net;*.storage.azure.net'. Any listed here 
are added to the default. For security, you should only put Microsoft Azure domains here. Separate multiple entries with semi-colons.      
  -v, --version                             version for azcopy

Use "azcopy [command] --help" for more information about a command.

Authorize AzCopy

You can provide authorization credentials by using Azure Active Directory (AD), or by using a Shared Access Signature (SAS) token.

Use this table as a guide:

Storage typeCurrently supported method of authorization
Blob storageAzure AD & SAS
Blob storage (hierarchical namespace)Azure AD & SAS
File storageSAS only

Option 1: Use Azure Active Directory

ใช้คำสั่ง azcopy login

> azcopy login
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code XXXXXXXXX to authenticate.

แล้วเปิด browser ไปที่ https://microsoft.com/devicelogin แล้วใส่ code

เลือก account เสร็จแล้ว จะมีหน้าถามว่า Are you trying to sign in to Azure Storage AzCopy? ให้กด Continue

กลับมาที่ terminal จะขึ้นว่า INFO: Login succeeded.

Option 2: Use a SAS token

You can append a SAS token to each source or destination URL that use in your AzCopy commands.

This example command recursively copies data from a local directory to a blob container. A fictitious SAS token is appended to the end of the container URL.

azcopy copy %LOCAL_PATH% %BLOB_PATH%?%SAS_KEY% --recursive=true
azcopy copy "C:\local\path" "https://account.blob.core.windows.net/mycontainer1/?sv=2018-03-28&ss=bjqt&srt=sco&sp=rwddgcup&se=2019-05-01T05:01:17Z&st=2019-04-30T21:01:17Z&spr=https&sig=MGCXiyEzbtttkr3ewJIh2AR8KrghSy1DGM9ovN734bQF4%3D" --recursive=true

เมื่อทำงานเสร็จก็ logout

> azcopy logout
INFO: Logout succeeded.

WordPress – ปรับความกว้างให้ธีม Twenty Eleven

ไปที่ Appearance | Customize | Additional CSS แล้วเพิ่ม CSS ดังนี้

#page {
  max-width: 1300px;
}

/* One column */
.one-column #page {
  max-width: 1300px;
}

ติดตั้ง Apache บน Ubuntu 20.04

Step 1 — Installing Apache

sudo apt update
sudo apt install apache2

Step 2 — Adjusting the Firewall

อันนี้ข้ามได้

$ sudo ufw app list
Available applications:
  Apache
  Apache Full
  Apache Secure
  OpenSSH

As indicated by the output, there are three profiles available for Apache:

  • Apache: This profile opens only port 80 (normal, unencrypted web traffic)
  • Apache Full: This profile opens both port 80 (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic)
  • Apache Secure: This profile opens only port 443 (TLS/SSL encrypted traffic)

It is recommended that you enable the most restrictive profile that will still allow the traffic you’ve configured. Since we haven’t configured SSL for our server yet in this guide, we will only need to allow traffic on port 80:

$ sudo ufw allow 'Apache'
Rules updated
Rules updated (v6)

You can verify the change by typing:

$ sudo ufw status
Status: inactive

ถ้าเป็น inactive ก็ทำการ enable ufwBasic UFW (Uncomplicated Firewall) commands – Serverspace.io

sudo ufw enable

แต่ถ้าใช้ Ubuntu บน WSL2 จะใช้ ufw ไม่ได้ – security – I can’t use ufw on WSL-Ubuntu – Ask Ubuntu

Step 3 — Checking your Web Server

$ systemctl status apache2

แต่ถ้ารันคำสั่งนี้ใน WSL2 จะไม่ได้

$ systemctl status apache2
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

ถ้าใช้ Ubuntu 20.04 ใน WSL2 ใช้คำสั่ง

$ service apache2 status
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2023-03-27 14:49:22 +07; 1min 2s ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 4834 (apache2)
      Tasks: 55 (limit: 9444)
     Memory: 5.0M
     CGroup: /system.slice/apache2.service
             ├─4834 /usr/sbin/apache2 -k start
             ├─4835 /usr/sbin/apache2 -k start
             └─4836 /usr/sbin/apache2 -k start
$ sudo service apache2 reload
$ sudo service apache2 restart

ทดลองเข้าใช้งานที่ http://localhost/

หรือใช้คำสั่ง hostname เพื่อดู IP ของเครื่อง แล้วเข้าด้วย IP ได้

$ hostname -I

Step 4 — Other

ตรวจสอบไฟล์ /etc/apache2/sites-available/000-default.conf

$ cat /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

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

APACHE_LOG_DIR ค่า default เป็น /var/log/apache2What is the Apache error log location on Linux (xmodulo.com)

$ ls -l /var/log/apache2/
total 36
-rw-r----- 1 root adm 16024 Mar 16 13:42 access.log
-rw-r----- 1 root adm 16683 Mar 16 13:42 error.log
-rw-r----- 1 root adm     0 Mar 14 16:42 other_vhosts_access.log