WordPress:Installasi di VPS: Difference between revisions
No edit summary |
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== | |||
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=== | |||
sudo mariadb -u root | |||
atau | |||
sudo mysql -u root | |||
create database wordpress; | |||
grant all privileges on wordpress.* to wpuser@localhost 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 <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. | |||
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== | ==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 | 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 | ||
Revision as of 16:47, 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
sudo mariadb -u root
atau
sudo mysql -u root
create database wordpress;
grant all privileges on wordpress.* to wpuser@localhost 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
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;
}
}