How to Install phpMyAdmin With Nginx on CentOS 7
Update Server
Login as root to the server and update the server with the following commands:
$ yum update -y
$ reboot
Install Packages
Install some packages that CentOS 7 requires.
$ yum install wget nano perl zip unzip -y
Install Firewall
Before starting, you need to install a Firewall to make it more secure. In this Firewall using CSF (ConfigServer Security & Firewall). Install it with the command below:
$ cd /usr/src
$ wget https://download.configserver.com/csf.tgz
$ tar -xzf csf.tgz
$ cd csf/
$ sh install.sh
In the CSF configuration change "make TESTING='1' to 0".
$ nano /etc/csf/csf.conf
Then add port 9000 to TCP_Out and TCP_In for phpMyAdmin purposes.
Then restart CSF to reload the updated configuration.
$ csf -r
Install Nginx WebServer
Since this article is about Nginx, it is necessary to install Nginx WebServer with the command below.
$ yum install nginx -y
Check which version of nginx you are using:
$ nginx -v
nginx version: nginx/1.16.1
The version we installed is currently 1.16.1, there may be differences with what you install later, depending on the latest update of the nginx version.
Start and enable on-boot nginx:
$ systemctl start nginx
$ systemctl enable nginx
Install PHP 7.2
For PHP, we use version 7.2, install php 7.2 along with several extensions needed. Before installing PHP 7.2, you need to enable Remi Repo first.
$ yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
$ yum install yum-utils -y
$ yum update -y
$ yum install php72-php-gd php72-php-json php72-php-mbstring php72-php-mysqlnd php72-php-xml php72-php-xmlrpc php72-php-opcache -y
Install PHP-FPM
PHP-FPM (FastCGI Process Manager) is an alternative to the FastCGI implementation for the PHP programming language. PHP-FPM is also a PHP interpreter that is separate from the web server, so that every request for PHP scripts that enter the web server will be forwarded or forwarded to FastCGI via a TCP / IP connection socket. To install PHP-FPM like the command below.$ yum install php-fpm -y
Start and enable on-boot php-fpm:
$ systemctl start php-fpm
$ systemctl enable php-fpm
Check whether php-fpm is active or not:$ systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process Manager Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled) Active: active (running) since Tue 2020-11-17 16:32:52 UTC; 18min ago Main PID: 6922 (php-fpm) Status: "Processes active: 0, idle: 5, Requests: 32, slow: 0, Traffic: 0req/sec" CGroup: /system.slice/php-fpm.service ├─6922 php-fpm: master process (/etc/php-fpm.conf) ├─6924 php-fpm: pool www ├─6925 php-fpm: pool www ├─6926 php-fpm: pool www ├─6927 php-fpm: pool www └─6928 php-fpm: pool www
Restart php-fpm:
$ systemctl restart php-fpm
Install Database Server
For the database server, we use MariaDB, as it is the most up-to-date and compatible at the moment.$ yum install mariadb-server mariadb -y
Start and enable on-boot for MariaDB services and then perform secure installation
$ systemctl enable mariadb
$ systemctl start mariadb
$ mysql_secure_installation
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!
Remove anonymous users? [Y/n] y ... Success!
Disallow root login remotely? [Y/n] y ... Success!
Remove test database and access to it? [Y/n] y - Dropping test database... ... Success! - Removing privileges on test database... ... Success!
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!
In the current password for root just enter it, then in the set root password select Y. Then next select Y all until the secure process is complete.
Check whether MariaDB is active or not:
$ systemctl status mariadb
● mariadb.service - MariaDB database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled) Active: active (running) since Tue 2020-11-17 17:21:53 UTC; 24s ago Process: 9625 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS) Process: 9542 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS) Main PID: 9624 (mysqld_safe)
Install phpMyAdmin
There are 2 ways to install phpMyAdmin, the first is directly using the YUM package manager, which is from the official CentOS or wget packages from the official phpMyAdmin website. For the phpMyAdmin installation in this article, we use the first way; namely install via YUM package manager.
$ yum install phpmyadmin -y
Config phpMyAdmin
After completing the phpMyAdmin installation, it is necessary to configure a virtual host for phpMyAdmin on Nginx. Because virtual hosts must be created manually, not automatically.
Create directory snippets:
$ mkdir -p /etc/nginx/snippets
Buat file phpMyAdmin.conf
$ nano /etc/nginx/snippets/phpMyAdmin.conf
Past the script below into the configuration file above.
location /phpMyAdmin { root /usr/share/; index index.php index.html index.htm; location ~ ^/phpMyAdmin/(.+\.php)$ { try_files $uri =404; root /usr/share/; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include /etc/nginx/fastcgi_params; }
location ~* ^/phpMyAdmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ { root /usr/share/; }
} location /phpmyadmin { rewrite ^/* /phpMyAdmin last; }
Tambahkan include snippets/phpMyAdmin.conf pada virtual host domain kamu. $ nano /etc/nginx/conf.d/vps201.dewiweb.net
server {
# . . .code
#phpMyAdmin include snippets/phpMyAdmin.conf;
# . . . code
}
In the middle of the other code, add include snippets/phpMyAdmin.conf.
If so, save and exit.
Check the configuration whether there are syntax errors or not:
$ nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Reload nginx:
$ systemctl reload nginx
Create a session directory for phpMyAdmin session purposes:$ mkdir -p /var/lib/php/session/
$ chown -R nginx:nginx /var/lib/php/session/
$ chmod 777 /var/lib/php/session/
Testing
If so, access the domain/phpMyAdmin and you will see the login page as below.
Using Username root.
As for the Password, use it when you do a secure installation of Mariadb before.
Then the result will be as below.