When creating a new server for a client that wants to run Nginx, you’ll need to adapt the virtual host
configuration to properly serve requests.
After modification the server block should look like this:
server {
listen 80;
server_name example.com www.example.com;
root /var/www/vhosts/example.com;
..
location /phpMyAdmin {
root /usr/share/;
index index.php;
auth_basic “phpMyAdmin Login”;
auth_basic_user_file /etc/phpMyAdmin/phpmyadmin-htpasswd;
location ~\.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm.sock;
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;
}
…
}
Check the work:
- nginx -t
Once you get the all clear:
- service nginx reload
You can test with the credentials located in /root/.phpmyadminpass.
NOTE: You may need to adjust the permissions on /etc/phpMyAdmin to allow the Nginx user/group to read the config.inc.php file if you are changing it to connect to a remote database (DBaaS for instance):
- chown -R root:nginx /etc/phpMyAdmin