Categories
Uncategorized

Filament Laravel

  • Install Laravel + Livewire + Filament
#Require : Php 8, Livewire, Filament
#Go to folder development, ex : /var/www
composer global require laravel/installer
laravel new filamentphp
cd filamentphp
composer require livewire/livewire
composer require filament/filament:"^2.0"
  • Start Laravel
#First create database name same as project or edit .env file to change db config
php artisan migrate
composer require doctrine/dbal --dev
php artisan make:filament-user
php artisan make:filament-resource User --generate
#Access : siteurl + /admin
  • Create Module
php artisan make:model Post --migration
#Edit file migration database\migrations\xxx_create_posts_table
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->string('slug');
$table->longText('content');
$table->dateTime('date_created');
$table->dateTime('date_modified');
});

#Edit file migration \app\Models\Post
protected $fillable = [
        'title',
        'slug',
        'content',
    ];

php artisan migrate
php artisan make:filament-resource Post --generate
  • Modify Resource
#Edit file \app\Filament\Resources\Post
Categories
Uncategorized

Centos 7 – Add Port

  • Start – Enable httpd
    • sudo systemctl start httpd
    • sudo systemctl enable httpd
    • sudo systemctl status httpd
  • Firewall Add Service
    • sudo firewall-cmd –list-all
    • sudo firewall-cmd –add-service=http –permanent
    • sudo firewall-cmd –add-service=https –permanent
    • sudo firewall-cmd –reload
    • sudo firewall-cmd –list-all
  • Firewall Add Port
    • sudo firewall-cmd –zone=public –add-port=80/tcp –permanent
    • sudo firewall-cmd –zone=public –permanent –add-port=443/tcp
    • sudo firewall-cmd –reload
  • IP add port
    • sudo iptables -I INPUT 5 -i eth0 -p tcp –dport 80 -m state –state NEW,ESTABLISHED -j ACCEPT
    • sudo iptables -I INPUT 5 -i eth0 -p tcp –dport 443 -m state –state NEW,ESTABLISHED -j ACCEPT
    • sudo iptables –line -vnL
  • Telnet xx.xx.xx.xx(IP ADDRESS) xx(PORT)

 

 

Categories
Uncategorized

Create Subdomain at DigitalOcean (Apache)

  • Create a New Hostname with an A Record
    • To add the hostname from the control panel, click Networking in the main menu. In the Domains tab, click the domain name you would like to add the new hostname to.
    • In the Create new record screen, click the A tab.
  • Create sub directory & host project files
    • Create a directory under /var/www/ the directory using the commands
    • cd /var/www/
    • mkdir subdomain.website.com
    • sudo nano index.html
  • Configure Virtual Host
    • cd /etc/apache2/sites-available/
    • cp 000-default.conf subdomain.website.com.conf
    • nano subdomain.website.com.conf
    • Now once you are inside the config file, change the following
      • #ServerName
      • #ServerAlias
      • #DocumentRoot
  • Enabling the New Virtual Host Files
    • sudo a2ensite subdomain.website.com.conf
    • sudo a2dissite 000-default.conf
    • sudo systemctl restart apache2

 

https://docs.digitalocean.com/products/networking/dns/how-to/add-subdomain/#create-a-new-hostname-with-an-a-record

https://medium.com/@Madgeek_in/how-to-create-subdomains-on-digitalocean-lamp-df501dff5855

https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-16-04

Categories
Uncategorized

Email Validation with Field Pattern

<input type=”email” name=”sample_email” pattern=”[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$”>

Categories
Uncategorized

Random Nonce for Non User

Will only be generated if user not login access nonce.

add_filter( ‘nonce_user_logged_out’, ‘generate_randomUID’ );
function generate_randomUID( $uid ) {
if($uid != 0){
return $uid;
}else{
return wp_generate_uuid4();
}
}

Categories
Uncategorized

Digital Ocean Droplet Ubuntu 20 – Nginx, Php, Mysql, Phpmyadmin

Digital Ocean

  • Create Droplet on Digitalocean
  • New SSh Key
    • Open puttygen and generate new key
    • Save private key and Save public key, no phasspassword is okay
    • Copy the key Content that has been generated by puttygen
    • Paste it to the SSh field on Digitalocean, and name the key

Putty on Server

  • sudo apt update
  • Nginx
    • sudo apt install nginx
    • sudo ufw app list
      • Check which UFW profiles are available
    • sudo ufw allow ‘Nginx HTTP’
      • Since you haven’t configured SSL for your server in this guide, you will only need to allow regular HTTP traffic on port 80
    • curl -4 icanhazip.com
      • Check IP address is accessible from the internet
      • Try to access the IP address from the browser
  • Mysql
    • sudo apt install mysql-server
  • Php
    • sudo add-apt-repository -y ppa:ondrej/php
    • sudo add-apt-repository -y ppa:ondrej/nginx-mainline
    • sudo apt update -y
    • sudo apt upgrade -y
    • sudo apt install -y -q php8.1-{cli,fpm,mysql,gd,soap,mbstring,bcmath,common,xml,curl,imagick,fileinfo,gettext,mbstring,SimpleXML,zip}
  • Configure Nginx
    • sudo mkdir /var/www/your_domain
      • Create root directory for website
    • sudo chown -R $USER:$USER /var/www/your_domain
      • Assign ownership of the directory
    • sudo nano /etc/nginx/sites-available/your_domain
      • server {
            listen 80;
            server_name your_domain www.your_domain;
            root /var/www/your_domain;
        
            index index.html index.htm index.php;
        
            location / {
                try_files $uri $uri/ =404;
            }
        
            location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
             }
        
            location ~ /\.ht {
                deny all;
            }
        
        }
      • CTRL+X and then y and ENTER to confirm
    • sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/
    • sudo unlink /etc/nginx/sites-enabled/default
    • sudo nginx -t
    • sudo systemctl reload nginx
    • nano /var/www/your_domain/index.html
      • Hello world!
      • CTRL+X and then y and ENTER to confirm
    • curl -4 icanhazip.com
      • Try to access the IP address from the browser
  • Phpmyadmin
    • sudo apt install phpmyadmin
    • Click Tab straight to OK, without choosing any web server
    • Yes for dgconfig-common, set password
    • sudo ln -s /usr/share/phpmyadmin /var/www/your_domain/phpmyadmin
    • sudo mysql -u root -p
      • enter mysql password
      • CREATE USER ‘pmauser’@’localhost’ IDENTIFIED BY ‘password_here’;
      • GRANT ALL PRIVILEGES ON *.* TO ‘pmauser’@’localhost’;
      • exit
    • curl -4 icanhazip.com
      • Try to access the IP address from the browser, http://your_domain/phpmyadmin
    • sudo mv /var/www/your_domain/phpmyadmin /var/www/your_domain/hide_phpmyadmin
      • Secure the url from common url phpmyadmin
    • sudo apt install apache2-utils
      • Secure phpmyadmin with popup credential
      • sudo htpasswd -c /etc/nginx/.htpasswd username , set new password after that
      • sudo nano /etc/nginx/sites-available/your_domain
        • location /hide_phpmyadmin {
                  auth_basic "Restricted Access";
                  auth_basic_user_file /etc/nginx/.htpasswd;
          }
      • sudo service nginx reload
  • Firewall
    • sudo nano /etc/default/ufw
      • Check that IPV6=yes
    • sudo ufw default deny incoming
    • sudo ufw default allow outgoing
    • sudo ufw app list
    • sudo ufw allow OpenSSH
      • Or sudo ufw allow 22
      • Or sudo ufw allow ssh
    • sudo ufw show added
      • Check rules that have been added
    • sudo ufw enable
    • sudo ufw allow ‘Nginx Full’
      • Include sudo ufw allow http
      • Include sudo ufw allow https
  • Fail2ban
    • apt install fail2ban
  • Add New User
    • adduser sammy
      • Setup password and information details
    • usermod -aG sudo sammy
    • su – sammy
      • Switch active user to sammy
    • sudo ls -la /root
      • Test one of the sudo command
      • Enter password for confirmation

 

References :

https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-20-04

https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-phpmyadmin-with-nginx-on-an-ubuntu-20-04-server

https://www.vultr.com/es/docs/installing-configuring-and-securing-php-8-1-on-ubuntu-20-04

https://devanswers.co/install-secure-phpmyadmin-nginx-ubuntu-20-04

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-with-ufw-on-ubuntu-18-04

https://serverspace.io/support/help/install-configure-fail2ban-ubuntu-20-04/

https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys-on-ubuntu-20-04

Categories
Uncategorized

Recommended WordPress Plugin

Instagram Feed :
https://wordpress.org/plugins/wd-instagram-feed/
https://wordpress.org/plugins/instagram-feed/

Woocommerce Discount Rule :
https://www.flycart.org/products/wordpress/woocommerce-discount-rules

Woocommerce Filter Product :
https://wordpress.org/plugins/woocommerce-products-filter/

Woocommerce Custom Advanced Report :
https://aspengrovestudios.com/product/product-sales-report-pro-for-woocommerce/

Woocommerce Print Order Detail :
https://tokopress.id/plug-and-ship/

Categories
Uncategorized

Dynamic Value Selection – ContactForm7

Dynamic Select List in Contact Form 7

function dynamic_select_field_values ( $scanned_tag, $replace )
{

if ( $scanned_tag[‘name’] != ‘products’ )
return $scanned_tag;

$rows = get_posts(
array (
‘post_type’ => ‘products’,
‘numberposts’ => -1,
‘orderby’ => ‘title’,
‘order’ => ‘ASC’
)
);

if ( ! $rows )
return $scanned_tag;

foreach ( $rows as $row ) {
$scanned_tag[‘raw_values’][] = $row->post_title . ‘|’ . $row->post_title;
}

$pipes = new WPCF7_Pipes($scanned_tag[‘raw_values’]);

$scanned_tag[‘values’] = $pipes->collect_befores();
$scanned_tag[‘labels’] = $pipes->collect_afters();
$scanned_tag[‘pipes’] = $pipes;

return $scanned_tag;
}

add_filter( ‘wpcf7_form_tag’, ‘dynamic_select_field_values’, 10, 2);

Categories
Uncategorized

WordPress Menu Tree

class Menu_tree{

public $menu_list;
public $menu_items;

function __construct() {

$menu = wp_get_nav_menu_object( ‘main-menu’ );
$this->menu_items = wp_get_nav_menu_items($menu->term_id);
$this->menu_list = array();
$this->getMenu();
}

function getMenu(){

foreach( $this->menu_items as $key => $current ) {

$current->children = array();

if($current->menu_item_parent == 0) // first parent
{
$this->menu_list[ $current->ID ] = $current;
}
else
{
if(isset($this->menu_list[ $current->menu_item_parent ])) // if child of first parent
{
$this->menu_list[ $current->menu_item_parent ]->children[ $current->ID ] = $current;
}
else
{
$this->current = $current;
$this->checkChildren(); // Setting up CHILDREN
}
}

}

return $this->menu_list;
}

function checkChildren($data = array()){

$last_arr = end($this->menu_list);

if(empty($data)) // FIRST CHILDREN LOOP
{
foreach( $last_arr->children as $key => $current ) {

if( $current->ID == $this->current->menu_item_parent )
{
$current->children[ $this->current->ID ] = $this->current;
break;
}

if(!empty($current->children))
{
$this->checkChildren($current->children);
}
}
}
else // RELOOP TO Children
{
foreach( $data as $key => $current ) {
if( $current->ID == $this->current->menu_item_parent )
{
$current->children[ $this->current->ID ] = $this->current;
break;
}

if(!empty($current->children))
{
$this->checkChildren($current->children);
}
}
}
}
}

Categories
Uncategorized

Hello world!

Welcome to WordPress. This is your first post. Edit or delete it, then start writing!