Jump to content

WordPress:Installasi di VPS: Difference between revisions

From Wiki
No edit summary
Line 1: Line 1:
Berikut adalah cara singkat menginstall [[WordPress]] di VPS [[Ubuntu]]
Berikut adalah cara singkat menginstall [[WordPress]] di VPS [[Ubuntu]]
==Installasi==
==Installasi==
  wget https://wordpress.org/latest.zip
  wget https://wordpress.org/latest.zip
Line 9: Line 8:


  sudo unzip latest.zip -d /var/www/
  sudo unzip latest.zip -d /var/www/
===Create a Database and User for WordPress Site===
===Create a Database and User for WordPress Site===
Masuk ke database server
Masuk ke database server
  sudo mariadb -u root
  sudo mariadb -u root
atau
atau
  sudo mysql -u root
  sudo mysql -u root
Lalu buat database dengan menggunakan perintah berikut
Lalu buat database dengan menggunakan perintah berikut
  create database wordpress;
  create database wordpress;


  grant all privileges on wordpress.* to wpuser@localhost identified by 'your-password';
  grant all privileges on wordpress.* to [/cdn-cgi/l/email-protection <nowiki>[email protected]</nowiki>] identified by 'your-password';


  flush privileges;
  flush privileges;


  exit;
  exit;
===Configure WordPress===
===Configure WordPress===
  cd /var/www/wordpress
  cd /var/www/wordpress


Line 33: Line 27:


  sudo vim wp-config.php
  sudo vim wp-config.php
Temukan baris berikut dan ganti teks merah dengan nama database, nama pengguna, dan kata sandi yang Anda buat pada langkah sebelumnya.
Temukan baris berikut dan ganti teks merah dengan nama database, nama pengguna, dan kata sandi yang Anda buat pada langkah sebelumnya.
  /** The name of the database for WordPress */
  /** The name of the database for WordPress */
  define('DB_NAME', 'database_name_here');
  define('DB_NAME', 'database_name_here');
Line 44: Line 36:
  /** MySQL database password */
  /** MySQL database password */
  define('DB_PASSWORD', 'password_here');
  define('DB_PASSWORD', 'password_here');
Kemudian gulir ke bawah untuk menemukan baris berikut.
Kemudian gulir ke bawah untuk menemukan baris berikut.
  $table_prefix = 'wp_';
  $table_prefix = 'wp_';
Secara default, setiap nama tabel database WordPress dimulai dengan wp_ sebagai awalan. Sangat disarankan untuk mengubahnya menjadi sesuatu yang lain untuk meningkatkan keamanan. Gunakan karakter acak seperti di bawah ini.
Secara default, setiap nama tabel database WordPress dimulai dengan wp_ sebagai awalan. Sangat disarankan untuk mengubahnya menjadi sesuatu yang lain untuk meningkatkan keamanan. Gunakan karakter acak seperti di bawah ini.
  $table_prefix = '9OzB3g_';
  $table_prefix = '9OzB3g_';
simpan dengan menggunakan tombol <code>esc</code> lalu ketik <code>:wq</code>
simpan dengan menggunakan tombol <code>esc</code> lalu ketik <code>:wq</code>


Kita juga perlu mengatur pengguna Nginx (www-data) sebagai pemilik direktori situs WordPress dengan menggunakan perintah berikut.
Kita juga perlu mengatur pengguna Nginx (www-data) sebagai pemilik direktori situs WordPress dengan menggunakan perintah berikut.
  sudo chown www-data:www-data /var/www/wordpress/ -R
  sudo chown www-data:www-data /var/www/wordpress/ -R
===Create an Nginx Server Block for WordPress===
===Create an Nginx Server Block for WordPress===
  sudo vim /etc/nginx/conf.d/wordpress.conf
  sudo vim /etc/nginx/conf.d/wordpress.conf
Masukkan teks berikut ke dalam file. Ganti teks merah dengan nama domain Anda sendiri. Jangan lupa untuk membuat catatan A untuk nama domain Anda di pengelola DNS Anda.
Masukkan teks berikut ke dalam file. Ganti teks merah dengan nama domain Anda sendiri. Jangan lupa untuk membuat catatan A untuk nama domain Anda di pengelola DNS Anda.
  server {
  server {
   listen 80;
   listen 80;
Line 125: Line 111:
   
   
  }
  }
Simpan dan tutup file. Kemudian uji konfigurasi Nginx.
Simpan dan tutup file. Kemudian uji konfigurasi Nginx.
  sudo nginx -t
  sudo nginx -t


Line 135: Line 119:
==Extension PHP==
==Extension PHP==
  sudo apt install php7.4-mbstring php7.4-xml php7.4-mysql php7.4-common php7.4-gd php7.4-bcmath php7.4-json php7.4-cli php7.4-curl php7.4-zip php-imagick php7.4-fpm php7.4-bcmath
  sudo apt install php7.4-mbstring php7.4-xml php7.4-mysql php7.4-common php7.4-gd php7.4-bcmath php7.4-json php7.4-cli php7.4-curl php7.4-zip php-imagick php7.4-fpm php7.4-bcmath
==Virtual Host Nginx==
==Virtual Host Nginx==
  server {
  server {
Line 179: Line 162:
*[https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/ nginx.com]
*[https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/ nginx.com]
*[https://www.linuxbabe.com/ubuntu/install-wordpress-ubuntu-20-04-nginx-mariadb-php7-4-lemp linuxbabe.com]
*[https://www.linuxbabe.com/ubuntu/install-wordpress-ubuntu-20-04-nginx-mariadb-php7-4-lemp linuxbabe.com]
[[Category:WordPress]]
[[Category:WordPress]]
[[Category:Website]]
[[Category:Web Server]]
[[Category:Server]]
[[Category:Tutorial]]
[[Category:CMS]]

Revision as of 16:55, 22 July 2022

Berikut adalah cara singkat menginstall WordPress di VPS Ubuntu

Installasi

wget https://wordpress.org/latest.zip
sudo apt install unzip
sudo mkdir -p /var/www/wordpress
sudo unzip latest.zip -d /var/www/

Create a Database and User for WordPress Site

Masuk ke database server

sudo mariadb -u root

atau

sudo mysql -u root

Lalu buat database dengan menggunakan perintah berikut

create database wordpress;
grant all privileges on wordpress.* to [/cdn-cgi/l/email-protection [email protected]] identified by 'your-password';
flush privileges;
exit;

Configure WordPress

cd /var/www/wordpress
sudo cp wp-config-sample.php wp-config.php
sudo vim wp-config.php

Temukan baris berikut dan ganti teks merah dengan nama database, nama pengguna, dan kata sandi yang Anda buat pada langkah sebelumnya.

/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');

/** MySQL database username */
define('DB_USER', 'username_here');

/** MySQL database password */
define('DB_PASSWORD', 'password_here');

Kemudian gulir ke bawah untuk menemukan baris berikut.

$table_prefix = 'wp_';

Secara default, setiap nama tabel database WordPress dimulai dengan wp_ sebagai awalan. Sangat disarankan untuk mengubahnya menjadi sesuatu yang lain untuk meningkatkan keamanan. Gunakan karakter acak seperti di bawah ini.

$table_prefix = '9OzB3g_';

simpan dengan menggunakan tombol esc lalu ketik :wq

Kita juga perlu mengatur pengguna Nginx (www-data) sebagai pemilik direktori situs WordPress dengan menggunakan perintah berikut.

sudo chown www-data:www-data /var/www/wordpress/ -R

Create an Nginx Server Block for WordPress

sudo vim /etc/nginx/conf.d/wordpress.conf

Masukkan teks berikut ke dalam file. Ganti teks merah dengan nama domain Anda sendiri. Jangan lupa untuk membuat catatan A untuk nama domain Anda di pengelola DNS Anda.

server {
  listen 80;
  listen [::]:80;
  server_name www.example.com example.com;
  root /var/www/wordpress/;
  index index.php index.html index.htm index.nginx-debian.html;

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

   location ~ ^/wp-json/ {
     rewrite ^/wp-json/(.*?)$ /?rest_route=/$1 last;
   }

  location ~* /wp-sitemap.*\.xml {
    try_files $uri $uri/ /index.php$is_args$args;
  }

  error_page 404 /404.html;
  error_page 500 502 503 504 /50x.html;

  client_max_body_size 20M;

  location = /50x.html {
    root /usr/share/nginx/html;
  }

  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;

    # Add headers to serve security related headers
    add_header X-Content-Type-Options nosniff;
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Permitted-Cross-Domain-Policies none;
    add_header X-Frame-Options "SAMEORIGIN";
  }

  #enable gzip compression
  gzip on;
  gzip_vary on;
  gzip_min_length 1000;
  gzip_comp_level 5;
  gzip_types application/json text/css application/x-javascript application/javascript image/svg+xml;
  gzip_proxied any;

  # A long browser cache lifetime can speed up repeat visits to your page
  location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ {
       access_log        off;
       log_not_found     off;
       expires           360d;
  }

  # disable access to hidden files
  location ~ /\.ht {
      access_log off;
      log_not_found off;
      deny all;
  }

}

Simpan dan tutup file. Kemudian uji konfigurasi Nginx.

sudo nginx -t
sudo systemctl reload nginx
sudo systemctl restart nginx

Extension PHP

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

Virtual Host Nginx

server {
        ## Your website name goes here.
        server_name domain.tld;
        ## Your only path reference.
        root /var/www/wordpress;
        ## This should be in your http block and if it is, it's not needed here.
        index index.php;

        location = /favicon.ico {
                log_not_found off;
                access_log off;
        }

        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
        }

        location / {
                # This is cool because no php is touched for static content.
                # include the "?$args" part so non-default permalinks doesn't break when using query string
                try_files $uri $uri/ /index.php?$args;
        }
        
        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 ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;
       }
}


Source