As FRAPI is currently under active beta development, the installation process isn't quite as smooth as we'd like it to be. This chapter intends to make installing FRAPI as simple and pain free as possible. You might want to give the document a read-through before you begin the install.
FRAPI requires a PHP 5 interpreter (at least PHP 5.2.4) with a webserver configured to handle PHP scripts correctly.
FRAPI also has dependencies on the following modules:
You can get FRAPI in one of two ways: cloning the FRAPI repository or downloading the latest FRAPI source as a tarball.
Go to the directory where you want to install FRAPI and do the following:
git clone git://github.com/frapi/frapi.git
Go to https://github.com/frapi/frapi/tarball/master and download the tar.gz to your install directory.
Uncompress the tar using the tar -xzvf frapi-frapi-VERSION.tar.gz
command.
You're about see a lot of references to something called
FRAPI_PATH
. This is simply a shorthand way of saying, "Where
you've chosen to install FRAPI." If you've placed the FRAPI codebase in /var/www/frapi
,
then you should read FRAPI_PATH
as /var/www/frapi
.
Since FRAPI is a web application, the web-user will need to have varying
levels of access to FRAPI_PATH
. This user is sometimes apache,
nobody, www-data, or some other user (please refer to the documentation for
your web server and operating system to determine the appropriate user if you
are not sure). During development and testing (including production, in some
cases) you will need access to those files as well.
FRAPI_PATH
to yourself and the web-user groupchown -R username.web-user FRAPI_PATH
You need to make sure that both
FRAPI_PATH/src/frapi/custom/Action/
and
FRAPI_PATH/src/frapi/custom/Config
are readable,
writable, and executable by the web-user, but only readable and executable to
everyone else (0775)
. You also want to make sure that the XML
files in FRAPI_PATH/src/frapi/custom/Config
are
readable and writable by the web-user, but only readable to everyone else
(0664)
.
chmod 775 FRAPI_PATH/src/frapi/custom/Action chmod 775 FRAPI_PATH/src/frapi/custom/Config/ chmod 664 FRAPI_PATH/src/frapi/custom/Config/*.xml
If you're using Linux you could run the FRAPI_PATH/setup.sh
script. The setup.sh
script will
initialize the ArmChair submodule and set directory permissions with the commands you see above.
sudo sh setup.sh
In order to setup FRAPI's admin interface, you'll need to setup a virtual host with the following configuration:
<VirtualHost *:80> ServerName admin.frapi DirectoryIndex index.php ServerAdmin admin@api.frapi # This should be omitted in the production environment SetEnv APPLICATION_ENV development DocumentRoot FRAPI_PATH/src/frapi/admin/public <Directory FRAPI_PATH/src/frapi/admin/public> AllowOverride All Order deny,allow Allow from All </Directory> </VirtualHost>
Make sure the server name (hostname of your api – if developing locally you may want to add admin.frapi to your /etc/hosts file) and the FRAPI_PATH (Defined in Setting Directory and File Permissions) are correct then restart Apache.
If you open your browser to http://admin.frapi you should now see a screen with a login and password (Username: admin, password: password)
The API frontend is the API that third party developers will be accessing. Very much like the administration interface, add a new site to your available sites in Apache with the following configuration:
<VirtualHost *:80> ServerName api.frapi ServerAdmin admin@api.frapi DocumentRoot FRAPI_PATH/src/frapi/public # This should be omitted in the production environment SetEnv APPLICATION_ENV development <Directory FRAPI_PATH/src/frapi/public> AllowOverride All Order deny,allow Allow from All </Directory> </VirtualHost>
Again, make sure the server name (hostname of your api – if developing locally you may want to add api.frapi to your /etc/hosts file) and the FRAPI_PATH (Defined in Setting Directory and File Permissions) are correct then restart Apache.
If you open your browser to http://api.frapi you should now see an XML payload that has an error that has the code ERROR_INVALID_ACTION_REQUEST
NOTE: At echolibre we run nearly all our FRAPI services under Nginx for performance reasons. We therefore recommend using Nginx instead of Apache whenever possible when it comes to FRAPI.
This documentation section assumes that you have Nginx setup to run with PHP as FastCGI. If you haven't setup php-fastcgi and Nginx, please read this blog post as it will be vital to your understanding and fulfillment of this setup.
Here's a list of the parameters you'll need in your fastcgi_params in order for Nginx and FRAPI to work nicely together:
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param REDIRECT_STATUS 200;
If you are uncertain about where those go, please look at the Nginx documentation for fastcgi params or look in your /etc/nginx/fastcgi_params configuration file.
In order to setup FRAPI's admin interface, you'll need to setup a virtual host with the following configuration:
server { listen 80; server_name admin.frapi; access_log /var/log/nginx/admin.frapi/access.log; root FRAPI_PATH/src/frapi/admin/public; index index.php; location / { try_files $uri $uri/ @api; } location @api { rewrite ^/(.*)$ /index.php?$1 last; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME FRAPI_PATH/src/frapi/admin/public/$fastcgi_script_name; include fastcgi_params; } }
Make sure the server name (hostname of your api – if developing locally you may want to add admin.frapi to your /etc/hosts file) and the FRAPI_PATH (Defined in Setting Directory and File Permissions) are correct then restart Nginx.
If you open your browser to http://admin.frapi you should now see a screen with a login and password (Username: admin, password: password)
The API frontend is the API that third party developers will be accessing. Very much like the administration interface, add a new site to your available sites in Nginx with the following configuration:
server { listen 80; server_name api.frapi; access_log /var/log/nginx/api.frapi/access.log; root FRAPI_PATH/src/frapi/public; index index.php; location ~* ^.+\.(jpg|js|jpeg|png|ico|gif|js|css|swf)$ { expires 24h; } location / { try_files $uri $uri/ @api; } location @api { rewrite ^/(.*)$ /index.php?$1 last; } location ~ ^/.*\.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME FRAPI_PATH/src/frapi/public/$fastcgi_script_name; include fastcgi_params; } }
Again, Make sure the server name (hostname of your api – if developing locally you may want to add api.frapi to your /etc/hosts file) and the FRAPI_PATH (Setting Directory and File Permissions) are correct then restart Nginx.
If you open your browser to http://api.frapi you should now see the documentation for your new API (Documenting Your API).