Products & Services Submit a ticket My Tickets
Selamat datang
Masuk  Mendaftar

Install LEMP (nginx) di Centos 7

A. Install NGINX di centos 7


1. Default repo centos nginx tidak available, kita butuh install EPEL repository


# yum install epel-release -y

2. Install Nginx


# yum install nginx -y

3. Aktifkan Nginx


# systemctl start nginx
# systemctl enable nginx

4. Cek Nginx sudah running atau tidak dengan mengakses IP Public server. Jika tidak bisa diakses coba set firewall :


# sudo firewall-cmd --permanent --zone=public --add-service=http
# sudo firewall-cmd --permanent --zone=public --add-service=https
# sudo firewall-cmd --reload


B. Install MySQL (mariadb)


1. mariadb sudah include pada reository default centos. langsung saja install mariadb


# yum install mariadb-server mariadb -y

2. Aktifkan mariadb


# systemctl start mariadb
# systemctl enable mariadb

3. Untuk menginstall mariadb dengan pengaturan yang aman.


# mysql_secure_installation

Change the root password? [Y/n] n
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

Additional aja, Jika ingin membuat userbaru bisa gunakan step :


# mysql
> CREATE USER 'usernamebaru'@'localhost' IDENTIFIED BY 'passwordbaru';
GRANT ALL PRIVILEGES ON * . * TO 'usernamebaru'@'localhost';


C. Install PHP v7.4


1. Kita perlu mengunduh dan menginstal repositori CentOS tambahan yang berisi paket-paket yang diperlukan untuk PHP v74


# wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
# rpm -Uvh remi-release-7.rpm

2. Enable php74 repositori, yang default nya disable


# yum install yum-utils -y
# yum-config-manager --enable remi-php74

3. Install paket php


# yum --enablerepo=remi,remi-php74 install php-fpm php-common

4. Install php modul, untuk memastikan service berjalan dengan baik


# yum --enablerepo=remi,remi-php74 install php-opcache php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongodb php-pecl-redis php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml

D. Konfigurasi Nginx agar bekerja dengan php


1. Buat nginx configuration file


# nano /etc/nginx/conf.d/default.conf

tambahkan scrip berikut, pastikan bagian your_server_ip replace dengan IP server :

server {
listen 80;
server_name your_server_ip;

# note that these lines are originally from the "location /" block
root /usr/share/nginx/html;
index index.php index.html index.htm;

location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

location ~ .php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

2. Save, lalu restart service nginx


# systemctl restart nginx

3. Edit PHP-FPM file


# nano /etc/php-fpm.d/www.conf

cari dan ganti bagian berikut ;


user = apache menjadi user = nginx
group = nginx menjadi group = nginx
;listen.owner = nobody menjadi listen.owner = nginx
;listen.group = nginx menjadi listen.group = nginx
listen = 127.0.0.1:9000 menjadi ;listen = 127.0.0.1:9000, lalu dibawahnya tambahkan
listen = /var/run/php-fpm/php-fpm.sock

4. Save, lalu aktifkan php-fpm


# systemctl start php-fpm.service
# systemctl enable php-fpm.service


E. Install phpmyadmin


1. Langkah terakhir adalah memasang phpmyadmin yang berfungsi untuk konfigurasi database baik itu export maupun import pada server


# yum -y install phpMyAdmin

2. Link agar dapat diakses http://xxx.xxx.xxx.xxx/phpMyAdmin/, login menggunakan root mariadb


# ln -s /usr/share/phpMyAdmin /usr/share/nginx/html
# chown -R nginx:nginx /var/lib/php/session
# systemctl restart nginx

Apakah jawaban ini bermanfaat? Ya Tidak

Send feedback
Maaf kami tidak bisa membantu. Bantu kami mengembangkan artikel ini dengan umpan balik Anda.