Categories
Blog

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
Categories
Blog

Enable cross-origin resource sharing for AJAX

A common problem when dealing with AJAX scripts is that the server script (or API) which javascript is calling is required to be on exactly the same domain (subdomain included).  To open up your server script / API to all domains the following headers are required to be sent before any content:

Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: X-Requested-With

In PHP the code would be:

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: X-Requested-With');

If you are using a single script that contains both the API and the regular page (even with includes), the headers must be sent before it is determined whether it is an API call or not.  This is due to a ‘pre-flight request‘ the browser does to test that the impending AJAX call is all approved and above board.  Once it receives the a-ok it will do a second call with the full AJAX credentials.

Categories
Blog

Installing HHVM on Amazon Linux (AWS)

HHVM

Alternative to PHP, said to increase speed by up to 40%.  Works similar to java in that it pre-compiles PHP automatically to speed up execution time.  Used by facebook.

cd /etc/yum.repos.d
wget http://www.hop5.in/yum/el6/hop5.repo
echo 'priority=9' >> hop5.repo
echo 'includepkgs=glog,tbb' >> hop5.repo
wget http://yum.sexydev.com/sexydev-amazon.repo
yum install hhvm