in FOSS

Cara Install WordPress dengan Nginx dan PHP 7.4 di CentOS 7

Cara Install WordPress dengan Nginx dan PHP 7.4 di CentOS 7

Tutorial kali ini membahas tentang bagaimana cara install WordPress dengan Nginx web server dipasangkan dengan PHP v7.4 dan MariaDB database atau lebih populer disingkat menjadi LEMP (Linux Nginx MySQL/MariaDB PHP).

0.Update System

Update CentOS dan install EPEL repository.

yum update -y	
yum install epel-release -y

1.Install Nginx

Install Nginx.

yum install nginx -y

Aktifkan dan jalankan Nginx service.

systemctl enable nginx	
systemctl start nginx	
systemctl status nginx	
Nginx service status

Nginx service status

2.Install PHP 7.4

Install yum-utils dan REMI repository.

yum install yum-utils -y
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y	

Verifikasi hasil install REMI repository, lihat isi direktori yum.repos.d.

ls -l /etc/yum.repos.d	
yum.repos.d directory

yum.repos.d directory

Aktifkan REMI PHP7.4 repository.

yum-config-manager --enable remi-php74	

Install PHP 7.4 beserta extension yang dibutuhkan.

yum install php74-php php74-php-fpm php74-php-gd php74-php-json php74-php-mbstring php74-php-mysqlnd php74-php-xml php74-php-xmlrpc php74-php-opcache -y

Buat symbolic link php ke php74 dan cek PHP yang telah terinstall.

ln -s /usr/bin/php74 /usr/bin/php
php -v	
Command php -v

Command php -v

Konfigurasi PHP-FPM.

vi /etc/opt/remi/php74/php-fpm.d/www.conf	

Ubah opsi seperti di bawah ini.

...
user = nginx
...
group = nginx
...
listen = /run/php74-fpm.sock
...
listen.owner = nginx
listen.group = nginx
listen.mode = 0660 	

Jalankan PHP-FPM service.

systemctl enable php74-php-fpm	
systemctl start php74-php-fpm	
systemctl status php74-php-fpm	
PHP-FPM service status

PHP-FPM service status

3.Membuat Nginx Server Block

Membuat file konfigurasi server block, ganti DOMAIN.COM dengan nama domain yang anda gunakan.

vi /etc/nginx/conf.d/DOMAIN.COM.conf	

Script konfigurasi server block.

server {
    listen 80;
    server_name DOMAIN.COM www.DOMAIN.COM;
    root /var/www/DOMAIN.COM;
    index index.php index.html index.htm;

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

    location ~ \.php$ {
        try_files $fastcgi_script_name =404;
        include fastcgi_params;
        fastcgi_pass                   unix:/run/php74-fpm.sock;
        fastcgi_index                  index.php;
        fastcgi_param DOCUMENT_ROOT    $realpath_root;
        fastcgi_param SCRIPT_FILENAME  $realpath_root$fastcgi_script_name;
    }

    access_log /var/log/nginx/DOMAIN.COM.access.log;
    error_log /var/log/nginx/DOMAIN.COM.error.log;
}	

Membuat root directory dan file info.php.

mkdir /var/www/DOMAIN.COM
echo "" > /var/www/DOMAIN.COM/info.php	

Uji konfigurasi dan restart Nginx service.

nginx -t
systemctl restart nginx
systemctl status nginx

Uji apakah Nginx sudah bisa menjalankan script PHP dengan mengakses info.php.

Browse http://DOMAIN.COM/info.php.

PHP Information

PHP Information

4.Install MariaDB

Membuat file MariaDB repository versi 10.4.

vi /etc/yum.repos.d/mariadb.repo	

Script mariadb.repo.

# MariaDB 10.4 CentOS repository list - created 2020-06-22 11:29 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1	

Install MariaDB.

yum install MariaDB-server MariaDB-client -y	

Aktifkan dan jalankan MariaDB service.

systemctl enable mariadb	
systemctl start mariadb	
systemctl status mariadb
MariaDB service status

MariaDB service status

Amanakan instalasi MariaDB.

mysql_secure_installation	

Jawab pertanyaan yang ditampilkan.

Enter current password for root (enter for none): ENTER
Switch to unix_socket authentication [Y/n] y
Change the root password? [Y/n] y
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y	

Login ke MariaDB.

mysql -u root -p	

Membuat database, user, dan password, serta memberikan hak akses database ke user.

create database NAMADB;
create user 'USERDB'@'localhost' identified by 'PASSDB';
grant all privileges on NAMADB.* to 'USERDB'@'localhost';
flush privileges;	

5.Install WordPress

Download WordPress terbaru.

curl -O https://wordpress.org/latest.tar.gz

Extract latest.tar.gz.

tar xzvf latest.tar.gz	

Copy isi direktori wordpress ke root directory.

cp -Rv wordpress/* /var/www/DOMAIN.COM	

Ubah owner dan permission root directory.

chown -R nginx:nginx /var/www/DOMAIN.COM
chmod -R 755 /var/www/DOMAIN.COM

Browse http://DOMAIN.COM.

  1. Pemilihan bahasa, pakai English (United States). Lalu Continue.
  2. Choose Language

    Choose Language

  3. Let’s go!
  4. Database information

    Database information

  5. Masukkan NAMADB, USERDB, dan PASSDB. Submit.
  6. Copy teks konfigurasi yang ditampilkan.
  7. Script wp-config.php

    Script wp-config.php

  8. Buat file wp-config.php lalu paste teks yang telah dicopy.
    vi /var/www/DOMAIN.COM/wp-config.php	
    
  9. Run the installation.
  10. Masukkan Site Title, Username, Password, Your Email. Install WordPress.
  11. Website information

    Website information

  12. WordPress telah selesai diinstall.
  13. Klik Log In untuk login ke dashboard.
  14. WordPress installed

    WordPress installed

6.Selesai

Halaman depan http://DOMAIN.COM.

WordPress site

WordPress site

Halaman dashboard http://DOMAIN.COM/wp-admin.

WordPress dashboard

WordPress dashboard

Selamat mencoba 🙂

Write a Comment

Comment