Ịwụnye LEMP (Linux, Nginx, MySQL/MariaDB, PHP/PHP-FPM na PhpMyAdmin) na Linux Gentoo


Gentoo bụ otu n'ime nkesa Linux kachasị ngwa ngwa n'ihi iwulite ya site na isi mmalite yana na-enye site na mmemme njikwa ngwanrọ ya - Portage- ụfọdụ ngwaọrụ achọrọ iji wuo usoro nrụpụta weebụ zuru oke nke na-arụ ọrụ ma na-arụ ọrụ ngwa ngwa na, nwekwara, nwere nnukwu ogo nke customization.

Isiokwu a ga-ewega gị site na usoro ntinye nzọụkwụ site na iji wuo ebe nrụọrụ weebụ zuru oke na LEMP (Linux Nginx, MySQL/MariaDB, PHP-FPM/PhpMyadmin), yana enyemaka na Jiri ọkọlọtọnyere site na Portage Package Management, nke na-enye nhazi ọrụ ngwugwu na usoro nchịkọta - modul ma ọ bụ ntọala dị mkpa maka ikpo okwu weebụ, ga-eme ka nhazi ihe nkesa dị ukwuu.

  1. Nwụnye Gentoo nwere profaịlụ siri ike maka ihe nkesa na-eche ịntanetị ihu – Ntuziaka nwụnye Gentoo.
  2. Network ejiri adreesị IP kwụ ọtọ ahazi.

Kwụpụ 1: Wụnye Nginx Web Server

1. Tupu ịgbalị ịga n'ihu na ntinye Nginx, jide n'aka na ahazila NIC gị na adreesị IP Static ma hụ na isi mmalite Portage na sistemụ gị dị ọhụrụ.

$ sudo su -
# emerge --sync
# emerge --update --deep --with-bdeps=y @world

2. Mgbe usoro mmelite mechara, gaa n'ihu na ntinye Nginx site na ịhọrọ ntọala na modul ndị kachasị amasị site na ịmegharị Nginx USE flags na Portage make.conf faịlụ. Ndepụta mbụ Nginx nrụnye modul site na ịme iwu na-esonụ.

# emerge -pv nginx

Maka ozi modul zuru ezu (Jiri ọkọlọtọ maka ngwugwu) jiri iwu equery.

# equery uses nginx

Wee tinye Nginx na iwu na-esonụ.

# emerge --ask nginx

Ọ bụrụ na ịchọrọ mgbakwunye modul (WebDAV, fancyindex, GeoIP, wdg) ewezuga ndị ndabara, nke Nginx ga-ejikọta ya, tinye ha niile n'otu ahịrị na Portage make.conf faịlụ nwere NGINX_MODULES_HTTP ntuziaka, wee jiri modul ọhụrụ chịkọta Nginx.

# echo 'NGINX_MODULES_HTTP="dav auth_pam fancyindex geoip fastcgi uwsgi gzip rewrite"' >> /etc/portage/make.conf
# emerge --ask nginx

3. Mgbe Portage mechara Nginx apụta, malite http daemon wee nyochaa ya site na iduzi ihe nchọgharị gị na http://localhost.

Nzọụkwụ 2: Wụnye PHP

4. Iji jiri PHP dynamic web programming language with Nginx server, wụnye PHP-FastCGI Process Manager(FPM) site na itinye fpm na PHP ndị ọzọ dị mkpa. Mgbakwunye na ọkọlọtọ Portage USE wee hụ na ị wepụrụ ndọtị Apache.

# emerge -pv php
# equery uses php
# echo " dev-lang/php fpm cgi curl gd imap mysql mysqli pdo zip json xcache apc zlib zip truetype -apache2 " >> /etc/portage/package.use
# emerge --ask php

5. Tupu ịmalite PHP-FPM ụfọdụ mgbanwe dị mkpa ka etinyere na faịlụ nhazi ọrụ. Mepee faịlụ nhazi php-fpm wee mee mgbanwe ndị a.

# nano /etc/php/fpm-php5.5/php-fpm.conf

Chọta wee kwughachi ntuziaka ndị a ka ọ dị ka nke a.

error_log = /var/log/php-fpm.log
listen = 127.0.0.1:9000    ## Here you can use any HTTP socket (IP-PORT combination ) you want  ##
pm.start_servers = 20

6. Mgbe PHP-FPM nhazi faịlụ ọ dezie, gbanwee PHP-FPM log faịlụ ikikere wee malite ọrụ.

# chmod 755 /var/log/php-fpm.log
# /etc/init.d/php-fpm start

Ọbụna ma ọ bụrụ na amalitere ọrụ PHP-FPM, Nginx enweghị ike ikwurịta okwu na ọnụ ụzọ PHP, yabụ, ọ dị mkpa ka eme mgbanwe ụfọdụ na faịlụ nhazi Nginx.

Kwụpụ 3: Dezie Nginx Nhazi

7. Nginx ndabere template nhazi faịlụ dị nnọọ na-enye isi HTTP soket maka localhost naanị. Iji gbanwee omume a wee mee ka Virtual Hosts, mepee nginx.conf faịlụ dị na /etc/nginx/ ụzọ wee mee nhazi ndị a.

# nano /etc/nginx/nginx.conf

Chọta ngọngọ nke mbụ sava nke dabara na localhost wee gee na 127.0.0.1 adreesị IP wee jaa okwu ya niile ka ọ dị na nseta ihuenyo dị n'okpuru.

Emechiela faịlụ ahụ ma gaa na ala ma tinye nkwupụta na-esonụ tupu emechie braces curly ikpeazụ \ } \.

Include /etc/nginx/sites-enabled/*.conf;

8. Ọzọ mepụta saịtị-enyerena saịtị dị(maka ndị ọbịa Virtual ejighi ya) Nginx directories na faịlụ nhazi maka localhost na HTTP na HTTPS protocols.

# mkdir /etc/nginx/sites-available
# mkdir /etc/nginx/sites-enabled

Mepụta nhazi faịlụ ndị a maka localhost.

# nano /etc/nginx/sites-available/localhost.conf

Tinye ọdịnaya faịlụ ndị a.

server {
               listen 80;
               server_name localhost;

               access_log /var/log/nginx/localhost_access_log main;
               error_log /var/log/nginx/localhost_error_log info;

               root /var/www/localhost/htdocs;

                location / {
                index index.html index.htm index.php;
                autoindex on;
                autoindex_exact_size off;
                autoindex_localtime on;

                                }

                         location ~ \.php$ {
                       # Test for non-existent scripts or throw a 404 error
                       # Without this line, nginx will blindly send any request ending in .php to php-fpm
                       try_files $uri =404;
                        include /etc/nginx/fastcgi.conf;
                       fastcgi_pass 127.0.0.1:9000;  ## Make sure the socket corresponds with PHP-FPM conf file
                        }
                }

Maka localhost nwere SSL mepụta faịlụ nhazi ndị a.

# nano /etc/nginx/sites-available/localhost-ssl.conf

Tinye ọdịnaya faịlụ ndị a.

server {
               listen 443 ssl;
               server_name localhost;

            ssl on;
               ssl_certificate /etc/ssl/nginx/nginx.pem;
               ssl_certificate_key /etc/ssl/nginx/nginx.key;

               access_log /var/log/nginx/localhost.ssl_access_log main;
               error_log /var/log/nginx/localhost.ssl_error_log info;

               root /var/www/localhost/htdocs;

                                location / {
                index index.html index.htm index.php;
                autoindex on;
                autoindex_exact_size off;
                autoindex_localtime on;
                                 }                                                

                      location ~ \.php$ {
                       # Test for non-existent scripts or throw a 404 error
                       # Without this line, nginx will blindly send any request ending in .php to php-fpm
                       try_files $uri =404;
                       include /etc/nginx/fastcgi.conf;
                       fastcgi_pass 127.0.0.1:9000;
                                }
                }

9. Ugbu a, ọ bụ oge ịmepụta edemede abụọ na usoro executable ụzọ (PATH shell variable), na-eme dị ka iwu iji rụọ ọrụ ma ọ bụ gbanyụọ Nginx Virtual Hosts.

Mepụta edemede Bash nke mbụ aha ya bụ n2ensite nke ga-eme ka faịlụ nhazi ndị ọbịa Virtual site na ịmepụta njikọ ihe atụ n'etiti ndị ọbịa akọwapụtara site na saịtị-dị ruo saịtị-enyere >.

# nano /usr/local/bin/n2eniste

Tinye ọdịnaya faịlụ ndị a.

#!/bin/bash
if test -d /etc/nginx/sites-available && test -d /etc/nginx/sites-enabled  ; then
echo "-----------------------------------------------"
else
mkdir /etc/nginx/sites-available
mkdir /etc/nginx/sites-enabled
fi

avail=/etc/nginx/sites-available/$1.conf
enabled=/etc/nginx/sites-enabled/
site=`ls /etc/nginx/sites-available/`

if [ "$#" != "1" ]; then
                echo "Use script: n2ensite virtual_site"
                echo -e "\nAvailable virtual hosts:\n$site"
                exit 0
else

if test -e $avail; then
sudo ln -s $avail $enabled
else
echo -e "$avail virtual host does not exist! Please create one!\n$site"
exit 0
fi

if test -e $enabled/$1.conf; then
echo "Success!! Now restart nginx server: sudo /etc/init.d/ nginx restart"
else
echo  -e "Virtual host $avail does not exist!\nPlease see available virtual hosts:\n$site"
exit 0
fi
fi

10. Mgbe ahụ mepụta edemede nke abụọ a na-akpọ n2dissite, nke ga-ehichapụ kpọmkwem ndị ọbịa Virtual nọ n'ọrụ site na saịtị-enyere ụzọ Nginx nwere ọdịnaya ndị a.

# nano /usr/local/bin/n2dissite

Tinye ọdịnaya ndị a.

#!/bin/bash
avail=/etc/nginx/sites-enabled/$1.conf
enabled=/etc/nginx/sites-enabled
site=`ls /etc/nginx/sites-available/`

if [ "$#" != "1" ]; then
                echo "Use script: n2dissite virtual_site"
                echo -e "\nAvailable virtual hosts: \n$site"
                exit 0
else

if test -e $avail; then
sudo rm  $avail
else
echo -e "$avail virtual host does not exist! Exiting!"
exit 0
fi

if test -e $enabled/$1.conf; then
echo "Error!! Could not remove $avail virtual host!"
else
echo  -e "Success! $avail has been removed!\nPlease restart Nginx: sudo /etc/init.d/nginx restart"
exit 0
fi
fi

11. Mgbe emechara edezi Bash scripts, tinye ikike igbu ma rụọ ọrụ localhost Virtual Hosts - jiri aha faịlụ nhazi nke Virtual Host na-enweghị .conf ndọtị, wee malitegharịa ọrụ Nginx na PHP-FPM iji tinye mgbanwe.

# chmod +x /usr/local/bin/n2dissite
# chmod +x /usr/local/bin/n2ensite
# n2ensite localhost
# n2ensite localhost-ssl
# service nginx restart
# service php-fpm restart

12. Iji nwalee nhazi mepụta faịlụ ozi PHP na ụzọ ndabere ndabere localhost maka faịlụ weebụ (/var/www/localhost/htdocs) wee redirect ihe nchọgharị gị na https://localhost/info .php ma ọ bụ http://localhost/info.php.

echo "<?php phpinfo(); ?>" /var/www/localhost/htdocs/info.php

Iji localhost Virtual Hosts nhazi faịlụ dị ka ndebiri na Nginx n2enmod na n2dismod ị nwere ike tinye ngwa ngwa ugbu a ọtụtụ weebụsaịtị dịka masịrị gị, mana jide n'aka na ị nwere akara ngosi DNS dị mma maka ịntanetị. -eche ihu sava weebụ ma ọ bụ jiri ndenye mpaghara na faịlụ ndị ọbịa sistemụ.

Kwụpụ 4: Wụnye MySQL/MariaDB + PhpMyAdmin

Iji wụnye MySQL nchekwa data na PhpMyAdmin Web interface maka MySQL jiri otu usoro ewepụtara na Ịwụnye LAMP na Gentoo.

13. Na nloghachi ma ọ bụrụ na ịchọrọ iji MariaDB, dobe-na nnọchi maka MySQL, jiri iwu ndị a iji nweta Jiri ọkọlọtọ wee wụnye ya.

# emerge -pv mariadb
# emerge --ask mariadb

Ọ bụrụ na ịnweta esemokwu ngwugwu na MySQL tinye ahịrị ndị a na Portage package.accept.keywords.

# echo “=dev-db/mariadb-5.5.37-r1 ~amd64” >> /etc/portage/package.accept.keywords
# echo “=virtual/mysql-5.5 ~amd64” >> /etc/portage/package.accept.keywords
# emerge --ask mariadb

14. Mgbe MySQL nchekwa data arụnyere mmalite ọrụ ma chekwaa ya site na iji mysql_secure_installation (gbanwee okwuntughe mgbọrọgwụ, gbanyụọ nbanye mgbọrọgwụ n'èzí localhost, wepụ onye ọrụ na-amaghị aha/ule nchekwa data).

# service mysql start
# mysql_secure_installation

15. Tinye MySQL nchekwa data site na iji, mysql -u root -piwu iji nwalee ọrụ ya wee hapụ ya na iwu wepụ.

# mysql -u root -p

MariaDB > show databases;
MariaDB > exit;

16. Ọ bụrụ na ị na-adịghị mma na MySQL iwu akara. wụnye PhpMyAdmin Web frontend site na ime iwu ndị a.

# emerge -pv dev-db/phpmyadmin
# echo “dev-db/phpmyadmin setup vhosts” >> /etc/portage/package.use
# emerge  --ask dev-db/phpmyadmin

17. Mgbe PhpMyAdmin mechara wụnye, mepụta faịlụ nhazi dabere na faịlụ nhazi sample, gbanwee blowfish_secretpassphrase na eriri na-enweghị usoro, wee mepụta njikọ ihe atụ site na /usr/share/webapps/phpmyadmin/ phpmyadmin_version_number/htdocs/ na Virtual Hosts akwụkwọ mgbọrọgwụ ụzọ ị chọrọ ịnweta PhpMyAdmin webụ interface.

# cd /usr/share/webapps/phpmyadmin/4.2.2/htdocs/
# cp config.sample.inc.php  config.inc.php
# nano config.inc.php
# ln -s /usr/share/webapps/phpmyadmin/4.2.2/htdocs/  /var/www/localhost/htdocs/phpmyadmin

18. Iji nweta MySQL nchekwa data site PhpMyAdmin Web interface, mepee ihe nchọgharị wee jiri URL na-esonụ https://localhost/phpmyadmin.

19. Nzọụkwụ ikpeazụ bụ ime ka ọrụ usoro-obosara, na-akpaghị aka na-amalite mgbe reboot.

# rc-update add nginx default
# rc-update add php-fpm default
# rc-update add mysql default

Ugbu a, anyị nwere nhazi obere gburugburu maka nnabata Weebụ, ma ọ bụrụ na ị na-eji HTML, Javascript na ibe PHP ike emepụtara na ịchọghị weebụsaịtị SSL, nhazi dị n'elu kwesịrị ị ga-eju gị afọ.