Otu esi etinye phpMyAdmin kacha ọhụrụ na LEMP na Ubuntu 20.04

phpmyadmin bụ ngwa nchịkwa na-emepe emepe nke edere na ya PHP eji na-elekọta MySQL na MariaDB nchekwa data sava site a Ntanetị weebụ. Ọtụtụ ndị mmepe na-ahọrọ iji phpMyAdmin ka ya na ihe nkesa nchekwa data na-emekọrịta ihe n'ihi na ọ dị mfe iji ya na nchịkọta akụkọ SQL dị elu, na-eme ka ọ dị mfe ịmepụta na ịnwale ajụjụ SQL dị mgbagwoju anya.

N'ime nkuzi a, ị ga-amụta otu esi etinye LEMP na phpMyAdmin site na isi iyi na Ubuntu 20.04.

Prerequisites

  • OS akwadoro: Ubuntu 20.04 - nhọrọ (Ubuntu 21.04 na Linux Mint 20)
  • Akaụntụ onye ọrụ: Akaụntụ onye ọrụ nwere sudo ma ọ bụ ohere mgbọrọgwụ.
  • chọrọ: Nginx, MariaDB na PHP (LEMP)

Na-emelite Sistemụ Ọrụ

Mbụ, tupu ihe ọ bụla, melite gị Ubuntu Sistemụ arụmọrụ iji hụ na ngwugwu niile dị adị adịla ugbu a:

sudo apt update && sudo apt upgrade -y

Advertisement


Nginx maka phpMyAdmin

Tinye PPA omenala maka Nginx kacha ọhụrụ

Nyere na ị na-edozi phpMyAdmin na Nginx, ị ga-achọ ịwụnye ngwa weebụ. Ugbu a, usoro kachasị mma maka ọtụtụ bụ iji PPA nke ndị a ma ama Ondřej Surý, onye na-edobe ma ụdị Nginx na Stable ma na-emelite ya mgbe niile.

Nke mbụ, tinye PPA kwụsiri ike ma ọ bụ nke isi dị ka ndị a:

Nginx Stable:

sudo add-apt-repository ppa:ondrej/nginx-stable -y && sudo apt update

Nginx Mainline (A kwadoro):

sudo add-apt-repository ppa:ondrej/nginx-mainline -y && sudo apt update

Wụnye Nginx

Mgbe ị wụnye Nginx PPA kwụsiri ike ma ọ bụ isi, jiri iwu na-esonụ iji wụnye Nginx:

sudo apt install nginx-core nginx-common nginx nginx-full

MariaDB maka phpMyAdmin

Wụnye MariaDB maka Ubuntu 20.04

Mbụ, ịkwesịrị ịwụnye MariaDB ka ịmepụta nchekwa data na aha njirimara dị ka ndị a:

sudo apt install mariadb-server

Mara, nke a bụ ụdị ochie, yana nrụnye ndabara bụ ụdị 10.3. Biko gaa na nke anyị nkuzi Ọ bụrụ na ịchọrọ ịwụnye ụdị MariaDB ọhụrụ, dị ka 10.5 na 10.6.

Na-esote, mee script nchekwa ma ọ bụrụ na ị wụnyere ọhụrụ na nke mbụ site na iji iwu a:

sudo mysql_secure_installation

Na-esote, soro n'okpuru:

  • Ịtọ ntọala paswọọdụ maka mgbọrọgwụ akaụntụ.
  • Iwepu akaụntụ mgbọrọgwụ nke a na-enweta site na mpụga onye ọbịa mpaghara.
  • Iwepu akaụntụ onye ọrụ amaghị aha.
  • Iwepu nchekwa data ule, nke ndị ọrụ amaghị aha nwere ike ịnweta na ndabara.

Mara, ị na-eji (NA) iji wepụ ihe niile.

Mepụta phpMyAdmin database na aha njirimara

Mbụ, mepee MariaDB wee mepụta nchekwa data ọhụrụ maka phpMyAdmin:

sudo mysql -u root

Ọzọ, mepụta nchekwa data na ọdụ MariaDB:

CREATE DATABASE phpmyadmindb;

Ugbu a ịkwesịrị ịmepụta onye ọrụ wee nye ikike dịka ndị a:

GRANT ALL ON phpmyadmindb.* TO phpmyadminuser@localhost IDENTIFIED BY 'password here change';

Iji mechaa, hichapụ ihe ùgwù ndị ahụ wee jiri koodu ndị a pụọ:

FLUSH PRIVILEGES;
QUIT;

Advertisement


PHP maka phpMyAdmin

Tinye PPA omenala maka PHP Kacha ọhụrụ

Dị ka nwụnye Nginx anyị, a na-atụ aro ka ịgbakwunye PPA site na Ondřej Surý, onye na-elekọta PHP maka Debian. PPA omenala nwere ụdị 7.4, 8.0 kachasị ọhụrụ na 8.1 kacha ọhụrụ na-abata.

Tinye PPA site na iji iwu a:

sudo apt install software-properties-common && sudo add-apt-repository ppa:ondrej/php -y

Wụnye PHP maka Ubuntu 20.04

Ugbu a, ị nwere ike iwunye PHP 7.4 ma ọ bụ PHP 8.0. Dị ka PHP ka dị ọhụrụ na ikekwe nwere ọtụtụ chinchi na phpMyAdmin, a na-atụ aro ka ịwụnye PHP 7.4 maka ugbu a. Iji mezuo nke a, jiri iwu njedebe na-esonụ iji wụnye ngwugwu achọrọ:

sudo apt install php7.4-fpm php7.4-mbstring php7.4-bcmath php7.4-xml php7.4-mysql php7.4-common php7.4-gd php7.4-mcrypt php7.4-cli php7.4-curl php7.4-zip php7.4-gd

Wụnye phpMyAdmin na Ubuntu 20.04

Site na ndabara, ebe nchekwa Ubuntu 20.04 na-abịa na phpMyAdmin yana ihe ndabere achọrọ. Agbanyeghị, dị ka mgbe ọ na-ewepụta Ubuntu LTS, ụdị na ihe nrụpụta dị n'azụ ihe dị ugbu a site na isi mmalite. Yabụ dịka ebumnuche ntuziaka a, ị ga-ebudata site na isi mmalite dị ka ndị a:

Budata ụdị isi mmalite kacha ọhụrụ phpMyAdmin

Iji malite, gaa na phpMyAdmin downloads ibe iji chọta ụdị kachasị ọhụrụ ugbu a. N'oge nkuzi a, ụdị 5.1.1 bụ nke kachasị ọhụrụ.

Mezue koodu ndị a ka ibudata ụdị asụsụ niile na-akpaghị aka:

DATA="$(wget https://www.phpmyadmin.net/home_page/version.txt -q -O-)"
URL="$(echo $DATA | cut -d ' ' -f 3)"
VERSION="$(echo $DATA | cut -d ' ' -f 1)"
wget https://files.phpmyadmin.net/phpMyAdmin/${VERSION}/phpMyAdmin-${VERSION}-all-languages.tar.gz

Ọ bụrụ na ịchọrọ ibudata ụdị bekee, were ihe ndị a dochie ahịrị ngwụcha:

wget https://files.phpmyadmin.net/phpMyAdmin/${VERSION}/phpMyAdmin-${VERSION}-english.tar.gz

Na-esote, wepụ ihe ndekọ ahụ site na iji iwu a:

tar xvf phpMyAdmin-${VERSION}-all-languages.tar.gz

Hazie phpMyAdmin Iji aka

Ịkwesịrị ịkwaga akwụkwọ ndekọ aha ewepụtara na akwụkwọ ndekọ aha ya gaa na / usr / kekọrịta ebe ndekọ ebe phpMyAdmin na-atụ anya ịchọta faịlụ nhazi ya na ndabara. Iji mee nke a, jiri iwu a:

sudo mv phpMyAdmin-*/ /usr/share/phpmyadmin

Site na ndabara, phpMyAdmin anaghị abịa na a TMP ndekọ mgbe ị na-etinye site na isi mmalite, ma ị ga-eji aka mepụta nke a:

sudo mkdir -p /var/lib/phpmyadmin/tmp

Kenye onye ọrụ ikike ziri ezi www-data ya na ndekọ phpMyAdmin:

sudo chown -R www-data:www-data /var/lib/phpmyadmin

Na ndekọ phpMyAdmin, a na-etinye faịlụ nhazi-ihe atụ nke ndabara. Ị ga-achọgharị aha faịlụ a maka phpMyAdmin iji mata nhazi ahụ. Agbanyeghị, maka nkwado ndabere na mpaghara, ị ga-eji CP iwu ka ịmepụta otu ma dobe ndabara dị ka ndabere ma ọ bụrụ na emehie ihe ọ bụla na ebe ahụ /etc/usr/phpmyadmin/ directory.

Copy config.sample.inc.php na config.inc.php site na iwu a:

sudo cp /usr/share/phpmyadmin/config.sample.inc.php /usr/share/phpmyadmin/config.inc.php

Ọzọ, mepee faịlụ a site na iji editọ ederede masịrị gị. Maka nkuzi a, a na-eji ndezi ederede nano:

sudo nano /usr/share/phpmyadmin/config.inc.php

phpMyAdmin na-eji a Blowfish cipher. Pịgharịa gaa na ahịrị nke na-amalite $cfg['blowfish_secret'].

Ahịrị ndị ahụ ga-adị ka ọmụmaatụ:

$cfg['blowfish_secret'] = ''; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

Ị ga-ekenye eriri mkpụrụedemede 32 na-enweghị usoro n'etiti otu akara nrịbama. Ụzọ kachasị mfe iji nweta nke a bụ iji mmemme pwgen. Iji wụnye pwgen, jiri iwu njedebe a:

sudo apt install pwgen

Ozugbo arụnyere, gbanye iwu a:

pwgen -s 32 1

Ị ga-enweta mkpụrụedemede 32 na-enweghị usoro maka nzuzo ịfụfụ, ihe atụ:

Otu esi etinye phpMyAdmin kacha ọhụrụ na LEMP na Ubuntu 20.04

Ọmụmaatụ nke ịgbakwunye cipher na faịlụ nhazi (Edoghachila):

$cfg['blowfish_secret'] = 'kQVwa2yLI6FxA3LN6E7YcW3WgtTKTZ2j'

Ntọala ndabara ndị ọzọ kwesịrị ịrụ ọrụ maka ọtụtụ ndị ọrụ. Ọ bụrụ na ihe nkesa gị dị na ihe nkesa ọzọ dị na netwọk gị, chọta ma gbanwee ahịrị $cfg['Servers']][$i]['onye ọbịa'] = gaa na nke adreesị IP nkeonwe. Ọmụmaatụ n'okpuru:

$cfg['Servers'][$i]['host'] = '192.168.55.101';

Advertisement


Mepụta Nginx Server Block maka phpMyAdmin

Iji nweta interface weebụ phpMyAdmin, ị ga-achọ ịmepụta ngọngọ nkesa Nginx. A na-atụ aro ka idobe nke a iche, yana na ngalaba ngalaba, ị nwere ike ịkpọ ya ihe ọ bụla masịrị gị iji nyere aka na nchekwa na mwakpo ike.

Mbụ, mepụta ma mepee ngọngọ nkesa gị site na iji nano ederede nchịkọta akụkọ dị ka ndị a:

sudo nano /etc/nginx/sites-available/phpmyadmin.conf

Na-esote, ị nwere ike mado ederede n'okpuru n'ime faịlụ ahụ. Mara, ị ga-eji nke gị dochie ngalaba URL:

server {
  listen 80;
  listen [::]:80;
  server_name pma.example.com;
  root /usr/share/phpmyadmin/;
  index index.php index.html index.htm index.nginx-debian.html;

  access_log /var/log/nginx/phpmyadmin_access.log;
  error_log /var/log/nginx/phpmyadmin_error.log;

  location / {
    try_files $uri $uri/ /index.php;
  }

  location ~ ^/(doc|sql|setup)/ {
    deny all;
  }

  location ~ \.php$ {
    fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    include snippets/fastcgi-php.conf;
  }

  location ~ /\.ht {
    deny all;
  }
}

Ọ bụrụ naanị gị na-enweta nke a site na adreesị IP static, ị nwere ike itinye koodu a n'elu ntinye ọnọdụ mbụ. Otu ihe atụ nke a bụ n'okpuru:

  allow <your ip address>;
  deny all; 

  location / {
    try_files $uri $uri/ /index.php;
  }
...........................................

Nke a ga-adị ngọngọ onye ọ bụla na-eleta ibe ahụ nwere njehie 403 ma ọ bụrụ na adreesị IP gị anabataghị. Nke a, site na okike, nwere ike ịkwụsị mwakpo ọjọọ niile na egwu ha, mana enwere ike ọ gaghị ekwe omume maka nhazi ụfọdụ.


Ugbu a chekwaa iji (CTRL+O) wee pụọ na ya (CTRL+X).

Nwalee ngọngọ nkesa Nginx gị site na iji iwu ịgba ọsọ kpọrọ nkụ:

sudo nginx -t

Ọ bụrụ na ịnweghị mperi, ị ga-enweta nsonaazụ a:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Ugbu a malitegharịa ọrụ Nginx gị ka mgbanwe wee malite:

sudo systemctl restart nginx

Ịnweta phpMyAdmin Weebụ UI

Iji nweta Interface Weebụ, mepee ihe nchọgharị ịntanetị masịrị gị wee banye pma.example.com na (ihe atụ) ngalaba gị. Ị ga-abịa na ihuenyo nbanye nke phpMyAdmin dị ka ndị a:

Otu esi etinye phpMyAdmin kacha ọhụrụ na LEMP na Ubuntu 20.04

Banye site na iji aha njirimara na paswọọdụ MariaDB nke hibere na mbido nkuzi. Ị ga-abịa na ihuenyo bụ isi.

Otu esi etinye phpMyAdmin kacha ọhụrụ na LEMP na Ubuntu 20.04

Advertisement


Wụnye Asambodo TLS

Iji gaa n'ihu nọrọ ná nchebe interface weebụ phpMyAdmin, ị nwere ike ịwụnye n'efu Ka anyị zoo asambodo TLS si Ebe nchekwa nchekwa Ubuntu.

Gbaa iwu a na ọdụ Ubuntu gị:

sudo apt install certbot python3-certbot-nginx

Ugbu a gbaa iwu a iji nweta ma wụnye asambodo TLS maka Nginx na phpMyAdmin:

sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --must-staple -d pma.example.com --email your-email-address

N'oge ntinye akwụkwọ, ị ga-enweta ọkwa ịnata ozi-e EFF(Electronic Frontier Foundation). Họrọ Y ma ọ bụ N mgbe ahụ, a ga-arụnye gị asambodo TLS na-akpaghị aka ma hazie gị.

Otu esi etinye phpMyAdmin kacha ọhụrụ na LEMP na Ubuntu 20.04

Nke ahụ bụ ya, ma ị wụnyela SSL na mpaghara phpMyAdmin gị. Jide n'aka na ịnwale site na iji ule SSL efu dị ka DigiCert or Ụlọ nyocha SSL.

Okwu na mmechi

N'ime nkuzi a, ị mụtala ka esi etinye ndabere ngwanrọ achọrọ wee budata wee mepụta akwụkwọ ndekọ aha ziri ezi maka phpMyAdmin site na isi mmalite. N'ozuzu, iji phpMyAdmin bụ nnukwu ngwá ọrụ maka njikwa nchekwa data ọ bụla. Ị nwere ike ịmepụta ọdụ data ngwa ngwa, ndị ọrụ, tebụl ma rụọ ọrụ ndị a na-emebu dị ka ihichapụ na imegharị ihe owuwu na data na ntanetị UI dị ọcha kama ọ bụghị njedebe ndabara.

Ahapụ a Comment