Jump to content

WordPress:Installasi di VPS: Difference between revisions

From Wiki
No edit summary
 
(3 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==


==Installasi==
<syntaxhighlight lang="bash">
wget https://wordpress.org/latest.zip
wget https://wordpress.org/latest.zip
</syntaxhighlight>


sudo apt install unzip
<syntaxhighlight lang="bash">
sudo apt install unzip
</syntaxhighlight>


sudo mkdir -p /var/www/wordpress
<syntaxhighlight lang="bash">
sudo mkdir -p /var/www/wordpress
</syntaxhighlight>


sudo unzip latest.zip -d /var/www/
<syntaxhighlight lang="bash">
sudo unzip latest.zip -d /var/www/
</syntaxhighlight>


===Create a Database and User for WordPress Site===
===Create a Database and User for WordPress Site===
sudo mariadb -u root
Masuk ke database server
 
<syntaxhighlight lang="bash">
sudo mariadb -u root
</syntaxhighlight>


atau
atau
sudo mysql -u root


create database wordpress;
<syntaxhighlight lang="bash">
sudo mysql -u root
</syntaxhighlight>


grant all privileges on wordpress.* to wpuser@localhost identified by 'your-password';
Lalu buat database dengan menggunakan perintah berikut


flush privileges;
<syntaxhighlight lang="sql">
create database wordpress;
</syntaxhighlight>


exit;
<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===
===Configure WordPress===


cd /var/www/wordpress
<syntaxhighlight lang="bash">
cd /var/www/wordpress
</syntaxhighlight>


sudo cp wp-config-sample.php wp-config.php
<syntaxhighlight lang="bash">
sudo cp wp-config-sample.php wp-config.php
</syntaxhighlight>


sudo vim wp-config.php
<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.
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 */
<syntaxhighlight lang="php">
/** The name of the database for WordPress */
  define('DB_NAME', 'database_name_here');
  define('DB_NAME', 'database_name_here');
   
   
Line 42: Line 74:
  /** MySQL database password */
  /** MySQL database password */
  define('DB_PASSWORD', 'password_here');
  define('DB_PASSWORD', 'password_here');
</syntaxhighlight>


Kemudian gulir ke bawah untuk menemukan baris berikut.
Kemudian gulir ke bawah untuk menemukan baris berikut.
$table_prefix = 'wp_';
 
<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.
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_';
 
<syntaxhighlight lang="php">
$table_prefix = '9OzB3g_';
</syntaxhighlight>


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
 
<syntaxhighlight lang="bash">
sudo chown www-data:www-data /var/www/wordpress/ -R
</syntaxhighlight>


===Create an Nginx Server Block for WordPress===
===Create an Nginx Server Block for WordPress===
sudo vim /etc/nginx/conf.d/wordpress.conf
 
<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.
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 {
  server {
   listen 80;
   listen 80;
Line 123: Line 169:
   
   
  }
  }
</syntaxhighlight>


Simpan dan tutup file. Kemudian uji konfigurasi Nginx.
Simpan dan tutup file. Kemudian uji konfigurasi Nginx.


sudo nginx -t
<syntaxhighlight lang="bash">
sudo nginx -t
</syntaxhighlight>
 
<syntaxhighlight lang="bash">
sudo systemctl reload nginx
</syntaxhighlight>


sudo systemctl reload nginx
<syntaxhighlight lang="bash">
sudo systemctl restart nginx
</syntaxhighlight>


sudo systemctl restart nginx
==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 171: Line 231:
         }
         }
  }
  }
 
</syntaxhighlight>


==Source==
==Source==
Line 178: Line 238:


[[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