GNU/Linux >> Belajar Linux >  >> Ubuntu

Cara Menginstal WordPress 5.x Dengan Nginx Di Ubuntu 18.04 / Ubuntu 16.04

WordPress adalah perangkat lunak blogging dan manajemen konten open-source yang paling banyak digunakan yang mendukung sekitar 60 juta situs web. Itu ditulis dalam PHP dan menggunakan MariaDB / MySQL sebagai database.

Tutorial ini membantu Anda cara menginstal WordPress 5.x dengan Nginx di Ubuntu 18.04 / Ubuntu 16.04.

Kami juga akan melihat cara menginstal Let's Encrypt SSL untuk WordPress untuk pengiriman situs web yang aman.

Instal LEMP Stack

Sebelum melanjutkan, Anda mungkin ingin melihat cara memasang tumpukan LEMP.

Instal LEMP (Nginx, MariaDB, dan PHP) Stack di Ubuntu 18.04

Instal LEMP (Nginx, MariaDB, dan PHP) Stack di Ubuntu 16.04

Instal Ekstensi PHP

Ekstensi berikut diperlukan untuk menginstal dan menjalankan WordPress di OS Ubuntu.

sudo apt install -y php-mysql php-dom php-simplexml php-ssh2 php-xml php-xmlreader php-curl php-exif php-ftp php-gd php-iconv php-imagick php-json php-mbstring php-posix php-sockets php-tokenizer

Konfigurasi Blok Server Nginx Untuk WordPress

Mari kita buat blok server Nginx untuk instalasi WordPress. File konfigurasi virtual host dapat ditemukan di direktori /etc/nginx/conf.d.

Blok server memerlukan nama domain, nomor port, root dokumen, lokasi log, CGI cepat, dll.

Asumsikan berikut ini,

Nama Domain: www.itzgeek.net
Akar Dokumen: /sites/www.itzgeek.net/public_html/
Log: /sites/www.itzgeek.net/logs/

Buat host virtual.

Jika Anda telah menginstal Nginx dari repositori Ubuntu, file konfigurasi virtual host dapat ditemukan di /etc/nginx/sites-enabled, dan jalur file akan seperti /etc/nginx/sites-enabled/www.itzgeek.net.conf.
sudo nano /etc/nginx/conf.d/www.itzgeek.net.conf

Tempatkan konten berikut.

server {
	listen 80; 
	server_name www.itzgeek.net;

	root /sites/www.itzgeek.net/public_html/;

	index index.html index.php;

	access_log /sites/www.itzgeek.net/logs/access.log;
	error_log /sites/www.itzgeek.net/logs/error.log;

	# Don't allow pages to be rendered in an iframe on external domains.
	add_header X-Frame-Options "SAMEORIGIN";

	# MIME sniffing prevention
	add_header X-Content-Type-Options "nosniff";

	# Enable cross-site scripting filter in supported browsers.
	add_header X-Xss-Protection "1; mode=block";

	# Prevent access to hidden files
	location ~* /\.(?!well-known\/) {
		deny all;
	}

	# Prevent access to certain file extensions
	location ~\.(ini|log|conf)$ {
		deny all;
	}
        
        # Enable WordPress Permananent Links
	location / {
		try_files $uri $uri/ /index.php?$args;
	}

	location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
	}

}

Buat direktori root dan log dokumen.

sudo mkdir -p /sites/www.itzgeek.net/public_html/

sudo mkdir -p /sites/www.itzgeek.net/logs/

Verifikasi file konfigurasi.

sudo nginx -t

Jika Anda mendapatkan yang berikut ini, berarti entri virtual host sudah benar.

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Mulai ulang layanan.

sudo systemctl restart nginx

Instal Let's Encrypt SSL untuk WordPress (Opsional)

Dalam situasi saat ini, hampir semua situs web menggunakan HTTPS (sertifikat SSL) untuk keaslian, akun yang aman, untuk menjaga komunikasi pengguna tetap pribadi. Google meminta pemilik untuk beralih ke HTTPS untuk keamanan yang lebih baik dan meningkatkan peringkat.

Instal Certbot

Untuk menghasilkan sertifikat SSL, instal klien Certbot ACME di sistem Anda. Ini menangani penerbitan sertifikat dan pemasangan sertifikat tanpa waktu henti.

Klien Certbot tidak tersedia di repositori Ubuntu. Jadi, kita perlu mengkonfigurasi Certbot PPA di Ubuntu.

sudo apt update

sudo apt install -y software-properties-common

sudo add-apt-repository universe

sudo add-apt-repository ppa:certbot/certbot

sudo apt update

Sekarang, instal klien certbot.

sudo apt install -y certbot python-certbot-nginx

Perbarui / Ubah Catatan DNS

Akses registrar domain Anda dan buat data A/CNAME untuk domain Anda.

Tunggu beberapa saat hingga rekaman menyebar.

Instal Let's Encrypt SSL Certificate

Gunakan perintah certbot untuk membuat dan menginstal sertifikat Let's Encrypt.

sudo certbot --nginx

Keluaran:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]  << Enter email id to receive notification

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A  << Accept Terms of Service

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y  << Subscribe to newsletter

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: www.itzgeek.net
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1  << Install SSL certificate for www.itzgeek.net
Deploying Certificate to VirtualHost /etc/nginx/conf.d/www.itzgeek.net.conf

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2  < Redirect HTTP traffic to HTTPS site
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/www.itzgeek.net.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://www.itzgeek.net

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=www.itzgeek.net
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:                                                                                                   
 - Congratulations! Your certificate and chain have been saved at:                                                 
   /etc/letsencrypt/live/www.itzgeek.net/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/www.itzgeek.net/privkey.pem
   Your cert will expire on 2019-12-12. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

Arahkan permintaan HTTP non-www ke www HTTPS dengan Nginx

Kami sekarang akan membuat blok server baru untuk mengarahkan lalu lintas yang datang untuk situs HTTP non-www ke situs HTTPS www. Yaitu, http://itzgeek.net>> https://www.itzgeek.net .

sudo nano /etc/nginx/conf.d/www.itzgeek.net.conf

Tambahkan blok di bawah ini di akhir file.

# Redirect NON-WWW HTTP to WWW HTTPS

server {
    if ($host = itzgeek.net) {
        return 301 https://www.itzgeek.net$request_uri;
    }


   server_name itzgeek.net;
    listen 80;
    return 404;

}

Mulai ulang layanan Nginx.

sudo systemctl restart nginx

Buat Basis Data Untuk WordPress

Masuk ke MySQL.

sudo mysql -u root -p

Buat database yang diinginkan untuk WordPress.

CREATE DATABASE wordpress;

Buat pengguna.

CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'wppassword';

Berikan izin kepada pengguna yang dibuat untuk mengakses database.

GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';

Keluar dari shell MariaDB.

quit

Unduh WordPress

Unduh paket WordPress terbaru.

wget http://wordpress.org/latest.tar.gz

Ekstrak paket WordPress.

tar -zxvf latest.tar.gz

Pindahkan file WordPress ke root dokumen.

sudo mv wordpress/* /sites/www.itzgeek.net/public_html/

Jadikan pengguna Apache (www-data) sebagai pemilik situs WordPress.

sudo chown -R www-data:www-data /sites/www.itzgeek.net/public_html/

sudo chown -R www-data:www-data /sites/www.itzgeek.net/logs/

Instal WordPress

Buka browser Anda dan kunjungi:

http://url-situs-web-anda

Anda akan mendapatkan wizard penginstalan WordPress.

Pilih bahasa untuk instalasi WordPress Anda.

Pastikan Anda memiliki nama database WordPress, pengguna database, dan kata sandi pengguna database. Jika sudah siap, klik tombol Let's go!.

Di halaman ini, masukkan informasi database agar WordPress terhubung dengan database.

Jika koneksi ke database berhasil, Anda akan mendapatkan halaman di bawah ini. Klik Jalankan Instalasi.

Di halaman ini, masukkan judul situs, admin WordPress, dan kata sandi (pilihan Anda) dan kemudian alamat email. Kemudian, klik Instal WordPress.

Instalasi WordPress sekarang selesai. Anda dapat mengklik Login untuk membuka halaman Admin WordPress.

Masukkan pengguna admin WordPress dan kata sandinya untuk mengakses halaman Admin WordPress.

Admin WordPress:

Frontend WordPress:

Informasi server WordPress (plugin Informasi Server YLD):

Beberapa Konfigurasi Ekstra

Konfigurasi Unggahan Ukuran File Maksimum untuk WordPress

Secara default, PHP tidak mengizinkan unggahan web di atas 2MB. Untuk mengizinkan unggahan file yang lebih besar melalui antarmuka web WordPress, konfigurasikan pengaturan upload_max_filesize di php.ini.

sudo nano /etc/php/7.2/fpm/php.ini

Ubah ukuran unggahan sesuai kebutuhan Anda

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 256M

Mulai ulang layanan php7.2-fpm.

sudo systemctl restart php7.2-fpm

Konfigurasikan client_max_body_size di Nginx untuk WordPress

Anda mungkin mengalami kesalahan di bawah ini meskipun Anda telah mengubah ukuran file unggahan maksimum pada langkah sebelumnya.

2019/09/13 04:40:08 [error] 3803#3803: *517 client intended to send too large body: 9872781 bytes, client: 49.207.143.143, server: www.itzgeek.net, request: "POST /wp-admin/update.php?action=upload-theme HTTP/1.1", host: "www.itzgeek.net", referrer: "https://www.itzgeek.net/wp-admin/theme-install.php?browse=featured"

Tambahkan modul inti client_max_body_size di file konfigurasi server Nginx.

sudo nano /etc/nginx/nginx.conf

Arahan dapat ditambahkan ke blok http (untuk semua situs), blok server tertentu, atau dalam konteks lokasi. Saya menambahkan arahan ke blok http yang menetapkan nilai untuk semua situs yang berjalan di server ini.

http {
....

    client_max_body_size 256M;

....
}

Juga, kita harus mengubah nilai post_max_size di php7.2-fpm.

sudo nano /etc/php/7.2/fpm/php.ini

Ubah ukuran unggahan sesuai kebutuhan Anda.

post_max_size = 256M

Mulai ulang layanan.

sudo systemctl restart php7.2-fpm

sudo systemctl restart nginx

Kesimpulan

Itu saja. Saya harap Anda telah mempelajari cara menginstal WordPress 5.x dengan Nginx di Ubuntu 18.04 / Ubuntu 16.04. Silakan bagikan tanggapan Anda di bagian komentar.


Ubuntu
  1. Cara Menginstal WordPress Menggunakan Nginx di Ubuntu 18.04

  2. Cara menginstal Elgg dengan Nginx di Ubuntu 14.04

  3. Cara Menginstal Nginx di Ubuntu 16.04

  1. Cara Menginstal Nginx di Ubuntu 16.04

  2. Cara Menginstal WordPress dengan Nginx di Ubuntu 18.04

  3. Cara Menginstal Joomla dengan Nginx di Ubuntu 18.04

  1. Cara Menginstal MediaWiki dengan Nginx di Ubuntu 16.04

  2. Cara Menginstal Magento dengan Nginx di Ubuntu 15.10

  3. Cara Menginstal Mailpile dengan Nginx di Ubuntu 15.10