Subscribe
Dapatkan berita terbaru seputar startup dan inspirasi technopreneurship dengan berlangganan newsletter Grevia.

 

Setup server Centos

Setup Nginx http to https

Basic command

shutdown server (halt)
shutdown -h now
restart server now (reload)
shutdown -r now

Pre requisite - Install Nano & Subversion

Install nano & subversion dulu
sudo yum install nano subversion -y

Set Nano as default crontab

buka file berikut
nano /etc/bashrc

tambahkan line berikut di line paling bawah
export EDITOR="nano"

lalu logout dan login lagi. untuk lihat hasilnya
crontab -e
dan voilla... crontab sudah menggunakan nano

ADD Login ssh dengan Public Key

Jika server sudah running dan server belum/ ingin ditambahkan login dengan Private Key silakan baca tutorial ini
Login SSH dan jalankan command ini
nano /root/.ssh/authorized_keys
lalu copaskan isi dari script public key yang berawalan -> rsa_blablablabalbla ke file ini
nano /etc/ssh/sshd_config
rsa key ini bisa lebih dari 1, dipisahkan dengan new line per key seperti berikut
rsa xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
rsa yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
Untuk melihat hasilnya, jangan lupa restart service
/etc/init.d/sshd restart

DISABLE login SSH dengan password

Jika anda telah menggunakan private key untuk login ke SSH, maka sebaiknya login dengan password diblok untuk mengamankan server dari akses dan menghindari brute force.
Buka settingan config SSH
nano /etc/ssh/sshd_config
tekan ctrl+w, lalu cari PermitRootLogin, uncomment dan ubah valuenya jadi
PermitRootLogin without-password
Untuk ubah port default misalnya menjadi 222
Port 222

jika sudah maka reload service ssh
/etc/init.d/sshd restart

Install Plugin Image GD

yum install gd gd-devel php-gd -y
lalu restart nginx
/etc/init.d/nginx restart

Instalasi Webserver NGINX, PHP-FPM, & Timezone

Step One - Install EPEL

EPEL stands for Extra Package Entreprise Linux
sudo yum install epel-release

Step Two - Install Nginx

sudo yum install nginx

Step Three - Start Nginx

sudo /etc/init.d/nginx start

Congratulations you have start your Nginx in your domain.


Step Four - Install PHP-FPM

PHP-FPM is a php render in server. You have to install it first

sudo yum install php-fpm php-mysql -y

Step Five - Start PHP-FPM

Start you php-fpm
sudo /etc/init.d/php-fpm start

Step Six - Checkout repository

Checkout in your root nginx directory to setup you script
cd /usr/share/nginx/html
svn co http://www.grevia.com/repository .
you will be asked for username & password for subversion
*tambahkan jika perlu extended_config.php

Step Six - Checkout repository

Buka
nano /etc/nginx/conf.d/default.conf
isi dengan ini
#
server { listen 80 default_server; listen [::]:80 default_server; server_name s1.grevia.com; error_log /var/log/nginx/error_nginx.log; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { root /usr/share/nginx/html; index index.php index.html index.htm; try_files $uri $uri/ /index.php; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ \.php$ { root /usr/share/nginx/html; index index.php index.html index.htm; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; try_files $uri $uri/ /index.php; } #location ~ \.php { # include /etc/nginx/common/php.conf; #} #sementara jangan pake dlu #error_page 404 /404.html; # location = /40x.html { #} error_page 500 502 503 504 /50x.html; location = /50x.html { }
}

Create bash restart nginx PHP-FPM

buat file bernama restart_nginx_fpm.sh
nano /home/restart_nginx_fpm.sh
Isi dengan ini lalu save
/etc/init.d/php-fpm restart && /etc/init.d/nginx restart
Run command for executable
chmod +x /home/restart_nginx_fpm.sh

Error Code Igniter Session

If showing error Session then run this command
mkdir /var/lib/php/session
chmod -R 777 /var/lib/php/session

Set PHP-FPM untuk merunning Nginx

Buka konfigurasi dengan
nano /etc/php-fpm.d/www.conf
Jika sudah, ketik ctrl+W, lalu cari "http" atau "apache"
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx
dan ganti dengan user = nginx dan group = nginx
lalu buka
nano /etc/nginx/nginx.conf
ganti line ini:
worker_processes auto;
Ganti Auto dengan 4 untuk blabla Restart Nginx
/home/restart_nginx_fpm.sh
And voila... Server sudah berjalan normal

Error Timezone

if error timezone show then run this
nano /etc/php.ini
Then tekan ctrl+w : cari "timezone" ubah jadi Asia/Jakarta
[Date]; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
date.timezone = Asia/Jakarta 

Set Timezone MYSQL

Untuk mengatur timezone UTC di mysql
nano /etc/my.cnf
Ketikan ini di dalam sintaks [mysqld]
default_time_zone='+07:00'
Set Autostart of Nginx, Php FPM and Mysql
sudo chkconfig --levels 235 mysqld on
sudo chkconfig --levels 235 nginx on
sudo chkconfig --levels 235 php-fpm on

Create bash auto svn up

Create file update.sh in your home directory
nano /home/update.sh
Filled update.sh with this for svn update
svn up /usr/share/nginx/html/
Run command for executable
chmod +x /home/update.sh

Set Cron auto update subversion

Untuk mengupdate script tiap ada perubahan / commit ke server repository:
crontab -e
Set update script tiap 2 menit sekali via cron
#cron
*/2 * * * * /home/update.sh
Voilla, script akan mengupdate otomatis

Install imagick

Imagick untuk image manipulation atau cropping
 -- install agar bisa membaca pecl yum install php-pear
 -- install untuk membaca error phpize sudo yum --noplugins install php-devel
 -- install untuk mengsolve error imagick c dependency yum install ImageMagick-devel yum intall gcc
 -- install imagick php 5.3 pecl install imagick-3.1.2
Copyright © 2011 - 2025. Grevia Networks
×