Sugeng rawuh

Membuat autocomplete Dart Flutter

List<String> suggestons = ["USA", "UK", "Uganda", "Uruguay", "United Arab Emirates"];
 Expanded(child: Autocomplete( optionsBuilder: (TextEditingValue textEditingValue){
if (textEditingValue.text == ''){
return const Iterable<String>.empty();
} else {
List<String> matches = <String>[];
matches.addAll(suggestons);
matches.retainWhere((s) {
return s.toLowerCase().contains(textEditingValue.text.toLowerCase());
});
return matches;
}
},
onSelected: (String selected){
print('Selection $selected');
},
)
Hasilnya



Share:

Full block nginx

##

# You should look at the following URL's in order to grasp a solid understanding

# of Nginx configuration files in order to fully unleash the power of Nginx.

# https://www.nginx.com/resources/wiki/start/

# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/

# https://wiki.debian.org/Nginx/DirectoryStructure

#

# In most cases, administrators will remove this file from sites-enabled/ and

# leave it as reference inside of sites-available where it will continue to be

# updated by the nginx packaging team.

#

# This file will automatically load configuration files provided by other

# applications, such as Drupal or Wordpress. These applications will be made

# available underneath a path with that package name, such as /drupal8.

#

# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.

##


# Default server configuration

#

server {

listen 80;

listen [::]:80;

# SSL configuration

#

# listen 443 ssl default_server;

# listen [::]:443 ssl default_server;

#

# Note: You should disable gzip for SSL traffic.

# See: https://bugs.debian.org/773332

#

# Read up on ssl_ciphers to ensure a secure configuration.

# See: https://bugs.debian.org/765782

#

# Self signed certs generated by the ssl-cert package

# Don't use them in a production server!

#

# include snippets/snakeoil.conf;


root /var/www/html;


# Add index.php to the list if you are using PHP

index index.php index.html index.htm index.nginx-debian.html;


server_name 8.222.129.138 backoffice.blueray.id;


location / {

# First attempt to serve request as file, then

# as directory, then fall back to displaying a 404.

# try_files $uri $uri/ =404;

# try_files $uri $uri/ /index.php$is_args$args;

try_files $uri $uri/ /index.php?$query_string;

}


location /order {

        alias /var/www/html/order/public;

        try_files $uri $uri/ @order;


        location ~ \.php$ {

            include snippets/fastcgi-php.conf;

            fastcgi_param SCRIPT_FILENAME $request_filename;

            fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;

        }

    }


        location /port {

        alias /var/www/html/port/public;

        try_files $uri $uri/ @port;


        location ~ \.php$ {

            include snippets/fastcgi-php.conf;

            fastcgi_param SCRIPT_FILENAME $request_filename;

            fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;

         }       

         }


    location @order {

        rewrite /order/(.*)$ /order/index.php?/ last;

    }


        location @port {

        rewrite /port/(.*)$ /port/index.php?/ last;

    }



# pass PHP scripts to FastCGI server

#

location ~ \.php$ {

include snippets/fastcgi-php.conf;

#

# # With php-fpm (or other unix sockets):

fastcgi_pass unix:/run/php/php8.2-fpm.sock;

# # With php-cgi (or other tcp sockets):

# fastcgi_pass 127.0.0.1:9000;

}


# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

#location ~ /\.ht {

# deny all;

#}

}



# Virtual Host configuration for example.com

#

# You can move that to a different file under sites-available/ and symlink that

# to sites-enabled/ to enable it.

#

#server {

# listen 80;

# listen [::]:80;

#

# server_name example.com;

#

# root /var/www/example.com;

# index index.html;

#

# location / {

# try_files $uri $uri/ =404;

# }

#}


Share:

#7 Memberikan permittion folder laravel Chmod

Keterangan 

 chmod -R a+rwx /var/www/html/folder
Share:

#6 Compress file and folder to .zip Ubuntu

Keterangan 
Folder yang akan di compress = port
nama file hasil compress = port.zip

  zip -r port.zip /var/www/html/port/
Share:

#5 Upload file ke server ubuntu menggunakan terminal

Sebelum upload file pastikan directory atau tempat penyimpanan file sudah anda tentukan sebelumnya, apabila sudah silahkan copy code berikut ini dan pastekan di terminal komputer anda

1. Upload File .zip by Terminal

keterangan 
Nama file yang akan di upload : laravelv8.zip
lokasi upload server ubuntu alibaba : /var/www/html/port
ip vps : 10.222.111.145

  scp -r /Applications/XAMPP/htdocs/laravelv8.zip root@10.222.111.145:/var/www/html/port/
Share:

laravel 8 : ErrorException failed to open stream: Permission denied

php artisan cache:clear

chmod -R 777 storage/

composer dump-autoload
Share:

JWT Token pada Laravel 8

Saya membayangkan kalian sudah mempunyai projeck laravel, jadi tinggal ikuti saja langkah-langkah berikut ini

1. Install JWT

Untuk penjelasan tentang JWT kalian bisa baca di blog codepolitan
Instal paket jwt-auth pihak ketiga. Anda dapat menjalankan perintah berikut untuk melakukannya:
 composer require tymon/jwt-auth

2. Tambahkan paket JWT ke penyedia layanan | provider

Buka file config/app.php dan perbarui array provider dan aliases.
'providers' => [
     ...
    'Tymon\JWTAuth\Providers\LaravelServiceProvider',
],
'aliases' => [
    ...
    'JWTAuth' => Tymon\JWTAuth\Facades\JWTAuth::class,
    'JWTFactory' => Tymon\JWTAuth\Facades\JWTFactory::class,
],

3. Publikasikan konfigurasi jwt

  php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"

4. Generate JWT Key

  php artisan jwt:secret
untuk cek token anda, bisa dibuka di file .env
silahkan cek pada bagian bawah sendiri

JWT_SECRET

5. Create JWT Middleware

Sebelum kita mulai menentukan rute API kita, kita harus membuat middleware JWT. Itu akan melindungi rute kita. Anda dapat menggunakan middleware JWT untuk memverifikasi permintaan dari rute API
  php artisan make:middleware JwtMiddleware
Silahkan buka file JwtMiddleware.php dan pastekan code berikut ini

-----------------------------------------------
<?php
namespace App\Http\Middleware; use Closure; use JWTAuth; use Exception; use Tymon\JWTAuth\Http\Middleware\BaseMiddleware; class JwtMiddleware extends BaseMiddleware { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { try { $user = JWTAuth::parseToken()->authenticate(); } catch (Exception $e) { if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenInvalidException){ return response()->json(['status' => 'Token is Invalid']); }else if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenExpiredException){ return response()->json(['status' => 'Token is Expired']); }else{ return response()->json(['status' => 'Authorization Token not found']); } } return $next($request); } }

-----------------------------------------------

6. Mendaftarkan Middleware ke Kernel

Untuk menggunakan middleware ini, daftarkan ini ke Kernel. Buka aplikasi\Http\Kernel.php

protected $routeMiddleware = [ ... 'jwt.verify' => \App\Http\Middleware\JwtMiddleware::class, 'jwt.auth' => 'Tymon\JWTAuth\Middleware\GetUserFromToken', 'jwt.refresh' => 'Tymon\JWTAuth\Middleware\RefreshToken', ];

Middleware ini akan memverifikasi bahwa pengguna diautentikasi dengan memeriksa token yang dikirim di header permintaan dan Ini akan membuat file middleware baru di direktori Middleware Anda.
Jika pengguna tidak mengautentikasi middleware, lempar pengecualian UnauthorizedHttpException.

7. Create API Route

<?php use Illuminate\Http\Request; use Illuminate\Support\Facades\Route; use App\Http\Controllers\ApiController; use App\Http\Controllers\ProductController; Route::post('login', [ApiController::class, 'authenticate']); Route::post('register', [ApiController::class, 'register']); Route::group(['middleware' => ['jwt.verify']], function() { Route::get('logout', [ApiController::class, 'logout']); });

8. Create Login untuk generate Token JWT

public function authenticate(Request $request) { $credentials = $request->only('email', 'password'); //valid credential $validator = Validator::make($credentials, [ 'email' => 'required|email', 'password' => 'required|string|min:6|max:50' ]); //Send failed response if request is not valid if ($validator->fails()) { return response()->json(['error' => $validator->messages()], 200); } //Request is validated //Crean token try { if (! $token = JWTAuth::attempt($credentials)) { return response()->json([ 'success' => false, 'message' => 'Login credentials are invalid.', ], 400); } } catch (JWTException $e) { return $credentials; return response()->json([ 'success' => false, 'message' => 'Could not create token.', ], 500); } //Token created, return with success response and jwt token return response()->json([ 'success' => true, 'token' => $token, ]); }


9. Hasil Testing










Share:

#4 Install mysql di server nginx Ubuntu

 Setelah sukses install Nginx pada server ubuntu, selanjutnya akan kita install MySql untuk databasenya

1. Install MySql

  sudo apt install mysql-server
Enter Y untuk konfirmasi.

2. Setup Validate Password Plugin

  sudo mysql_secure_installation
Enter Y sampai dengan selesai.

3. Tes Uji MySql

  sudo mysql
OutputWelcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 8.0.19-0ubuntu5 (Ubuntu)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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> 
Share:

#3 Install & Konfigurasi PHP di Nginx Ubuntu

Instalasi PHPMyadmin pada server nginx Ubuntu

1. Perbarui perangkat lunak

  sudo apt-get update && sudo apt-get upgrade -y

2. Install PHP

 apt install php8.2 php8.2-fpm

3. Check list

 ls /var/var/run/php/php     



4. Setting Block untuk akses PHP

 vim /etc/nginx/site-available

index.html

 server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;
        index index.php index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                try_files $uri $uri/ =404;
        }

        # pass PHP scripts to FastCGI server
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php8.2-fpm.sock;
        }
 }

Simpan dan keluar

Restart / Reload server

 sudo systemctl reload nginx

5. Buat file index.php

Buat file index.php pada folder domain anda untuk test apakah ekstensi php berjalan dengan normal
<?php
phpinfo();
?>

6. Uji coba file index.php 


Selanjutnya : 

Share:

#2 Membuat block Server Nginx Ubuntu

Buat direktori untuk domain_Anda sebagai berikut, gunakan flag -p untuk membuat direktori induk yang diperlukan:

 1. Buat Domain Website

 sudo mkdir -p /var/www/your_domain/html

2. Buat Kepemilikan Domain kepada User

 sudo chown -R $USER:$USER /var/www/your_domain/html                   

3. Buat Permissions Folder

 sudo chmod -R 755 /var/www/your_domain          

4. Buat Contoh File index.html

 sudo nano /var/www/your_domain/html/index.html    

index.html

<html>
    <head>
        <title>Welcome to your_domain!</title>
    </head>
    <body>
        <h1>Success!  The your_domain server block is working!</h1>
    </body>
</html>

5. Setting Server Block

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

Buat configurasi block seperti ini : 

server {
        listen 80;
        listen [::]:80;

        root /var/www/your_domain/html;
        index index.html index.htm index.nginx-debian.html;

        server_name your_domain www.your_domain;

        location / {
                try_files $uri $uri/ =404;
        }
}

ubah your_domain sesuai dengan domain yang sudah anda buat sebelumnya

Selanjutnya, aktifkan file dengan membuat tautan darinya ke direktori yang mengaktifkan situs, yang dibaca Nginx selama startup:

 sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/

Untuk menghindari kemungkinan masalah memori keranjang hash yang dapat timbul dari penambahan nama server tambahan, perlu untuk menyesuaikan satu nilai di file /etc/nginx/nginx.conf. 

Buka file:

 sudo nano /etc/nginx/nginx.conf
...
http {
    ...
    server_names_hash_bucket_size 64;
    ...
}
...

Selanjutnya, uji untuk memastikan tidak ada kesalahan sintaks di salah satu file Nginx Anda :

 sudo nginx -t
 sudo systemctl restart nginx


Selanjutnya : 

Install PHP dan setting di Nginx Ubuntu

Share:

#1 Install Nginx, php, phpmyadmin - Ubuntu 22.04.1 LTS (GNU/Linux 5.15.0-52-generic x86_64)

 1. Install Nginx Ubuntu

 sudo apt update  
 sudo apt install nginx  

2. Adjusting the Firewall 

 sudo ufw app list                    
Output
Available applications: Nginx Full Nginx HTTP Nginx HTTPS OpenSSH

keterangan : 

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

Nginx HTTP : This profile opens only port 80 (normal, unencrypted web traffic)

Nginx HTTPS : This profile opens only port 443 (TLS/SSL encrypted traffic)

Anda dapat mengaktifkan ini dengan mengetik:

 sudo ufw allow 'Nginx HTTP'         

Anda dapat memverifikasi perubahan dengan mengetik:

 sudo ufw status       
Output
Status: active To Action From -- ------ ---- OpenSSH ALLOW Anywhere Nginx HTTP ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6) Nginx HTTP (v6) ALLOW Anywhere (v6)

3. Check Web Server

  systemctl status nginx
Output
● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2020-04-20 16:08:19 UTC; 3 days ago Docs: man:nginx(8) Main PID: 2369 (nginx) Tasks: 2 (limit: 1153) Memory: 3.5M CGroup: /system.slice/nginx.service ├─2369 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; └─2380 nginx: worker process

Cek web server di Address Bar

http://your-server-ip


4. Managing The Nginx Process

a. Stop Server
  sudo systemctl stop nginx
b. Start Server
  sudo systemctl start nginx
c. Reload Server
  sudo systemctl reload nginx
d. Disable Server
  sudo systemctl disable nginx
e. Enable Server
  sudo systemctl enable nginx


Selanjutnya : 

Membuat Block Server - Ubuntu

Share:

Tonton video



Yuk, SUBSCRIBE

omfiki.blogspot.com