Tag Archives: nginx

Configuring phpmyadmin with nginx

Install the php dependencies

apt-get install phpmyadmin php5-fpm

Modify /etc/nginx/sites-available/default and add the following at the end of the server section

location ^~ /phpmyadmin {
    alias /usr/share/phpmyadmin/;
    index index.php index.html index.htm;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

To restrict access to a certain IP, add the following just below the index line that you have just added…

allow 127.0.0.1;
allow 1.2.3.4;
deny all;

enable mcrypt extension

php5enmod mcrypt

restart nginx & php5

service restart nginx
service restart php5-fpm

Hosting multiple sites/domains on nginx

Create a folder for your new domain within nginx

mkdir -p /var/www/yourdomain.com/public_html

Fix up the permissions

chown -R www-data:www-data /var/www/yourdomain.com/public_html
chmod 755 /var/www

Create a simple page to serve

Add the following to /var/www/yourdomain.com/public_html/index.html

<html>
  <head>
    <title>www.yourdomain.com</title>
  </head>
  <body>
    <h1>Success: You Have Set Up a Virtual Host</h1>
  </body>
</html>

Create and modify the new virtual host config

cp /etc/nginx/sites-available/default /etc/nginx/sites-available/yourdomain.com

Edit the new file and modify the following areas in the server section

listen 80;
#listen [::]:80 default_server ipv6only=on;
root /var/www/yourdomain.com/public_html;
index index.php index.html index.htm;
server_name yourdomain.com;

Enable the virtual host

ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/yourdomain.com

Restart nginx

service nginx restart