Cara menginstal WordPress dengan CyberPanel di Ubuntu

Best Practice to RUN Litespeed + Cyber Panel in AWS EC2 Instance

Posted on

RUN Litespeed + Cyber Panel in AWS EC2 Instance, Here You Can See how to RUN Litespeed + Cyber Panel I am Changing All My Sites to Litespeed.

Without wasting any time, I am here posting the steps which I do in AWS.

1 – Launch Amazon EC2 Instance ( CentOS )

After Launch – Stop Instance – Create Snapshot of The Volume – Create New Volume from the Snapshot – Delete Old Volume and Snapshot – Attach New Volume to Instance ( mention root directory ) Mostly its /dev/sda1 for Linux ( can be Different for some situations ) – Start Instance.

Create an Elastic IP – Associate with Your Instance. ( Permanent IP for Instance – FREE when it’s associated with an Instance )

NB: This is Good to Avoid Many Future Problems.

2 – Login to SSH

3 – Run

Code:
sudo su -

to Change OS to Root

4 – RUN

Code:
yum -y update

to Update Instance

5 – Follow This Guide to Install Litespeed – https://cyberpanel.net/docs/installing-cyberpanel/

6 – Everything Else for a Website Can be Done Through The Litespeed Cyber Panel.

This is 6 Simple Steps… But I took Many weeks to Learn this Simple Steps.

NB: Before I was doing many things Wrong :) , Now I follow This…

Cara Membersihkan PHP Session Penyebab Inode Di Server Linux Penuh

Dalam kondisi tertentu, kadang saat menggunakan website tidak bisa untuk upload file apapun. biasanya kalau hal ini terjadi ada beberapa hal penyebabnya, bisa dari permission file ataupun disk psace yang penuh. tapi jika sudah di lakukan pengecekan keduanya dan ternyata normal semua, anda perlu mengecek dari sisi inode. bisa jadi, website anda penuh karena inode di server penuh.

Silahkan gunakan perintah berikut untuk mengecek inode server anda:

df -i

sehingga akan menghasilkan seperti berikut:

Filesystem       Inodes   IUsed    IFree IUse% Mounted on
/dev/sda2       1310720 1310720        0  100% /

Dari situ, sudah jelas bahwa penyebab masalah di server adalah inode yang penuh. Untuk mengecek lebih detail darimana penyebab penuhnya, anda bisa melihatnya lewat perintah yang ada di artikel berikut: https://hosteko.com/kb/cara-cek-besar-inode-di-server-linux/

Biasanya, penyebab inode cepat penuh berasal dari PHP SESSION. yang berlokasi di folder /var/lib/php/session dengan isi kurang lebih seperti ini: sess_*

Untuk membersihkannya, anda bisa menggunakan perintah berikut:

find /var/lib/php/session -type f -cmin +24 -name "sess_*" -exec rm -f {} \;

Tetapi kami akan merekomendasikan Anda untuk menggunakan skrip bash, agar kedepan anda tidak perlu repot lagi untuk membersihkan PHP Session:
Sebelum membuat script, periksa dahulu setting PHP anda dan ubah seperti di bawah ini:

; After this number of seconds, stored data will be seen as 'garbage' and
; cleaned up by the garbage collection process.
session.gc_maxlifetime = 1440
 
; NOTE: If you are using the subdirectory option for storing session files
;       (see session.save_path above), then garbage collection does not
;       happen automatically.  You will need to do your own garbage
;       collection through a shell script, cron entry, or some other method.

buat folder di /root dengan nama bebas, misal dalam hal ini saya buat nama hapusphpsession, sehingga alan terbentuk lokasi folder /root/hapusphpsession

silahkan masuk ke folder/ directory /root/hapusphpsession dan buat script berikut dengan di berinama hapus-php-session.sh

#!/bin/bash 
 
# Export bin paths
export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 
# Get PHP Session Details
PHPSESSIONPATH=$(php -i 2>/dev/null | grep -w session.save_path | awk '{print $3}' | head -1);
PHPSESSIONLIFETIME=$(php -i 2>/dev/null | grep -w session.gc_maxlifetime | awk '{print $3}' | head -1);
PHPSESSIONLIFETIMEMINUTE=$( expr $PHPSESSIONLIFETIME / 60 );
 
# If PHPSESSIONPATH exists
if [ -d $PHPSESSIONPATH ];
then
    # Find and delete "expired" sessions
    find $PHPSESSIONPATH -type f -cmin +$PHPSESSIONLIFETIMEMINUTE -name "sess_*" -exec rm -f {} \;
fi

Buat cronjob dengan menjalankan perintah EDITOR=nano crontab -e dengan setting setiap jam sekali.

# Delete PHP sessions
0 * * * * root /root/hapusphpsession/hapus-php-session.sh >/dev/null 2>&1

Mengubah Default PHP Version di Sever Cyberpanel

Secara standar, versi php pada cyberpanel adalah versi 7.1. sehingga kita perlu mengubahnya satu per satu di setiap website, jika ingin mengubah versi php ke yang lain. Namun, di sini anda tidak perlu mengubah satu per satu di setiap website, jika anda mengubahnya lewat CLI. Berikut adalah cara Mengubah Default PHP Version di Sever Cyberpanel:

  • Silahkan login ke root sever cyberpanel anda
  • Jalankan perintah berikut untuk memindahkan dan melakukan backup PHP default
mv /usr/bin/php /root/php-backup
  • Pilih salah satu perintah di bawah ini sesuai dengan versi PHP yang ingin anda inginkan berjalan di server anda.

untuk php 5.6

ln -s /usr/local/lsws/lsphp56/bin/php /usr/bin/php

untuk php 7.0

ln -s /usr/local/lsws/lsphp70/bin/php /usr/bin/php

untuk php 7.1

ln -s /usr/local/lsws/lsphp71/bin/php /usr/bin/php

untuk php 7.2

ln -s /usr/local/lsws/lsphp72/bin/php /usr/bin/php

untuk php 7.3

ln -s /usr/local/lsws/lsphp73/bin/php /usr/bin/php

untuk php 7.4

ln -s /usr/local/lsws/lsphp74/bin/php /usr/bin/php

Silahkan coba cek kembali versi PHP anda dengan menjalankan perintah berikut:

php -v

How to increase the size of my Aws EBS volume

How do I increase the size of my Aws EBS volume if I receive an error that there’s no space left on my file system?

I received an error that there’s no space left on my file system when I tried to increase the size of my Amazon Elastic Block Store (Amazon EBS) volume. How do I fix this?

How To Avoid No space left on Aws

To avoid No space left on device errors when expanding the root partition or root file system on your EBS volume, use the temporary file system, tmpfs, that resides in memory. Mount the tmpfs file system under the /tmp mount point, and then expand your root partition or root file system.

Example

The following example shows that the root EBS volume block device (/dev/nvme0n1) is 9 GiB, and the root partition (partition 1) is already 8 GiB.

$ lsblk
NAME          MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme0n1       259:0    0   9G  0 disk
├─nvme0n1p1   259:1    0   8G  0 part /
└─nvme0n1p128 259:2    0   1M  0 part

If you attempt to increase the root partition (partition 1), you receive one of the following errors:  

$ sudo growpart /dev/nvme0n1 1
/bin/growpart: line 248: /tmp/growpart.fklt5u/dump.out: No space left on device
FAILED: failed to dump sfdisk info for /dev/nvme0n1

-or-

$ sudo growpart /dev/nvme0n1 1
CHANGED: partition=1 start=4096 old: size=16773087 end=16777183 new: size=18870239 end=18874335
FAILED: failed: sfdisk --list /dev/nvme0n1

Note: It’s a best practice to create an Amazon Machine Image (AMI) backup of the instance or a snapshot of the root EBS volume that’s attached to your instance before attempting the resolution steps. A backup allows you to recover your data from unforeseen issues.

Resolution

1.    Connect to your Amazon Elastic Compute Cloud (Amazon EC2) Linux instance using SSH.

2.    Use the df -h command to verify that the root partition mounted under “/” is full (100%). In the following example, /dev/nvme0n1p1 is using 100% of its space.

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        460M     0  475M   0% /dev
tmpfs           478M     0  492M   0% /dev/shm
tmpfs           478M  432K  492M   1% /run
tmpfs           478M     0  492M   0% /sys/fs/cgroup
/dev/nvme0n1p1  8.0G  8.0G  664K 100% /
tmpfs            96M     0   99M   0% /run/user/1000

3.    Run the following commands to gather details about your attached block devices and the root “/” mount point.

$ lsblk
NAME          MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme0n1       259:0    0   9G  0 disk
├─nvme0n1p1   259:1    0   8G  0 part /
└─nvme0n1p128 259:2    0   1M  0 part
$ lsblk -f
NAME          FSTYPE LABEL           UUID                                 MOUNTPOINT
nvme0n1
├─nvme0n1p1   xfs    /               afcf1342-1d40-41bd-bde9-e4ea5d87e3b6 /
└─nvme0n1p128

In the preceding example output, the root EBS volume has 9 GiB of total space but the root partition (/dev/nvme0n1p1) or partition 1, is only 8 GiB. The file system type is XFS.

4.    To avoid a No space left on the block device error, mount the temporary file system tmpfs to the /tmp mount point. This creates a 10 M tmpfs mounted to /tmp.

$ sudo mount -o size=10M,rw,nodev,nosuid -t tmpfs tmpfs /tmp

5.    Run the growpart command to grow the size of the root partition or partition 1. Replace /dev/nvme0n1 with your root partition.

$ sudo growpart /dev/nvme0n1 1 
CHANGED: partition=1 start=4096 old: size=16773087 end=16777183 new: size=18870239 end=18874335

Run the lsblk command to verify that partition 1 is expanded to 9 GiB.

$ lsblk
NAME          MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme0n1       259:0    0   9G  0 disk
├─nvme0n1p1   259:1    0   9G  0 part /
└─nvme0n1p128 259:2    0   1M  0 part

6.    Expand the file system. Refer to step 3 to verify the file system of your root partition “/”.

In the following example, an XFS-type file system is expanded.

$ sudo xfs_growfs -d /
data blocks changed from 2096635 to 2358779
         =                       sectsz=512   sunit=0 blks, lazy-count=1
log      =internal               bsize=4096   blocks=2560, version=2
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
         =                       sunit=0      swidth=0 blks
data     =                       bsize=4096   blocks=2096635, imaxpct=25
         =                       crc=1        finobt=1 spinodes=0
         =                       sectsz=512   attr=2, projid32bit=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
meta-data=/dev/nvme0n1p1         isize=512    agcount=4, agsize=524159 blks

In the following example, an EXT2/EXT3/EXT4 file system on partition 1 is expanded:

$ sudo resize2fs /dev/nvme0n1p1

7.    After expanding the file system, use the df -h command to verify that the OS can see the additional space.

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        960M     0  960M   0% /dev
tmpfs           978M     0  978M   0% /dev/shm
tmpfs           978M  392K  978M   1% /run
tmpfs           978M     0  978M   0% /sys/fs/cgroup
/dev/nvme0n1p1  9.0G  8.0G 1022M  89% /
tmpfs           196M     0  196M   0% /run/user/1000
tmpfs            10M     0   10M   0% /tmp

8.    Run the unmount command to unmount the tmpfs file system.

$ sudo umount /tmp