H. Instalasi dan Konfigurasi VPS

 

  1. Update dan upgrade sistem debian serta install dependensi yang dibutuhkan

    # apt -y update 
    # apt -y upgrade
    # apt -y install build-essential
    # apt -y install net-tools
    # apt -y install dnsutils
    # apt -y install iftop

     

  2. Install PHP (default versi PHP pada Debian 10 adalah PHP7.3)

    # apt -y install php php-cgi php-cli libapache2-mod-php php-bcmath php-fpm php-common php-curl php-gd php-intl php-mbstring php-mysql php-opcache php-readline php-xml php-xsl php-zip php-bz2

     

  3. Install MariaDB Database Server

    # apt -y install curl software-properties-common gnupg2
    # apt -y upgrade
    # reboot
    # curl -LsS -O https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
    # bash mariadb_repo_setup --mariadb-server-version=10.9
        [info] Checking for script prerequisites.
        [info] MariaDB Server version 10.9 is valid
        [info] Repository file successfully written to /etc/apt/sources.list.d/mariadb.list
        [info] Adding trusted package signing keys...
        [info] Running apt-get update...
        [info] Done adding trusted package signing keys
    
    # apt update
    # apt -y install mariadb-server mariadb-client
    # mariadb-secure-installation
    
        NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
              SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
    
        In order to log into MariaDB to secure it, we'll need the current
        password for the root user. If you've just installed MariaDB, and
        haven't set the root password yet, you should just press enter here.
    
        Enter current password for root (enter for none): [Tekan Enter]
        OK, successfully used password, moving on...
    
        Setting the root password or using the unix_socket ensures that nobody
        can log into the MariaDB root user without the proper authorisation.
    
        You already have your root account protected, so you can safely answer 'n'.
    
        Switch to unix_socket authentication [Y/n] y
        Enabled successfully!
        Reloading privilege tables..
         ... Success!
    
    
        You already have your root account protected, so you can safely answer 'n'.
    
        Change the root password? [Y/n] y
        New password:    [ketikan password user root phpmyadmin disini]
        Re-enter new password:    [ketik ulang password]
        Password updated successfully!
        Reloading privilege tables..
         ... Success!
    
    
        By default, a MariaDB installation has an anonymous user, allowing anyone
        to log into MariaDB without having to have a user account created for
        them.  This is intended only for testing, and to make the installation
        go a bit smoother.  You should remove them before moving into a
        production environment.
    
        Remove anonymous users? [Y/n] y
         ... Success!
    
        Normally, root should only be allowed to connect from 'localhost'.  This
        ensures that someone cannot guess at the root password from the network.
    
        Disallow root login remotely? [Y/n] y
         ... Success!
    
        By default, MariaDB comes with a database named 'test' that anyone can
        access.  This is also intended only for testing, and should be removed
        before moving into a production environment.
    
        Remove test database and access to it? [Y/n] y
         - Dropping test database...
         ... Success!
         - Removing privileges on test database...
         ... Success!
    
        Reloading the privilege tables will ensure that all changes made so far
        will take effect immediately.
    
        Reload privilege tables now? [Y/n] y
         ... Success!
    
        Cleaning up...
    
        All done!  If you've completed all of the above steps, your MariaDB
        installation should now be secure.
    
        Thanks for using MariaDB!
    
        

     

  4. Install Apache2 Web Server dan PHPMyAdmin

    Untuk pengaturan pada instalasi ini, kami memilih Apache sebagai server web untuk digunakan dengan phpMyAdmin. Anda bebas memilih server web mana pun yang Anda inginkan, misalnya Nginx.

    Instal Apache Web Server pada sistem Debian dengan menjalankan perintah berikut:

    # apt-get -y install wget apache2

    Anda dapat memeriksa rilis phpMyAdmin dari halaman resminya. Terima kasih William Desportes atas petunjuk tentang cara mengunduh rilis terbaru phpMyAdmin.

    Unduh versi terbaru phpMyAdmin dengan perintah wget.

    # 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

    Ekstrak file yang telah diunduh:

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

    Pindahkan folder hasil ekstrak ke folder /usr/share/phpmyadmin.

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

    Buat direktori untuk file temp phpMyAdmin.

    # mkdir -p /var/lib/phpmyadmin/tmp
    
    # chown -R www-data:www-data /var/lib/phpmyadmin

    Buat direktori untuk file konfigurasi phpMyAdmin seperti file .htpass

    # mkdir /etc/phpmyadmin/

    Buat file konfigurasi phpMyAdmin.

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

    Edit file /usr/share/phpmyadmin/config.inc.php dan atur frasa sandi rahasia:

    # nano /usr/share/phpmyadmin/config.inc.php
        $cfg['blowfish_secret'] = 'H2OxcGXxflSd8JwrwVlh6KW6s2rER63i';
        $cfg['TempDir'] = '/var/lib/phpmyadmin/tmp';

    Buat file konfigurasi Apache phpMyAdmin:

    # nano /etc/apache2/conf-enabled/phpmyadmin.conf

    Dan paste kan script di bawah ini ke file phpmyadmin.conf

        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>

    Anda dapat membatasi akses dari IP tertentu dengan menambahkan baris seperti di bawah ini:

    Require ip 127.0.0.1 192.168.16.0/24

    Restart apache web server

    # systemctl restart apache2

     

    Akses interface web phpMyAdmin di http://[ServerIP|Hostname]/phpmyadmin. Gunakan nama user dan kata sandi yang sudah di seting sebelumnya untuk masuk.

     

  5. Install Multiple PHP (PHP7.4, PHP8.0 dan PHP8.1) dan beberapa modul PHP

    Install dependensi software
    Software yang akan di install disini tidak hanya untuk kebutuhan instalasi PHP saja, tetapi agar proses instalasi berjalan normal ada baiknya kita install semuanya

    # apt -y install apt-transport-https lsb-release ca-certificates

     

    Repository Sury
    Repository yang menyediakan PHP di Debian adalah Sury. Ondřej Surý orang yang mengelola sury.org adalah maintener PHP di Debian, jadi kualitas yang ditawarkan sama dengan repository resmi Debian. Tambahkan repository Sury kedalam konfigurasi APT

    # echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list
    	deb https://packages.sury.org/php/ buster main

     

    Install GPG Key dari Sury

    # curl -sSL -o /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg

     

    Lakukan update sekaligus upgrade agar repository dari sury dapat dikenali oleh apt

    # apt -y update
    
    # apt -y upgrade

     

    Install PHP

    # apt install -y php7.4 php7.4-cgi php7.4-cli libapache2-mod-php7.4 php7.4-bcmath php7.4-fpm php7.4-common php7.4-curl php7.4-gd php7.4-intl php7.4-mbstring php7.4-mysql php7.4-opcache php7.4-readline php7.4-xml php7.4-xsl php7.4-zip php7.4-bz2
    
    # apt install -y php8.0 php8.0-cgi php8.0-cli libapache2-mod-php8.0 php8.0-bcmath php8.0-fpm php8.0-common php8.0-curl php8.0-gd php8.0-intl php8.0-mbstring php8.0-mysql php8.0-opcache php8.0-readline php8.0-xml php8.0-xsl php8.0-zip php8.0-bz2
    
    # apt install -y php8.1 php8.1-cgi php8.1-cli libapache2-mod-php8.1 php8.1-bcmath php8.1-fpm php8.1-common php8.1-curl php8.1-gd php8.1-intl php8.1-mbstring php8.1-mysql php8.1-opcache php8.1-readline php8.1-xml php8.1-xsl php8.1-zip php8.1-bz2
    

     

    Memeriksa versi PHP serta PHP yang aktif

    # php -v
        PHP 8.1.11 (cli) (built: Sep 29 2022 22:12:52) (NTS)
        Copyright (c) The PHP Group
        Zend Engine v4.1.11, Copyright (c) Zend Technologies
            with Zend OPcache v8.1.11, Copyright (c), by Zend Technologies

    Dari hasil perintah diatas, terlihat bahwa versi PHP yang tampil adalah yang versi paling tinggi yaitu PHP8.1 sedangkan untuk melihat PHP yang aktif kita bisa gunakan cara berikut ini :

    # nano /var/www/html/info.php
            <?php
            phpinfo();
    
    # chmod +x /var/www/html/info.php

    Kemudian akses menggunakan browser dengan mengetikan alamat http://IP_server/info.php

    Dari tampilan diatas terlihat bahwa yang aktif saat ini adalah PHP versi PHP7.3, lalu bagaimana caranya agar yang aktif adalah PHP versi PHP7.4 atau PHP8.0 atau yang paling baru yaitu PHP8.1 ? caranya adalah sebagai berikut :

    Disable modul PHP7.3

    # a2dismod php7.3
        Module php7.3 disabled.
        To activate the new configuration, you need to run:
          systemctl restart apache2

    Enable modul PHP8.1

    # a2enmod php8.1
        Considering dependency mpm_prefork for php8.1:
        Considering conflict mpm_event for mpm_prefork:
        Considering conflict mpm_worker for mpm_prefork:
        Module mpm_prefork already enabled
        Considering conflict php5 for php8.1:
        Enabling module php8.1.
        To activate the new configuration, you need to run:
          systemctl restart apache2

    Restart service Apache

    # systemctl restart apache2

    Cek kembali PHP yang aktif

    # php -v
        PHP 8.1.11 (cli) (built: Sep 29 2022 22:12:52) (NTS)
        Copyright (c) The PHP Group
        Zend Engine v4.1.11, Copyright (c) Zend Technologies
            with Zend OPcache v8.1.11, Copyright (c), by Zend Technologies

    versi PHP masih tetap PHP8.1, kemudian kita lihat info lengkapnya

    Dari tampilan diatas terlihat bahwa yang aktif saat ini adalah PHP versi PHP8.1, Jika kita ingin ke versi 7.4 atau 8.0, tinggal jalankan lagi perintah seperti di atas.

     

  6. Tuning PHP untuk kebutuhan Export dan Import database di PHPMyAdmin

    # nano /etc/php/8.1/apache2/php.ini

    Dan rubah beberapa parameter seperti berikut ini:

    max_execution_time = 60
    max_input_time = 180
    memory_limit = 512M
    post_max_size = 800M
    upload_max_filesize = 800M
    max_file_uploads = 200

    Lakukan restart pada service Apache

    # /etc/init.d/apache2 restart
    [ ok ] Restarting apache2 (via systemctl): apache2.service.

     

  7. Selesai
    Semoga bisa membantu dan bermanfaat

     

     

 

 

Sumber :

  • https://computingforgeeks.com/install-phpmyadmin-with-apache-on-debian/
  • https://jaranguda.com/cara-terbaru-install-php-8-di-debian-10/
  • https://www.petanikode.com/php8-install/