Cara Install Nginx Mariadb PHP (LEMP) Di VPS Server Centos 7
Performance Apache dikatakan lebih rendah dibandingkan dengan Nginx. Dengan konfigurasi yang benar, mungkin benar. Bagi saya sendiri konfigurasi Nginx lebih mudah dibandingkan dengan konfigurasi Apache. Kalau anda tertarik, kali ini saya akan menuliskan cara dan setup install Nginx, php-fpm dan mariadb server. Silakan lanjut.
Install Nginx
Untuk meng-install nginx, lakukan perintah berikut melalui command line.
yum install nginx
Start nginx
systemctl start nginx
Restart nginx
systemctl restart nginx
Melihat status nginx
systemctl status nginx
Web server nginx seharusnya dapat berjalan pada tahap ini. Kunjungi ip address anda di web browser: http://ip_address, kemudian tekan enter. Jika belum berjalan, silakan lakukan hal berikut:
a. Buat file baru dengan nama index.html dengan isi misalnya "Nginx Centos 7". Letakkan file tersebut di dalam folder /var/www/html.
nano /var/www/html/index.html
b. Sekarang, buka sekali lagi ip dari vps anda atau domain anda lewat browser. Maka akan muncul halaman index.html tersebut.
Install Mariadb Server
Untuk meng-install mariadb server, ketikkan perintah berikut melalui command line dan tekan enter.
yum install mariadb-server
Start mariadb server
systemctl start mariadb
Restart mariadb server
systemctl restart mariadb
Melihat status mariadb server
systemctl status mariadb
Lakukan langkah berikut agar mariadb-server menjadi "secure".
mysql_secure_installation
Pada tahap ini yang terpenting dan perlu diperhatikan adalah :
● Set root password: jawab "y" dan buatlah password
● Remove anonymous users: jawab "y"
● Disallow root login remotely: jawab "y"
● Remove test database and access to it: jawab "y"
● Reload privilege tables now: jawab "y"
Jika anda memerlukan bantuan membuat password yang benar-benar bagus, kunjungi website random.org
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
Untuk login ke mariadb-server, ketik perintah berikut dan tekan tombol enter.
mysql -uroot -p
Kemudian masukkan password anda.
Install PHP
PHP bawaan Centos 7 bukanlah versi PHP 7. Saran saya sih, jangan gunakan php 5 lagi. Oleh karena itu kali ini saya akan menggunakan remirepo. Lakukan langkah berikut secara berurutan:
1. Install remirepo
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
<p></p>
wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
<p></p>
rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm
<p></p>
rpm -i epel-release-latest-7.noarch.rpm
<p></p>
yum install yum-utils
<p></p>
yum-config-manager --enable remi-php73
2. Install php
yum install php73-php-cli php73-php-fpm php73-php-mysqlnd
Start php-fpm server
systemctl start php73-php-fpm
Restart php-fpm server
systemctl restart php73-php-fpm
Melihat status php-fpm server
systemctl status php73-php-fpm
Lakukan editing tambahan konfigurasi nginx agar php dapat berjalan di webserver nginx.
a. Edit konfigurasi nginx
nano /etc/nginx/nginx.conf
Tambahkan baris berikut ke dalam http block.
upstream php {
server 127.0.0.1:9000;
}
Dan jangan lupa, tambahkan pula baris berikut ini ke dalam server block
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass php;
}
Untuk menjaga agar sistem php tetap "secure", anda harus melakukan editing php.ini. Tambahkan baris "cgi.fix_pathinfo = 0" ke dalam php.ini, kemudian restart php-fpm.
b. Buat file php, misalnya info.php. Letakkan file tersebut di folder /var/www/html
nano /var/www/html/info.php
c. Isikan script sederhana berikut ke dalam file info.php
<?php
// Show all information, defaults to INFO_ALL
phpinfo();
// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(INFO_MODULES);
?>
d. Sekarang buka file php tersebut lewat browser: http://ip_address/info.php.
Database Connection
Lakukan hal berikut untuk mengecek apakah sistem mariadb server dapat dikoneksikan dengan sistem php.
a. Login ke mariadb server.
mysql -uroot -p
b. Buat database baru.
create database testinglemp;
c. Buat database user
CREATE USER 'usertestinglemp'@'localhost' IDENTIFIED BY 'Cwo48*&#';
d. Grant all privileges, agar user dapat mengakses ke database yang barusan dibuat.
GRANT ALL PRIVILEGES ON testinglemp.* TO 'usertestinglemp'@'localhost';
e. Buat file konek.php yang berisi script php berikut.
<?php
$servername = "localhost";
$username = "usertesting";
$password = "Cwo48*&#";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
f. Selanjutnya buka halaman ini: http://ip_address/konek.php lewat web browser. Jika terlihat status "Connected successfully", itu tandanya php sudah dapat dikoneksikan dengan mariadb server.
Jika php dapat berkomunikasi dengan database server, anda bisa meng-install aplikasi php di sistem LEMP Centos 7. Anda bisa install joomla, wordpress, moodle dan lain sebagainya.
Tags :