Instalasi pgAdmin

Muhammad Fajri
Sunday, 18 June 2023

Bismillahirrahmanirrahim.

Dalam melakukan manajemen basis data, akan mudah dilakukan melalui GUI. Untuk itu, diperlukan sebuah tool agar pengelolaan basis data yang akan lebih nyaman dibandingkan menggunakan perintah-perintah SQL melalui CLI.

Dalam proses kali ini akan dilakukan instalasi pgAdmin sebagai tool administrasi PostgreSQL berbasis web. pgAdmin merupakan platform pengembangan dan administrasi Open Source yang paling populer dan kaya fitur Open Source untuk PostgreSQL, basis data Open Source terdepan di dunia. pgAdmin dapat digunakan di Linux, Unix, macOS dan Windows untuk mengelola PostgreSQL dan EDB Advanced Server 10 ke atas.

Instalasi Prasyarat dan Unduh File pgAdmin

Tools yang diperlukan:

Instalasi NodeJS dan Yarn

  1. Unduh file melalui web NodeJS.
  2. Unzip arsip biner ke direktori yang diinginkan untuk menginstal Node, misal di /usr/local/lib/nodejs:
     VERSION=v18.16.0
     DISTRO=linux-x64
     sudo mkdir -p /usr/local/lib/nodejs
     sudo tar -xJvf node-$VERSION-$DISTRO.tar.xz -C /usr/local/lib/nodejs
    
  3. Set variabel env ~/.bashrc, tambahkan baris berikut di bagian akhir:
    # Nodejs
    VERSION=v10.15.0
    DISTRO=linux-x64
    export PATH=/usr/local/lib/nodejs/node-$VERSION-$DISTRO/bin:$PATH
    
  4. Refresh bashrc
    source ~/.bashrc
    
  5. Tes instalasi, node -v, npm version, dan npx -v:
    fajri@fajri-PC:~$ node -v
    v18.16.0
    fajri@fajri-PC:~$ npm version
    {
      npm: '9.5.1',
      node: '18.16.0',
      acorn: '8.8.2',
      ada: '1.0.4',
      ares: '1.19.0',
      brotli: '1.0.9',
      cldr: '42.0',
      icu: '72.1',
      llhttp: '6.0.10',
      modules: '108',
      napi: '8',
      nghttp2: '1.52.0',
      nghttp3: '0.7.0',
      ngtcp2: '0.8.1',
      openssl: '3.0.8+quic',
      simdutf: '3.2.2',
      tz: '2022g',
      undici: '5.21.0',
      unicode: '15.0',
      uv: '1.44.2',
      uvwasi: '0.0.15',
      v8: '10.2.154.26-node.26',
      zlib: '1.2.13'
    }
    fajri@fajri-PC:~$ npx -v
    9.5.1
    fajri@fajri-PC:~$
    
  6. Instal Yarn dengan package manager npm (sudah terinstal sebagai bundle Node.js).
    npm install --global yarn
    

    Cek instalasi Yarn:

    yarn --version
    // output
    1.22.19
    

Setelah semua tools terinstal, tentukan direktori untuk menyimpan file pgAdmin4 misalnya di direktori /opt/ lalu jalankan perintah:

git clone https://github.com/pgadmin-org/pgadmin4.git

Output:

Cloning into 'pgadmin4'...
remote: Enumerating objects: 130976, done.
remote: Counting objects: 100% (9299/9299), done.
remote: Compressing objects: 100% (699/699), done.
remote: Total 130976 (delta 8719), reused 8851 (delta 8556), pack-reused 121677
Receiving objects: 100% (130976/130976), 250.82 MiB | 780.00 KiB/s, done.
Resolving deltas: 100% (85327/85327), done.
fajri@fajri-PC:~$ 

Instal Paket-paket Python

Backend pgAdmin dibangun dengan bahasa Python dan agar dapat berjalan harus menginstal persyaratan yang dibutuhkan Python.

  1. Memastikan direktori bin PostgreSQL berada pada variabel environment PATH. Ini penting karena package psycopg bergantung pada binary PostgreSQL untuk proses instalasi. Pada file ~/.bashrc tambahkan baris berikut di bagian akhir:
    ...
    # PostgreSQL
    PATH=/usr/lib/postgresql/11/bin:$PATH
    export PATH
    

    Lalu, refresh bashrc:

    source ~/.bashrc
    
  2. Buat direktori virtual environment Python, misal pada direktori /opt/ (harus menyertakan sudo):
    sudo python3 -m venv /opt/myenv
    

Error saat menjalankan perintah di atas:

The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.

    apt-get install python3-venv

You may need to use sudo with that command.  After installing the python3-venv
package, recreate your virtual environment.

Failing command: ['/opt/myenv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']

Jalankan instalasi python3-venv:

sudo apt-get install python3-venv

Jalankan ulang pembuatan virtual environment, dan ubah kepemilikan folder myenv ke user yang sedang aktif:

sudo chown -R fajri:fajri myenv/
  1. Aktivasi virtual environment:
    source /opt/myenv/bin/activate
    
pip install --upgrade pip

Output:

Collecting pip
  Downloading https://files.pythonhosted.org/packages/08/e3/57d4c24a050aa0bcca46b2920bff40847db79535dc78141eb83581a52eb8/pip-23.1.2-py3-none-any.whl (2.1MB)
    100% |████████████████████████████████| 2.1MB 441kB/s 
Installing collected packages: pip
  Found existing installation: pip 18.1
    Uninstalling pip-18.1:
      Successfully uninstalled pip-18.1
Successfully installed pip-23.1.2
  1. Pada terminal yang sama, pindah ke direktori pgAdmin4, lalu jalankan perintah pip install -r requirements.txt:
    (myenv) fajri@fajri-PC:~$ cd /opt/pgadmin4/
    (myenv) fajri@fajri-PC:/opt/pgadmin4$ pip install -r requirements.txt
    

Output:

Ignoring pywinpty: markers 'sys_platform == "win32"' don't match your environment
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/flask/
Collecting Flask==2.2.* (from -r requirements.txt (line 11))                              
  Using cached Flask-2.2.5-py3-none-any.whl (101 kB)
Collecting Flask-Gravatar==0.* (from -r requirements.txt (line 12))
  Using cached Flask_Gravatar-0.5.0-py2.py3-none-any.whl (7.5 kB)
Collecting Flask-Login==0.* (from -r requirements.txt (line 13))
  Using cached Flask_Login-0.6.2-py3-none-any.whl (17 kB)
Collecting Flask-Mail==0.* (from -r requirements.txt (line 14))
  Using cached Flask-Mail-0.9.1.tar.gz (45 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting Flask-Migrate==4.* (from -r requirements.txt (line 15))
  Using cached Flask_Migrate-4.0.4-py3-none-any.whl (20 kB)
Collecting greenlet==1.1.2 (from -r requirements.txt (line 16))
  Downloading greenlet-1.1.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (150 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 150.2/150.2 kB 635.3 kB/s eta 0:00:00
Collecting Flask-SQLAlchemy==3.0.* (from -r requirements.txt (line 17))
  Using cached Flask_SQLAlchemy-3.0.3-py3-none-any.whl (24 kB)
Collecting Flask-WTF==1.1.1 (from -r requirements.txt (line 18))
  Using cached Flask_WTF-1.1.1-py3-none-any.whl (12 kB)
Collecting Flask-Compress==1.* (from -r requirements.txt (line 19))
  Using cached Flask_Compress-1.13-py3-none-any.whl (7.9 kB)
Collecting Flask-Paranoid==0.* (from -r requirements.txt (line 20))
  Using cached Flask_Paranoid-0.3.0-py3-none-any.whl (4.5 kB)
Collecting Flask-Babel==3.1.* (from -r requirements.txt (line 21))
  Using cached flask_babel-3.1.0-py3-none-any.whl (9.6 kB)
Collecting Flask-Security-Too==5.1.* (from -r requirements.txt (line 22))
  Using cached Flask_Security_Too-5.1.2-py2.py3-none-any.whl (369 kB)
Collecting Flask-SocketIO==5.3.* (from -r requirements.txt (line 23))
  Using cached Flask_SocketIO-5.3.4-py3-none-any.whl (17 kB)
Collecting WTForms==3.0.* (from -r requirements.txt (line 24))
  Using cached WTForms-3.0.1-py3-none-any.whl (136 kB)
Collecting passlib==1.* (from -r requirements.txt (line 25))
  Using cached passlib-1.7.4-py2.py3-none-any.whl (525 kB)
Collecting pytz==2023.* (from -r requirements.txt (line 26))
  Using cached pytz-2023.3-py2.py3-none-any.whl (502 kB)
Collecting speaklater3==1.* (from -r requirements.txt (line 27))
  Using cached speaklater3-1.4-py3-none-any.whl (5.9 kB)
Collecting sqlparse==0.* (from -r requirements.txt (line 28))
  Using cached sqlparse-0.4.4-py3-none-any.whl (41 kB)
Collecting psutil==5.9.* (from -r requirements.txt (line 29))
  Downloading psutil-5.9.5-cp36-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (282 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 282.1/282.1 kB 640.4 kB/s eta 0:00:00
Collecting psycopg[c]==3.1.8 (from -r requirements.txt (line 30))
  Using cached psycopg-3.1.8-py3-none-any.whl (167 kB)
Collecting python-dateutil==2.* (from -r requirements.txt (line 31))
  Using cached python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
Collecting SQLAlchemy==2.* (from -r requirements.txt (line 32))
  Downloading SQLAlchemy-2.0.16-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.7/2.7 MB 1.2 MB/s eta 0:00:00
Collecting bcrypt==4.0.* (from -r requirements.txt (line 33))
  Downloading bcrypt-4.0.1-cp36-abi3-manylinux_2_28_x86_64.whl (593 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 593.7/593.7 kB 1.1 MB/s eta 0:00:00
Collecting cryptography==40.0.* (from -r requirements.txt (line 34))
  Downloading cryptography-40.0.2-cp36-abi3-manylinux_2_28_x86_64.whl (3.7 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.7/3.7 MB 1.5 MB/s eta 0:00:00
Collecting sshtunnel==0.* (from -r requirements.txt (line 35))
  Downloading sshtunnel-0.4.0-py2.py3-none-any.whl (24 kB)
Collecting ldap3==2.* (from -r requirements.txt (line 36))
  Downloading ldap3-2.9.1-py2.py3-none-any.whl (432 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 432.2/432.2 kB 227.6 kB/s eta 0:00:00
Collecting gssapi==1.8.* (from -r requirements.txt (line 37))
  Downloading gssapi-1.8.2.tar.gz (94 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 94.3/94.3 kB 108.5 kB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error
  
  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [21 lines of output]
      /bin/sh: 1: krb5-config: not found
      Traceback (most recent call last):
        File "/opt/myenv/lib/python3.7/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/opt/myenv/lib/python3.7/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/opt/myenv/lib/python3.7/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
        File "/tmp/pip-build-env-52xt6hdz/overlay/lib/python3.7/site-packages/setuptools/build_meta.py", line 341, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
        File "/tmp/pip-build-env-52xt6hdz/overlay/lib/python3.7/site-packages/setuptools/build_meta.py", line 323, in _get_build_requires
          self.run_setup()
        File "/tmp/pip-build-env-52xt6hdz/overlay/lib/python3.7/site-packages/setuptools/build_meta.py", line 338, in run_setup
          exec(code, locals())
        File "<string>", line 109, in <module>
        File "<string>", line 22, in get_output
        File "/usr/lib/python3.7/subprocess.py", line 395, in check_output
          **kwargs).stdout
        File "/usr/lib/python3.7/subprocess.py", line 487, in run
          output=stdout, stderr=stderr)
      subprocess.CalledProcessError: Command 'krb5-config --libs gssapi' returned non-zero exit status 127.
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.
(myenv) fajri@fajri-PC:/opt/pgadmin4$ 

Jika terdapat error:

setuptools-rust>=0.11.4" failed with error code 1 in None

jalankan perintah:

pip3 install --upgrade setuptools

Output:

Collecting setuptools
  Using cached https://files.pythonhosted.org/packages/f5/2c/074ab1c5be9c7d523d8d6d69d1f46f450fe7f11713147dc9e779aa4ca4ea/setuptools-67.8.0-py3-none-any.whl
Installing collected packages: setuptools
  Found existing installation: setuptools 40.8.0
    Uninstalling setuptools-40.8.0:
      Successfully uninstalled setuptools-40.8.0
Successfully installed setuptools-67.8.0

Lalu jalankan kembali perintah pip install -r requirements.txt.

  1. Setelah terinstal dengan baik, server backend pgAdmin sudah siap.

STOP YANG BAGIAN INI

Mengedit file config pgAdmin

  1. Buka dan edit file /opt/pgAdmin4/web/config_local.py:
    ...
    

STOP YANG BAGIAN INI

Instal Paket-paket Javascript dan bundle

pgAdmin merupakan aplikasi web dan UI frontend-nya dibangun secara penuh dengan JavaScript. Paket-paket JavaScript perlu untuk diinstal seperti yang ada pada file package.json.

  1. Pindah ke direktori web pgAdmin4 (/opt/pgAdmin4/web).
  2. Jalankan perintah:
    yarn install
    

    Output:

    yarn install v1.22.19
    [1/4] Resolving packages...
    warning @material-ui/core@4.12.4: Material UI v4 doesn't receive active development since September 2021. See the guide https://mui.com/material-ui/migration/migration-v4/ to upgrade to v5.
    warning @material-ui/core > @material-ui/styles@4.11.5: Material UI v4 doesn't receive active development since September 2021. See the guide https://mui.com/material-ui/migration/migration-v4/ to upgrade to v5.
    warning @material-ui/lab@4.0.0-alpha.61: Material UI v4 doesn't receive active development since September 2021. See the guide https://mui.com/material-ui/migration/migration-v4/ to upgrade to v5.
    warning @material-ui/pickers@3.3.10: Material UI Pickers v3 doesn't receive active development since January 2020. See the guide https://mui.com/material-ui/guides/pickers-migration/ to upgrade.
    warning @types/classnames@2.3.1: This is a stub types definition. classnames provides its own type definitions, so you do not need this installed.
    warning cssnano > cssnano-preset-default > postcss-svgo > svgo > stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
    warning popper.js@1.16.1: You can find the new Popper v2 at @popperjs/core, this package is dedicated to the legacy v1
    info There appears to be trouble with your network connection. Retrying...
    info There appears to be trouble with your network connection. Retrying...
    warning imagemin-mozjpeg > mozjpeg > bin-build > tempfile > uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
    warning istanbul-instrumenter-loader > istanbul-lib-instrument > babel-template > babel-runtime > core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
    [2/4] Fetching packages...
    info There appears to be trouble with your network connection. Retrying...
    [3/4] Linking dependencies...
    warning "@projectstorm/react-diagrams > @projectstorm/react-diagrams-core@6.7.4" has incorrect peer dependency "react@18.*".
    warning "@projectstorm/react-diagrams > @projectstorm/react-diagrams-routing@6.7.4" has incorrect peer dependency "react@18.*".
    warning "@projectstorm/react-diagrams > @projectstorm/react-diagrams-defaults@6.7.4" has incorrect peer dependency "react@18.*".
    warning " > aspen-decorations@1.1.1" has unmet peer dependency "aspen-core@^1.0.4".
    warning " > react-aspen@1.2.0" has incorrect peer dependency "react@^16.0.0".
    warning " > react-aspen@1.2.0" has incorrect peer dependency "react-dom@^16.0.0".
    warning " > snapsvg-cjs@0.0.6" has unmet peer dependency "eve@~0.5.1".
    warning " > styled-components@5.3.11" has unmet peer dependency "react-is@>= 16.8.0".
    warning " > istanbul-instrumenter-loader@3.0.1" has incorrect peer dependency "webpack@^2.0.0 || ^3.0.0 || ^4.0.0".
    warning " > karma-browserify@8.1.0" has unmet peer dependency "watchify@>=3 <5".
    warning " > karma-requirejs@1.1.0" has unmet peer dependency "requirejs@^2.1.0".
    warning " > svgo-loader@2.2.2" has incorrect peer dependency "svgo@^1.0.0".
    [4/4] Building fresh packages...
    success Saved lockfile.
    Done in 1235.02s.
    
  3. Compile dan bundle file pgAdmin JS menggunakan perintah:
    yarn run webpacker
    

Output:

yarn run v1.22.19
$ yarn run webpack --config webpack.config.js --progress
$ /opt/pgadmin4/web/node_modules/.bin/webpack --config webpack.config.js --progress
assets by chunk 2.83 MiB (auxiliary name: style) 20 assets
assets by path *.js 35.3 MiB
  asset vendor.others.js 15.3 MiB [emitted] (name: vendor_others) (id hint: vendor_others)
  + 13 assets
assets by chunk 691 KiB (auxiliary name: pgadmin.style)
  asset fonts/SourceCodePro-Regular..ttf 188 KiB [emitted] [from: pgadmin/static/fonts/SourceCodePro-Regular.ttf] (auxiliary name: pgadmin.style)
  + 3 assets
assets by path *.css 670 KiB
  asset pgadmin.css 328 KiB [emitted] (name: pgadmin) 1 related asset
  + 2 assets
assets by path img/*.png 84.3 KiB
  asset img/dark_preview.png 37.1 KiB [emitted] [from: pgadmin/static/scss/resources/dark/dark_preview.png] [copied]
  + 2 assets
asset pgadmin.themes.json 304 bytes [emitted] [from: pgadmin/misc/themes/pgadmin.themes.json] [copied]
chunk (runtime: app.bundle) app.bundle.js (app.bundle) 4.7 MiB (javascript) 4.77 KiB (runtime) [entry] [rendered]
  dependent modules 3.98 MiB [dependent] 315 modules
  runtime modules 4.77 KiB 10 modules
  cacheable modules 737 KiB
    modules by path ./pgadmin/browser/server_groups/servers/databases/ 626 KiB 40 modules
    modules by path ./pgadmin/browser/server_groups/servers/roles/static/js/*.js 31.2 KiB 2 modules
    modules by path ./pgadmin/browser/server_groups/servers/static/js/*.js 37.6 KiB 2 modules
    modules by path ./pgadmin/browser/static/js/ 14.9 KiB 2 modules
    + 5 modules
chunk (runtime: app.bundle, sqleditor) browser_nodes.js (browser_nodes) (id hint: browser_nodes) 321 KiB [initial] [rendered] split chunk (cache group: browser_nodes) (name: browser_nodes)                                                                                  
  dependent modules 45.8 KiB [dependent] 10 modules
  modules by path ./pgadmin/browser/server_groups/servers/databases/ 227 KiB
    modules by path ./pgadmin/browser/server_groups/servers/databases/schemas/ 167 KiB 32 modules
    modules by path ./pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/ 11.7 KiB 3 modules
    + 7 modules
  ./pgadmin/browser/server_groups/servers/resource_groups/static/js/res...(truncated) 3.6 KiB [built] [code generated]
  ./pgadmin/browser/server_groups/servers/roles/static/js/role.js 5.51 KiB [built] [code generated]                                                                                 
  ./pgadmin/browser/server_groups/servers/static/js/server.js 33 KiB [built] [code generated]                                                                                       
  ./pgadmin/browser/server_groups/servers/tablespaces/static/js/tablespace.js 4.04 KiB [built] [code generated]                                                                     
  ./pgadmin/browser/server_groups/static/js/server_group.js 2.23 KiB [built] [code generated]                                                                                       
chunk (runtime: codemirror) codemirror.js (codemirror) 8.91 KiB (javascript) 4.74 KiB (runtime) [entry] [rendered]
  runtime modules 4.74 KiB 9 modules
  dependent modules 6.54 KiB [dependent] 2 modules
  ./pgadmin/static/bundle/codemirror.js 2.37 KiB [built] [code generated]
chunk (runtime: debugger) debugger.js (debugger) 1.83 MiB (javascript) 4.77 KiB (runtime) [entry] [rendered]                                                                        
  dependent modules 1.82 MiB [dependent] 158 modules
  runtime modules 4.77 KiB 10 modules
  cacheable modules 15.7 KiB
    modules by path ./pgadmin/browser/static/js/ 14.9 KiB
      ./pgadmin/browser/static/js/node_view.jsx 9.03 KiB [built] [code generated]
      ./pgadmin/browser/static/js/panel_view.jsx 5.84 KiB [built] [code generated]
    ./pgadmin/tools/debugger/static/js/index.js 869 bytes [built] [code generated]
    fs (ignored) 15 bytes [built] [code generated]
chunk (runtime: erd_tool) erd_tool.js (erd_tool) 2.16 MiB (javascript) 4.77 KiB (runtime) [entry] [rendered]                                                                        
  dependent modules 2.15 MiB [dependent] 181 modules
  runtime modules 4.77 KiB 10 modules
  cacheable modules 15.8 KiB
    modules by path ./pgadmin/browser/ 14.9 KiB
      ./pgadmin/browser/static/js/node_view.jsx 9.03 KiB [built] [code generated]
      ./pgadmin/browser/static/js/panel_view.jsx 5.84 KiB [built] [code generated]
    ./pgadmin/tools/erd/static/js/index.js 886 bytes [built] [code generated]
    fs (ignored) 15 bytes [built] [code generated]
chunk (runtime: pgadmin) pgadmin.css, pgadmin.js (pgadmin) 550 bytes (javascript) 317 KiB (css/mini-extract) 274 bytes (runtime) [entry] [rendered]
  dependent modules 317 KiB [dependent] 13 modules
  runtime modules 274 bytes 1 module
  cacheable modules 550 bytes
    modules by path ./pgadmin/browser/ 200 bytes 4 modules
    modules by path ./pgadmin/tools/ 150 bytes 3 modules
    modules by path ./pgadmin/static/ 100 bytes
      ./pgadmin/static/js/components/PgTree/scss/styles.scss 50 bytes [built] [code generated]                                                                                      
      ./pgadmin/static/scss/pgadmin.scss 50 bytes [built] [code generated]
    ./pgadmin/dashboard/static/scss/_dashboard.scss 50 bytes [built] [code generated]
    ./pgadmin/preferences/static/scss/_preferences.scss 50 bytes [built] [code generated]
chunk (runtime: pgadmin.style) pgadmin.style.css, pgadmin.style.js (pgadmin.style) 700 bytes (javascript) 156 KiB (css/mini-extract) 274 bytes (runtime) [entry] [rendered]
  dependent modules 156 KiB [dependent] 14 modules
  runtime modules 274 bytes 1 module
  cacheable modules 700 bytes
    modules by path ./pgadmin/browser/ 400 bytes
      modules by path ./pgadmin/browser/server_groups/servers/ 300 bytes 6 modules
      modules by path ./pgadmin/browser/static/css/*.css 100 bytes 2 modules
    modules by path ./pgadmin/static/ 100 bytes
      ./pgadmin/static/css/pgadmin.css 50 bytes [built] [code generated]
      ./pgadmin/static/js/pgadmin.fonticon.js 50 bytes [built] [code generated]
    + 4 modules
chunk (runtime: app.bundle, debugger, erd_tool, psql_tool, schema_diff, sqleditor) pgadmin_commons.js (pgadmin_commons) (id hint: secondary) 65.4 KiB [initial] [rendered] split chunk (cache group: secondary) (name: pgadmin_commons)                                       
  dependent modules 47.1 KiB [dependent] 2 modules
  cacheable modules 18.3 KiB
    ./pgadmin/browser/static/js/collection.js 5 KiB [built] [code generated]
    ./pgadmin/browser/static/js/frame.js 4.67 KiB [built] [code generated]
    ./pgadmin/browser/static/js/panel.js 8.67 KiB [built] [code generated]
chunk (runtime: psql_tool) psql_tool.js (psql_tool) 1.64 MiB (javascript) 4.77 KiB (runtime) [entry] [rendered]
  dependent modules 1.63 MiB [dependent] 147 modules
  runtime modules 4.77 KiB 10 modules
  cacheable modules 17.9 KiB
    modules by path ./pgadmin/browser/static/js/ 14.9 KiB
      ./pgadmin/browser/static/js/node_view.jsx 9.03 KiB [built] [code generated]
      ./pgadmin/browser/static/js/panel_view.jsx 5.84 KiB [built] [code generated]
    ./pgadmin/tools/psql/static/js/index.js 2.99 KiB [built] [code generated]
    fs (ignored) 15 bytes [built] [code generated]
chunk (runtime: schema_diff) schema_diff.js (schema_diff) 1.77 MiB (javascript) 4.77 KiB (runtime) [entry] [rendered]
  dependent modules 1.76 MiB [dependent] 154 modules
  runtime modules 4.77 KiB 10 modules
  cacheable modules 15.7 KiB
    modules by path ./pgadmin/browser/static/js/ 14.9 KiB
      ./pgadmin/browser/static/js/node_view.jsx 9.03 KiB [built] [code generated]
      ./pgadmin/browser/static/js/panel_view.jsx 5.84 KiB [built] [code generated]
    ./pgadmin/tools/schema_diff/static/js/index.js 881 bytes [built] [code generated]
    fs (ignored) 15 bytes [built] [code generated]
chunk (runtime: sqleditor) sqleditor.js (sqleditor) 3.34 MiB (javascript) 4.77 KiB (runtime) [entry] [rendered]
  dependent modules 2.62 MiB [dependent] 195 modules
  runtime modules 4.77 KiB 10 modules
  cacheable modules 738 KiB
    modules by path ./pgadmin/browser/server_groups/servers/databases/ 626 KiB 40 modules
    modules by path ./pgadmin/browser/server_groups/servers/roles/static/js/*.js 31.2 KiB 2 modules
    modules by path ./pgadmin/browser/server_groups/servers/static/js/*.js 37.6 KiB 2 modules
    modules by path ./pgadmin/browser/static/js/ 14.9 KiB 2 modules
    + 5 modules
chunk (runtime: style) style.css, style.js (style) 50 bytes (javascript) 175 KiB (css/mini-extract) 274 bytes (runtime) [entry] [rendered]
  dependent modules 175 KiB [dependent] 13 modules
  runtime modules 274 bytes 1 module
  ./pgadmin/static/css/style.css 50 bytes [built] [code generated]
chunk (runtime: app.bundle, debugger, erd_tool, psql_tool, schema_diff, sqleditor) vendor.main.js (vendor_main) (id hint: vendor_main) 894 KiB [initial] [rendered] split chunk (cache group: vendor_main) (name: vendor_main)                                                
  dependent modules 365 KiB [dependent] 2 modules
  cacheable modules 529 KiB
    ./node_modules/bootstrap/dist/js/bootstrap.js 134 KiB [built] [code generated]
    ./node_modules/jquery-contextmenu/dist/jquery.contextMenu.js 91.4 KiB [built] [code generated]                                                                                  
    ./node_modules/webcabin-docker/Build/wcDocker.min.js 303 KiB [built] [code generated]
chunk (runtime: app.bundle, codemirror, debugger, erd_tool, psql_tool, schema_diff, sqleditor) vendor.others.js (vendor_others) (id hint: vendor_others) 12.1 MiB [initial] [rendered] split chunk (cache group: vendor_others) (name: vendor_others)                         
  dependent modules 8.24 MiB [dependent] 2016 modules
  cacheable modules 3.85 MiB
    modules by path ./node_modules/@material-ui/ 98.9 KiB 101 modules
    modules by path ./node_modules/core-js/ 92.7 KiB 101 modules
    modules by path ./node_modules/codemirror/addon/ 82 KiB 11 modules
    modules by path ./node_modules/react-select/ 3.32 KiB
      ./node_modules/react-select/creatable/dist/react-select-creatable.esm.js 1.44 KiB [built] [code generated]                                                                    
      ./node_modules/react-select/dist/react-select.esm.js 1.88 KiB [built] [code generated]                                                                                        
    + 40 modules
2023-06-18 15:11:41: webpack 5.87.0 compiled successfully in 34009 ms

asset pgadmin.theme.dark.css 226 KiB [emitted] [minimized] (name: pgadmin.theme.dark)
asset pgadmin.theme.dark.js 8.62 KiB [emitted] (name: pgadmin.theme.dark)
Entrypoint pgadmin.theme.dark 234 KiB = pgadmin.theme.dark.css 226 KiB pgadmin.theme.dark.js 8.62 KiB                                                                               
runtime modules 10.3 KiB 45 modules
orphan modules 1.02 MiB [orphan] 15 modules
cacheable modules 550 bytes (javascript) 317 KiB (css/mini-extract)
  modules by path ./pgadmin/ 550 bytes (javascript) 299 KiB (css/mini-extract)
    javascript modules 550 bytes 11 modules
    css modules 299 KiB
      modules by path ./pgadmin/browser/ 18.3 KiB 4 modules
      modules by path ./pgadmin/tools/ 11.4 KiB 3 modules
      modules by path ./pgadmin/static/ 262 KiB 2 modules
      + 2 modules
  modules by path ./node_modules/ 17.9 KiB
    css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[3].use[1]!./node_modules/rc-dock/dist/rc-dock.css 15 KiB [built] [code generated]
    css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[3].use[1]!./node_modules/@szhsin/react-menu/dist/index.css 2.91 KiB [built] [code generated]
webpack 5.87.0 compiled successfully in 22076 ms

asset pgadmin.theme.high_contrast.css 225 KiB [emitted] [minimized] (name: pgadmin.theme.high_contrast)
asset pgadmin.theme.high_contrast.js 8.62 KiB [emitted] (name: pgadmin.theme.high_contrast)
Entrypoint pgadmin.theme.high_contrast 234 KiB = pgadmin.theme.high_contrast.css 225 KiB pgadmin.theme.high_contrast.js 8.62 KiB                                                    
runtime modules 10.3 KiB 45 modules
orphan modules 1.04 MiB [orphan] 15 modules
cacheable modules 550 bytes (javascript) 317 KiB (css/mini-extract)
  modules by path ./pgadmin/ 550 bytes (javascript) 299 KiB (css/mini-extract)
    javascript modules 550 bytes 11 modules
    css modules 299 KiB
      modules by path ./pgadmin/browser/ 18.3 KiB 4 modules
      modules by path ./pgadmin/tools/ 11.4 KiB 3 modules
      modules by path ./pgadmin/static/ 262 KiB 2 modules
      + 2 modules
  modules by path ./node_modules/ 17.9 KiB
    css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[3].use[1]!./node_modules/rc-dock/dist/rc-dock.css 15 KiB [built] [code generated]
    css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[3].use[1]!./node_modules/@szhsin/react-menu/dist/index.css 2.91 KiB [built] [code generated]
webpack 5.87.0 compiled successfully in 22071 ms
Done in 35.07s.
  1. Perintah di atas hanya meng-compile sekali. Ketika bekerja dengan frontend pgAdmin, JS perlu untuk meng-compile terus-menerus. Untuk itu, jalankan webpacker dalam mode watch:
    yarn run webpacker --watch
    
  2. Untuk mem-bundle file untuk produksi, gunakan perintah:
    yarn run bundle
    

Memulai Aplikasi pgAdmin

Sekarang, pengaturan backend dan frontend sudah siap. Aplikasi pgAdmin dapat dijalankan sekarang.

  1. Buka terminal di mana virtual environment pgAdmin python aktif.
  2. Pindah ke direktori /opt/pgAdmin4/web.
  3. Jalankan perintah python3 pgAdmin4.py:
    (myenv) fajri@fajri-PC:/opt/pgadmin4/web$ python3 pgAdmin4.py
    

Terjadi error:

Traceback (most recent call last):
  File "pgAdmin4.py", line 49, in <module>
    import config
  File "/opt/pgadmin4/web/config.py", line 25, in <module>
    from pgadmin.utils import env, IS_WIN, fs_short_path
  File "/opt/pgadmin4/web/pgadmin/__init__.py", line 24, in <module>
    from flask import Flask, abort, request, current_app, session, url_for
ModuleNotFoundError: No module named 'flask'
(myenv) fajri@fajri-PC:/opt/pgadmin4/web$ python3 pgAdmin4.py 
Traceback (most recent call last):
  File "pgAdmin4.py", line 49, in <module>
    import config
  File "/opt/pgadmin4/web/config.py", line 25, in <module>
    from pgadmin.utils import env, IS_WIN, fs_short_path
  File "/opt/pgadmin4/web/pgadmin/__init__.py", line 24, in <module>
    from flask import Flask, abort, request, current_app, session, url_for
ModuleNotFoundError: No module named 'flask'

Instal flask dengan pip:

python3 -m pip install -U Flask
// atau untuk diinstal pada environment tertentu
source /opt/myenv/bin/activate
python3 -m pip install -U Flask

Output:

Collecting Flask
  Using cached Flask-2.2.5-py3-none-any.whl (101 kB)
Collecting Werkzeug>=2.2.2 (from Flask)
  Downloading Werkzeug-2.2.3-py3-none-any.whl (233 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 233.6/233.6 kB 217.8 kB/s eta 0:00:00
Collecting Jinja2>=3.0 (from Flask)
  Downloading Jinja2-3.1.2-py3-none-any.whl (133 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 133.1/133.1 kB 148.4 kB/s eta 0:00:00
Collecting itsdangerous>=2.0 (from Flask)
  Downloading itsdangerous-2.1.2-py3-none-any.whl (15 kB)
Collecting click>=8.0 (from Flask)
  Downloading click-8.1.3-py3-none-any.whl (96 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 96.6/96.6 kB 485.8 kB/s eta 0:00:00
Collecting importlib-metadata>=3.6.0 (from Flask)
  Downloading importlib_metadata-6.6.0-py3-none-any.whl (22 kB)
Collecting zipp>=0.5 (from importlib-metadata>=3.6.0->Flask)
  Downloading zipp-3.15.0-py3-none-any.whl (6.8 kB)
Collecting typing-extensions>=3.6.4 (from importlib-metadata>=3.6.0->Flask)
  Using cached typing_extensions-4.6.3-py3-none-any.whl (31 kB)
Collecting MarkupSafe>=2.0 (from Jinja2>=3.0->Flask)
  Downloading MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25 kB)
Installing collected packages: zipp, typing-extensions, MarkupSafe, itsdangerous, Werkzeug, Jinja2, importlib-metadata, click, Flask
Successfully installed Flask-2.2.5 Jinja2-3.1.2 MarkupSafe-2.1.3 Werkzeug-2.2.3 click-8.1.3 importlib-metadata-6.6.0 itsdangerous-2.1.2 typing-extensions-4.6.3 zipp-3.15.0

Jalankan ulang kembali python3 pgAdmin4.py.

Terdapat error lagi:

Traceback (most recent call last):
  File "pgAdmin4.py", line 49, in <module>
    import config
  File "/opt/pgadmin4/web/config.py", line 25, in <module>
    from pgadmin.utils import env, IS_WIN, fs_short_path
  File "/opt/pgadmin4/web/pgadmin/__init__.py", line 25, in <module>
    from flask_socketio import SocketIO
ModuleNotFoundError: No module named 'flask_socketio'

Instal paket flask-socketio:

python3 -m pip install -U flask-socketio

Output:

Collecting flask-socketio
  Using cached Flask_SocketIO-5.3.4-py3-none-any.whl (17 kB)
Requirement already satisfied: Flask>=0.9 in /opt/myenv/lib/python3.7/site-packages (from flask-socketio) (2.2.5)
Collecting python-socketio>=5.0.2 (from flask-socketio)
  Downloading python_socketio-5.8.0-py3-none-any.whl (56 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 57.0/57.0 kB 116.2 kB/s eta 0:00:00
Requirement already satisfied: Werkzeug>=2.2.2 in /opt/myenv/lib/python3.7/site-packages (from Flask>=0.9->flask-socketio) (2.2.3)
Requirement already satisfied: Jinja2>=3.0 in /opt/myenv/lib/python3.7/site-packages (from Flask>=0.9->flask-socketio) (3.1.2)
Requirement already satisfied: itsdangerous>=2.0 in /opt/myenv/lib/python3.7/site-packages (from Flask>=0.9->flask-socketio) (2.1.2)
Requirement already satisfied: click>=8.0 in /opt/myenv/lib/python3.7/site-packages (from Flask>=0.9->flask-socketio) (8.1.3)
Requirement already satisfied: importlib-metadata>=3.6.0 in /opt/myenv/lib/python3.7/site-packages (from Flask>=0.9->flask-socketio) (6.6.0)
Collecting bidict>=0.21.0 (from python-socketio>=5.0.2->flask-socketio)
  Downloading bidict-0.22.1-py3-none-any.whl (35 kB)
Collecting python-engineio>=4.3.0 (from python-socketio>=5.0.2->flask-socketio)
  Downloading python_engineio-4.4.1-py3-none-any.whl (53 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 53.4/53.4 kB 212.4 kB/s eta 0:00:00
Requirement already satisfied: zipp>=0.5 in /opt/myenv/lib/python3.7/site-packages (from importlib-metadata>=3.6.0->Flask>=0.9->flask-socketio) (3.15.0)
Requirement already satisfied: typing-extensions>=3.6.4 in /opt/myenv/lib/python3.7/site-packages (from importlib-metadata>=3.6.0->Flask>=0.9->flask-socketio) (4.6.3)
Requirement already satisfied: MarkupSafe>=2.0 in /opt/myenv/lib/python3.7/site-packages (from Jinja2>=3.0->Flask>=0.9->flask-socketio) (2.1.3)
Installing collected packages: python-engineio, bidict, python-socketio, flask-socketio
Successfully installed bidict-0.22.1 flask-socketio-5.3.4 python-engineio-4.4.1 python-socketio-5.8.0

Selanjutnya akan error lagi saat menjalankan ulang perintah python3 pgAdmin4.py. Berturut-turut instal package yang tidak ada:

[1] python3 -m pip install -U flask-babel
[2] python3 -m pip install -U flask-login
[3] python3 -m pip install -U flask-mail
[4] python3 -m pip install -U flask-paranoid
[5] python3 -m pip install -U flask-security
[6] python3 -m pip install -U email-validator
[7] python3 -m pip install -U flask-sqlalchemy
[8] python3 -m pip install -U python-dateutil
[9] python3 -m pip install -U flask-migrate
[10] python3 -m pip install -U keyring
[11] python3 -m pip install -U psycopg
[12] python3 -m pip install -U sshtunnel
[13] python3 -m pip install -U ldap3
[14] python3 -m pip install -U authlib
[14] python3 -m pip install -U requests
[14] python3 -m pip install -U pyotp
[14] python3 -m pip install -U qrcode

Error terakhir yaitu karena masalah permission:

ERROR  : Failed to create the directory /var/lib/pgadmin:
           [Errno 13] Permission denied: '/var/lib/pgadmin'
HINT :   Create the directory /var/lib/pgadmin, ensure it is writeable by
         'fajri', and try again, or, create a config_local.py file
         and override the SQLITE_PATH setting per
         https://www.pgadmin.org/docs/pgadmin4/7.3/config_py.html

Buat folder pgadmin pada direktori /var/lib/:

sudo mkdir /var/lib/pgadmin /var/log/pgadmin
sudo chown -R fajri:fajri /var/lib/pgadmin /var/log/pgadmin
  1. Saat semua paket dan direktori yang dibutuhkan sudah terinstal dan dibuat, maka jalankan perintah python3 pgAdmin4.py:
    (myenv) fajri@fajri-PC:/opt/pgadmin4/web$ python3 pgAdmin4.py
    

Output:


temukan baris /* User used to manipulate with storage */. Lalu isi pada bagian controluser (user mariaDB) –pma merupakan user khusus yang melakukan tugas administratif tertentu– dan controlpass (kata sandi user MariaDB). Jangan lupa hapus tanda dua garis miring yang ada pada bagian depan baris. Ini dilakukan agar tidak sembarang user yang dapat mengakses database melalui phpMyAdmin.

/* User used to manipulate with storage */ // $cfg[‘Servers’][$i][‘controlhost’] = ‘’; // $cfg[‘Servers’][$i][‘controlport’] = ‘’; $cfg[‘Servers’][$i][‘controluser’] = ‘root’; $cfg[‘Servers’][$i][‘controlpass’] = ‘password’;


Skrol ke bawah, pada bagian `/* Storage database and tables */` terdapat akses-akses administratif user database `pma`. Hilangkan tanda dua garis miring (komentar) pada tiap bagian sehingga menjadi:
```bash
/* Storage database and tables */
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
$cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
$cfg['Servers'][$i]['relation'] = 'pma__relation';
$cfg['Servers'][$i]['table_info'] = 'pma__table_info';
$cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
$cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
$cfg['Servers'][$i]['column_info'] = 'pma__column_info';
$cfg['Servers'][$i]['history'] = 'pma__history';
$cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
$cfg['Servers'][$i]['tracking'] = 'pma__tracking';
$cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
$cfg['Servers'][$i]['recent'] = 'pma__recent';
$cfg['Servers'][$i]['favorite'] = 'pma__favorite';
$cfg['Servers'][$i]['users'] = 'pma__users';
$cfg['Servers'][$i]['usergroups'] = 'pma__usergroups';
$cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding';
$cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches';
$cfg['Servers'][$i]['central_columns'] = 'pma__central_columns';
$cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings';
$cfg['Servers'][$i]['export_templates'] = 'pma__export_templates';

Tabel-tabel di atas ini belum ada, namun akan segera dibuat.

Terakhir, skrol ke paling bawah dan tambahkan baris berikut. Direktori temporary akan digunakan oleh phpMyAdmin sebagai template cache agar loading halaman lebih cepat.

$cfg['TempDir'] = '/var/lib/phpmyadmin/tmp';

Simpan dan tutup file (CTRL + X, Y, lalu ENTER).

Selanjutnya, perlu untuk membuat storage tabel dan database phpMyAdmin. Pada instalasi phpMyAdmin, terdapat file dengan nama create_tables.sql. File SQL ini memuat perintah-perintah yang dibutuhkan untuk membuat storage tabel dan database phpMyAdmin agar dapat berfungsi dengan baik.

Jalankan perintah:

sudo mariadb < /usr/share/phpmyadmin/sql/create_tables.sql

Selanjutnya, buat user administratif pma. Buka prompt MariaDB:

sudo mariadb

Buat user pma dsn GRANT izin yang sesuai, pastikan input password sesuai dengan yang ada pada dile config.inc.php.

GRANT SELECT, INSERT, UPDATE, DELETE ON phpmyadmin.* TO 'pma'@'localhost' IDENTIFIED BY 'password';

Untuk mengelola database melalui phpMyAdmin, buat user baru yang memiliki privilege terhadap semua tabel yang ada dalam database dan buat kata sandi yang kuat.

GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

Keluar dari prompt MariaDB:

exit

phpMyAdmin sudah sepenuhnya terinstal dan dikonfigurasi pada server. Tetapi, server Apache belum bisa men-serve aplikasi. Buat file konfigurasi Apache untuk mengatasinya.

Konfigurasi Apache untuk Men-serve phpMyAdmin

Saat instalasi phpMyAdmin melalui repositori, proses instalasi akan membuat file konfigurasi Apache secara otomatis (phpmyadmin.conf) dan disimpan pada direktori /etc/apache2/conf-enabled/. Karena instalasi dilakukan secara manual maka harus membuat filenya sendiri.

sudo nano /etc/apache2/conf-available/phpmyadmin.conf

Lalu tambahkan isi:

# phpMyAdmin default Apache configuration

Alias /phpmyadmin /usr/share/phpmyadmin

<Directory /usr/share/phpmyadmin>
    Options SymLinksIfOwnerMatch
    DirectoryIndex index.php

    <IfModule mod_php5.c>
        <IfModule mod_mime.c>
            AddType application/x-httpd-php .php
        </IfModule>
        <FilesMatch ".+\.php$">
            SetHandler application/x-httpd-php
        </FilesMatch>

        php_value include_path .
        php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
        php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/php-gettext/:/usr/share/php/php-php-gettext/:/usr/share/javascript/:/usr/share/php/tcpdf/:/usr/share/doc/phpmyadmin/:/usr/share/php/phpseclib/
        php_admin_value mbstring.func_overload 0
    </IfModule>
    <IfModule mod_php.c>
        <IfModule mod_mime.c>
            AddType application/x-httpd-php .php
        </IfModule>
        <FilesMatch ".+\.php$">
            SetHandler application/x-httpd-php
        </FilesMatch>

        php_value include_path .
        php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
        php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/php-gettext/:/usr/share/php/php-php-gettext/:/usr/share/javascript/:/usr/share/php/tcpdf/:/usr/share/doc/phpmyadmin/:/usr/share/php/phpseclib/
        php_admin_value mbstring.func_overload 0
    </IfModule>

</Directory>

# Authorize for setup
<Directory /usr/share/phpmyadmin/setup>
    <IfModule mod_authz_core.c>
        <IfModule mod_authn_file.c>
            AuthType Basic
            AuthName "phpMyAdmin Setup"
            AuthUserFile /etc/phpmyadmin/htpasswd.setup
        </IfModule>
        Require valid-user
    </IfModule>
</Directory>

# Disallow web access to directories that don't need it
<Directory /usr/share/phpmyadmin/templates>
    Require all denied
</Directory>
<Directory /usr/share/phpmyadmin/libraries>
    Require all denied
</Directory>
<Directory /usr/share/phpmyadmin/setup/lib>
    Require all denied
</Directory>

Simpan dan tutup file, lalu aktifkan dengan mengetikkan:

sudo a2enconf phpmyadmin.conf

Output:

Enabling conf phpmyadmin.
To activate the new configuration, you need to run:
  systemctl reload apache2

Lalu reload service apache2 agar konfigurasi diterapkan.

sudo systemctl reload apache2

Setelah selesai, phpMyAdmin sudah dapat diakses melalui web browser.

https://<alamat_domain>/phpmyadmin

phpmyadmin_test_deepin

Berikut tampilan phpMyAdmin setelah login.

phpmyadmin_test_deepin_login

Sekarang sudah dapat terkoneksi dan berinteraksi dengan phpMyAdmin, langkah terakhir yaitu memperkuat keamanan sistem agar terlindungi dari penyerang.

Mengamankan phpMyAdmin Lebih Lanjut

Karena phpMyAdmin banyak digunakan dimana-mana sehingga sangat berpotensi menjadi target bagi penyerang, sehingga perlu untuk menambahkan perlindungan akses terautorisasi. Salah satu cara termudah yaitu menempatkan sebuah gateway di depan semua aplikasi menggunakan fungsionalitas autorisasi dan autentikasi Apache yaitu .htaccess.

Edit file konfigurasi Apache:

sudo nano /etc/apache2/conf-available/phpmyadmin.conf

Tambahkan AllowOverride All di bagian dalam <Directory /usr/share/phpmyadmin>, seperti ini:

<Directory /usr/share/phpmyadmin>
    Options FollowSymLinks
    DirectoryIndex index.php
    AllowOverride All

    <IfModule mod_php5.c>
    ...

Simpan dan tutup file. Restart service Apache:

sudo systemctl restart apache2

Sekarang .htaccess sudah diaktifkan. Lanjutkan, dengan membuat file .htaccess. Agar berhasil, file ini harus dibuat di dalam direktori aplikasi:

sudo nano /usr/share/phpmyadmin/.htaccess

Tambahkan baris:

AuthType Basic
AuthName "Restricted Files"
AuthUserFile /usr/share/phpmyadmin/.htpasswd
Require valid-user

Lokasi yang dipilih untuk file password yaitu /usr/share/phpmyadmin/.htpasswd. Buat file dengan utilitas htpasswd dan sebuah user:

sudo htpasswd -c /usr/share/phpmyadmin/.htpasswd root

Output:

New password: 
Re-type new password: 
Adding password for user root

Untuk membuat user tambahan, jalankan seperti perintah di atas tanpa -c:

sudo htpasswd /etc/phpmyadmin/.htpasswd additionaluser

Restart service Apache agar autentikasi tambahan diterapkan:

sudo systemctl restart apache2

Sekarang, saat mengakses phpMyAdmin melalui web browser, akan dihadapkan tampilan login tambahan (autentikasi Apache) sebelum dihadapkan pada halaman login phpMyAdmin. Pengaturan ini menambahkan layer keamanan tambahan yang diinginkan karena phpMyAdmin rawan terhadap kerentanan.

phpmyadmin_test_deepin_apache_login

Jika tidak dapat melakukan autentikasi dengan data yang benar, saat menekan tombol Cancel akan dihadapkan pada halaman error Unauthorized.

phpmyadmin_test_deepin_apache_login_error

Akhirnya sampai juga di bagian akhir artikel ini. Terima kasih sudah membaca artikel ini sampai bagian akhir.

Demikian langkah-langkah instalasi phpMyAdmin ini. Semoga bermanfaat. Jangan lupa di-share.

Referensi