ก๊วนซอฟท์แวร์ </softganz> SoftGang (Gang Software)

Web &amp; Software Developer Gang.

617 items|« First « Prev 1 (2/62) 3 4 5 Next » Last »|
โดย Little Bear on 30 ก.ค. 67 12:00

กำลังศึกษาเรื่อง Class บน JavaScript อยู่

ที่มา

โดย Little Bear on 7 ก.ค. 67 17:27

/var/log/apache2/error.log

[Sun Jul 07 14:36:12.269017 2024] [mpm_prefork:error] [pid 3153653:tid 3153653] AH00161: server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting

/var/log/php7.4-fpm.log

  • [07-Jul-2024 00:00:01] NOTICE: error log file re-opened
  • [07-Jul-2024 13:15:25] WARNING: [pool www] server reached pm.max_children setting (5), consider raising it
nano /etc/php/7.4/fpm/pool.d/www.conf
change
pm.max_children = 5
to
pm.max_children = 20
nano /etc/apache2/mods-enabled/mpm_prefork.conf
<IfModule mpm_prefork_module>
    #StartServers       10
    MinSpareServers       10
    MaxSpareServers      20
    #MaxRequestWorkers    150
    #MaxConnectionsPerChild   0

    ServerLimit              250
    StartServers              10
    #MinSpareThreads           75
    #MaxSpareThreads          250<br />
    #ThreadLimit               64
    #ThreadsPerChild           32
    MaxRequestWorkers       250
    MaxConnectionsPerChild 10000
</IfModule>
โดย Little Bear on 13 พ.ค. 67 09:40

กลับมาเริ่มเขียน IoT ใหม่อีกครั้ง หลังจากทิ้งไปนาน

NodeMcu

Additional Boards Manager URLs

http://arduino.esp8266.com/stable/packageesp8266comindex.json
Board: esp8266
Select board: NodeMCU 1.0
Port: dev/cu.usbserial-21110

ESP-32

Additional Boards Manager URLs

https://dl.espressif.com/dl/packageesp32index.json
(สำรอง)https://espressif.github.io/arduino-esp32/packageesp32index.json
(สำรอง)https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/packageesp32index.json
Board: esp32 by Espressif
Select board: ESP32-WROOM-DA Module or ESP32 Dev Port: dev/cu.usbserial-0001
Upload speed: 460800 (***** ระวัง ความเร็ว 921600 ใช้งานไม่ได้ อัพโหลดโปรแกรมแล้วเกิดข้อผิดพลาด *****)

Resource:

โดย Little Bear on 10 พ.ค. 67 14:00

มีโจทย์ว่าต้องการเพิ่ม user ใน Ubuntu แต่จำกัดไม่ให้เปลี่ยน folder หรือ ไม่ให้เข้าถึงบาง folder ซึ่งตามปกติบน Linux จะจัดการสิทธิได้ 3 ระดับ คือ เจ้าของ/กลุ่ม/คนอื่นๆ โดยไม่สามารถจัดการเฉพาะ user ได้

จึงจำเป็นต้องใช้โปรแกรมสำหรับจัดการสิทธิเพิ่มเติม ในที่นี้จะใช้ setfacl : set file access control lists - Linux

1.ยกเลิกการเข้าถึง folder

setfacl -m user:username:--- folder/

2.อื่น ประมาณเช่น

setfacl -R -m g:username:rwx /home/user1/domains/xxx.com/folder/
setfacl -m u:username:--x /home/user1/domains/xxx.com/
setfacl -R -x user:username /home/user1/domains/xxx.com/folder/
setfacl -m u:username:--x /home/user1/domains
setfacl -m u:username:--x /home/user1

3.ขอดูสิทธิ

getfacl folder

โดย Little Bear on 3 เม.ย. 67 16:03

yum update iproute
yum update ss

โดย Little Bear on 24 ธ.ค. 66 10:51
brew services list
brew services restart nginx
/opt/homebrew/opt/nginx/bin/nginx -g daemon off;

brew install shivammathur/php/php@7.4
brew reinstall php@7.4

sudo lsof -i -n -P|grep php-fpm

brew services start php@8.2

แก้ไขไฟล์ opt/homebrew/etc/nginx/nginx.conf

    location / {
        root /path/to/www;
        try_files $uri $uri/ /index.php?$uri&$args;
    }

Install multiple PHP version

brew tap shivammathur/php

เลือกมาสักเวอร์ชั่น

brew install shivammathur/php/php@5.6
brew install shivammathur/php/php@7.0
brew install shivammathur/php/php@7.1
brew install shivammathur/php/php@7.2
brew install shivammathur/php/php@7.3
brew install shivammathur/php/php@7.4
brew install shivammathur/php/php@8.0
brew install shivammathur/php/php@8.1
brew install shivammathur/php/php@8.2
brew install shivammathur/php/php@8.3

Mac M1 : Config file อยู่ที่

/opt/homebrew/etc/php/7.0/php.ini
/opt/homebrew/etc/php/7.1/php.ini
/opt/homebrew/etc/php/7.2/php.ini
/opt/homebrew/etc/php/7.3/php.ini
/opt/homebrew/etc/php/7.4/php.ini
/opt/homebrew/etc/php/8.0/php.ini
/opt/homebrew/etc/php/8.1/php.ini
/opt/homebrew/etc/php/8.2/php.ini
/opt/homebrew/etc/php/8.3/php.ini

แก้ไขไฟล์ php.ini ที่ /opt/homebrew/etc/php/8.0/php-fpm.d/www.conf เปลี่ยน port จาก 9000 เป็น 9080

restart php

brew services start php@8.0

Problem

1.Can't upload jpg/pdf

โดย Little Bear on 22 ธ.ค. 66 14:19

Mount harddisk

Using /dev/disk/by-uuid/:

  • Open a terminal.
  • Type ls -l /dev/disk/by-uuid/ and press Enter.
  • This will display a list of symlinks, where the filename is the UUID and the target is the device it points to (e.g., lrwxrwxrwx 1 root root 10 Jul 12 12:00 1234-5678 -> ../../sda1).
  • Identify the UUID you need and then use the corresponding device path (e.g., /dev/sda1) in other commands if needed.

Create user

Ubuntu create user account commands
sudo adduser <username>

Make user to sudoer

sudo adduser <username> sudo

Make user ssh




Step 1 – Installing the Nginx Web Server

sudo apt update
sudo apt upgrade

sudo apt install nginx

sudo nginx -t

Restart nginx

sudo systemctl restart nginx
sudo systemctl reload nginx
sudo service nginx restart
sudo service nginx reload

Enable HTTP/2 in Nginx on Ubuntu

sudo nano /etc/nginx/sites-available/your_domain
listen 443 ssl http2;
listen [::]:443 ssl http2 ipv6only=on;

Step 2 – Installing MariaDB to Manage Site Data

sudo apt install mariadb-server
sudo mysqlsecureinstallation
    Switch to unixsocket authentication [Y/n] n
sudo mysql
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysqlnative_password BY 'password';
mysql> FLUSH PRIVILEGES;

ปรับแต่ง config

nano /etc/mysql/mariadb.conf.d/50-server.cnf

[mysqld]
log_slow_query_file    = /var/log/mysql/mariadb-slow.log
log_slow_query_time    = 2<br />
...
innodb_buffer_pool_size = 256M
innodb_log_file_size = 128M

ตรวจสอบตารางว่า crash หรือไม่

mariadb-check -u user -p -c database

Step 3 – Installing PHP and Configuring Nginx to Use the PHP Processor => รายละเอียด

ถ้าต้องการถอด php ออก ด้วย

sudo apt-get purge php7.*
sudo apt-get autoclean
sudo apt-get autoremove

Install php

sudo apt purge php8.*
sudo add-apt-repository ppa:ondrej/php
sudo apt update && sudo apt-get install ca-certificates apt-transport-https software-properties-common
sudo apt install php8.3-fpm
php -v
php --modules
apt install -y php8.3-common php8.3-fpm php8.3-mysql php8.3-redis php8.3-mongodb php8.3-zip php8.3-gd php8.3-mbstring php8.3-cli php8.3-curl php8.3-xml php8.3-bcmath

ปรับ config PHP

เปลี่ยนค่า session.gcprobability, date.timezone, postmaxsize, uploadmax_filesize

nano /etc/php/8.3/fpm/php.ini

session.gc_probability = 1
date.timezone = Asia/Bangkok
post_max_size = 64M
upload_max_filesize = 64M

แก้ไขค่า php pool

nano /etc/php/8.3/fpm/pool.d/www.conf

pm.max_children = 30
pm.start_servers = 5
pm.min_spare_servers = 3
pm.max_spare_servers = 5

Enabling PHP8.3 on Nginx server

sudo nano /etc/nginx/sites-available/default

location ~ \.php$ {
        include snippets/fastcgi-php.conf
        # With php-fpm (or other unix sockets):
        fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
        # With php-cgi (or other tcp sockets):
        <a class="hashtag" href="/tags/fastcgi">#fastcgi</a>_pass 127.0.0.1:9000;
}

index index.php index.html

Restart php

sudo service php8.3-fpm restart

Restart nginx

sudo systemctl restart nginx.service

Install phpmyadmin

apt install phpmyadmin
sudo ln -s /usr/share/phpmyadmin /var/www/your_domain/phpmyadmin

Create site config

cd /etc/nginx/sites-available
nano domain.conf

cd /etc/nginx/sites-enabled ln -s ../sites-available/domain.conf domain.conf







Old version

sudo add-apt-repository universe
sudo apt install php-fpm php-mysql
sudo apt install php8.1-mbstring
sudo apt install php8.1-gd

php --version which php whereis php

sudo nano /etc/nginx/sites-available/your_domain

/etc/nginx/sites-available/yourdomain

server {
        listen 80;
        root /var/www/html;
        index index.php index.html index.htm index.nginx-debian.html;
        servername your_domain;

    location / {
           try_files $uri $uri/ /index.php?$uri&amp;$args;
           # try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }

    location ~ /\.ht {
            deny all;
    }

}

Step 4 - How To Secure Nginx with Let's Encrypt on Ubuntu 22.04

sudo apt remove certbot
sudo snap install core; sudo snap refresh core
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot

ติดตั้ง SSL Certificate Filde วิธีการติดตั้ง SSL Certificate บน Nginx Server

Step 5 – ขั้นตอนสุดทัาย - Check List

1. Create new user



ติดตั้ง ssl แบบ manual
server {
    ...
    listen 443 ssl; # managed by manual
    sslcertificate    /etc/ssl/certs/filename.crt;
    sslcertificatekey    /etc/ssl/certs/filename.key;
    # sslcertificate_chain /etc/ssl/filename.chain
}

config PHP

Change timezone to Asia/Bangkok
sudo nano /etc/php/8.3/fpm/php.ini
Then change
date.timezone = Asia/Bangkok
Then restart php
sudo service php8.3-fpm restart
เปลี่ยนขนาดอัพโหลดไฟล์
It sets the maximum allowed size of the client request body, specified in the “Content-Length” request header field. Here’s an example of increasing the limit to 50MB in /etc/nginx/nginx.conf file. Set in http block which affects all server blocks (virtual hosts).
nano /etc/nginx/nginx.conf
http {
    ...
    client_max_body_size 50M;
}
In each domain config in site-a Set in server block, which affects a particular site/app
nano /etc/nginx/sites-available/domain.conf
server {
    ...
    client_max_body_size 50M;
}
Set in location block, which affects a particular directory (uploads) under a site/app.
location /uploads {
    ...
    client_max_body_size 50M;
}<br />
Save the file and restart Nginx web server to apply the recent changes using following command.
systemctl restart nginx

ถอนการติดตั้ง

หากมีการติดตั้ง apache2 ไว้ก่อน สามารถถอนการติดตั้งด้วย

apt-get purge apache2
apt-get autoremove

กรณีการอัพเกรดจาก Apache มีขั้นตอนของการตรวจสอบ และ ถอดโปรแกรม

uname -a
Linux alumni 5.4.0-167-generic <a class="hashtag" href="/tags/184">#184</a>-Ubuntu SMP Tue Oct 31 09:21:49 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.1 LTS
Release:    20.04

apachectl -v
Server version: Apache/2.4.41 (Ubuntu)
Server built:   2023-10-26T13:54:09

php -v
PHP 7.4.3-4ubuntu2.20 (cli) (built: Feb 21 2024 13:54:34) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3-4ubuntu2.20, Copyright (c), by Zend Technologies

mysql --version
mysql  Ver 15.1 Distrib 10.3.39-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

<a class="hashtag" href="/tags/apt">#apt</a> update
<a class="hashtag" href="/tags/apt">#apt</a> list --upgradable<br />
<br />
<br />
add-apt-repository ppa:ondrej/apache2
apt update
apt upgrade

do-release-upgrade

ssh recovery port 1022
โดย Little Bear on 15 ธ.ค. 66 09:20

กำลังศึกษาวิธีการจัดการ light/dark mode เพิ่งเริ่ม เดี๋ยวค่อยกลับมาเขียนต่อ

keyword: force for darkmode using prefers-color-scheme: dark

ที่มา

โดย Little Bear on 1 ส.ค. 66 10:49

กำลังเปลี่ยน Class MyDb() ของเดิมเป็น Class SoftganzDB() ของใหม่ และเปลี่ยนมาใช้ PDO แทน mysqli

ที่มา

โดย Little Bear on 24 พ.ค. 66 13:39

เดิมเคยเก็บโดยการแปลงด้วยคำสั่ง jsonencode แต่มักจะเกิดปัญหาเมื่อมีอักขระบางตัวหรือการขึ้นบรรทัดใหม่ ซึ่งจะทำให้ไม่สามารถแปลงกลับด้วยคำสั่ง jsondecode

แต่....

MySQL version 5.7.8 ได้เพิ่ม JSON data type ให้แล้ว (แม้ว่าเมื่อเลือกเป็น JSON data type แล้ว MySQL ก็จะเก็บเป็น longtext type ก็ตาม)

และมีคำสั่งเฉพาะในการจัดการกับข้อมูล เช่น

JSONOBJECT,
JSONARRAY,
JSONMERGEPRESERVE,
 JSONMERGEPATCH,
 JSONTYPE,
 JSONEXTRACT,
 JSONINSERT,
 JSONREPLACE,
 JSONSET,
 JSONREMOVE

JSON-SET:

UPDATE iot
SET dataJson = JSON-SET(
    dataJson,
    "$.test",
    "1"
)
WHERE nodeDataId=3

JSON-REPLACE จะบันทึกค่าทับของเดิม แต่หากของเดิมไม่เคยมี key นั้นอยู่ ก็จะไม่มีการบันทึกข้อมูลใหม่ลงไป

JSON-SET จะบันทึกข้อมูลทับของเดิม หากยังไม่เคยมี key นั้นอยู่ ก็จะสร้างเพิ่มให้โดยอัตโนมัติ

ลองดูรายละเอียดได้จาก How To Work with JSON in MySQL

ที่มา

617 items|« First « Prev 1 (2/62) 3 4 5 Next » Last »|