Jump to content

WordPress:Installasi di VPS: Difference between revisions

From Wiki
No edit summary
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
Berikut adalah cara singkat menginstall [[WordPress]] di VPS [[Ubuntu]]
Berikut adalah cara singkat menginstall [[WordPress]] di VPS [[Ubuntu]]
==Installasi==
<syntaxhighlight lang="bash">
wget https://wordpress.org/latest.zip
</syntaxhighlight>
<syntaxhighlight lang="bash">
sudo apt install unzip
</syntaxhighlight>
<syntaxhighlight lang="bash">
sudo mkdir -p /var/www/wordpress
</syntaxhighlight>
<syntaxhighlight lang="bash">
sudo unzip latest.zip -d /var/www/
</syntaxhighlight>
===Create a Database and User for WordPress Site===
Masuk ke database server
<syntaxhighlight lang="bash">
sudo mariadb -u root
</syntaxhighlight>
atau
<syntaxhighlight lang="bash">
sudo mysql -u root
</syntaxhighlight>
Lalu buat database dengan menggunakan perintah berikut
<syntaxhighlight lang="sql">
create database wordpress;
</syntaxhighlight>
<syntaxhighlight lang="sql">
grant all privileges on wordpress.* to [/cdn-cgi/l/email-protection <nowiki>[email protected]</nowiki>] identified by 'your-password';
</syntaxhighlight>
<syntaxhighlight lang="sql">
flush privileges;
</syntaxhighlight>
<syntaxhighlight lang="sql">
exit;
</syntaxhighlight>
===Configure WordPress===
<syntaxhighlight lang="bash">
cd /var/www/wordpress
</syntaxhighlight>
<syntaxhighlight lang="bash">
sudo cp wp-config-sample.php wp-config.php
</syntaxhighlight>
<syntaxhighlight lang="bash">
sudo vim wp-config.php
</syntaxhighlight>
Temukan baris berikut dan ganti teks merah dengan nama database, nama pengguna, dan kata sandi yang Anda buat pada langkah sebelumnya.
<syntaxhighlight lang="php">
/** 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');
</syntaxhighlight>
Kemudian gulir ke bawah untuk menemukan baris berikut.
<syntaxhighlight lang="php">
$table_prefix = 'wp_';
</syntaxhighlight>
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.
<syntaxhighlight lang="php">
$table_prefix = '9OzB3g_';
</syntaxhighlight>
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.
<syntaxhighlight lang="bash">
sudo chown www-data:www-data /var/www/wordpress/ -R
</syntaxhighlight>
===Create an Nginx Server Block for WordPress===
<syntaxhighlight lang="bash">
sudo vim /etc/nginx/conf.d/wordpress.conf
</syntaxhighlight>
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.
<syntaxhighlight lang="bash">
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;
  }
}
</syntaxhighlight>
Simpan dan tutup file. Kemudian uji konfigurasi Nginx.
<syntaxhighlight lang="bash">
sudo nginx -t
</syntaxhighlight>
<syntaxhighlight lang="bash">
sudo systemctl reload nginx
</syntaxhighlight>
<syntaxhighlight lang="bash">
sudo systemctl restart nginx
</syntaxhighlight>


==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
 
<syntaxhighlight lang="bash">
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
</syntaxhighlight>
 
==Virtual Host Nginx==
==Virtual Host Nginx==
<syntaxhighlight lang="bash">
  server {
  server {
         ## Your website name goes here.
         ## Your website name goes here.
Line 42: Line 231:
         }
         }
  }
  }
 
</syntaxhighlight>


==Source==
==Source==
*[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]
[[Category:WordPress]]
[[Category:WordPress]]
[[Category:Website]]
[[Category:Web Server]]
[[Category:Server]]
[[Category:Tutorial]]
[[Category:CMS]]

Latest revision as of 11:56, 28 November 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 <nowiki>[email protected]</nowiki>] 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