Requirement | Comment |
---|---|
Interpret PHP Scripts | We would like the web server to call the PHP interpreter when a page ending with .php is requested. |
Be able to have access to the MySQL functions of PHP | Since we set up a LEMP server, we need to have a MySQL server installed and accessible from PHP. |
Be as fast as possible | To be fast, especially with serving PHP scripts, we can use a caching module in PHP which will speed things up. |
Modify the expiry date of http headers to encourage caching | We want files that should should not change (e.g. css or images) to be cached on the client's side to make the client's experience more pleasant |
Compress text before they are served to the client | We can compress the text that flows between the client and the server and in this way reduce the over the line bytes which in turn should also give the client a more pleasant experience |
Enable rewrite rules in CakePHP for pretty URL's | CakePHP makes use of the .htaccess files in Apache to enable pretty URLs. Singe Nginx does not support .htaccess files, we need to change Nginx to behave in the same way. |
Install Nginx
sudo apt-get install nginx
Ensure the web server starts up and is running
sudo /etc/init.d/nginx stop
sudo /etc/init.d/nginx start
Navigate to the IP Address of the server where you installed Nginx using a browser to ensure Nginx serves content e.g. http://127.0.0.1
Install the php5-fpm service:
sudo apt-get install php5-fpm
Edit the config file so it creates a unix socket instead of a network socket to listen on.
sudo vi -c37 /etc/php5/fpm/pool.d/www.conf
Change the listen part to the following:
;listen = 127.0.0.1:9000
listen = /var/run/php5-fpm.sock
Restart the php5-fpm service:
sudo /etc/init.d/php5-fpm restart
Edit the default server file:
sudo vi /etc/nginx/sites-enabled/default
Add index.php to this line:
#add index.php
index index.php index.html index.htm;
Activate PHP precessing by uncommenting this this section. Note that we use the UNIX socket:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
Enable the hiding of .htaccess files
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
Reload the Nginx web server's configuration
sudo /etc/init.d/nginx reload
Create a test .php file to confirm that it does work
sudo vi /usr/share/nginx/www/test.php
Contents:
<?php
phpinfo();
?>
Navigate to http://127.0.0.1/test.php and see if the page display the PHP info.
sudo apt-get install mysql-server mysql-client php5-mysql
sudo apt-get install php5-xcache
sudo /etc/init.d/php5-fpm reload
Edit the /etc/nginx/sites-available/default file:
sudo vi /etc/nginx/sites-available/default
Add the following inside the server section:
location ~* ^.+\.(jpg|jpeg|gif|png|ico|js|css)$ {
rewrite ^/c2/rd_cake/webroot/(.*)$ /c2/rd_cake/webroot/$1 break;
rewrite ^/c2/rd_cake/(.*)$ /c2/rd_cake/webroot/$1 break;
access_log off;
expires max;
add_header Cache-Control public;
}
Reload Nginx:
sudo /etc/init.d/nginx reload
Edit the main config file of Nginx.
sudo vi /etc/nginx/nginx.conf
Change the compression section to contain the following:
#gzip on;
#gzip_disable "msie6";
gzip on;
gzip_http_version 1.1;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js;
gzip_buffers 16 8k;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
Restart Nginx
sudo /etc/init.d/nginx restart
Make sure the following packages are installed:
sudo apt-get install php5-cli php5-gd php5-curl
Install the available language packs (These are optional)
sudo apt-get install language-pack-af language-pack-fa
Download the 2.x version of CakePHP (Version 2.3.5 as of this writing). https://github.com/cakephp/cakephp/tags
Copy and extract it inside the directory that Nginx is serving its content from (/usr/share/nginx/www by default on Ubuntu)
sudo cp cakephp-2.3.5.tar.gz /usr/share/nginx/www
cd /usr/share/nginx/www
sudo tar -xzvf cakephp-2.3.5.tar.gz
sudo ln -s ./cakephp-2.3.5 ./cake2
Reload php5-fpm
sudo /etc/init.d/php5-fpm reload
Install subversion in order for you to check out the latest source for RADIUSdesk.
sudo apt-get install subversion
Check out the rd_cake branch from trunk to /usr/share/nginx/www.
cd /usr/share/nginx/www/cake2
sudo svn checkout svn://dvdwalt@svn.code.sf.net/p/radiusdesk/code/trunk/rd_cake ./rd_cake
TIP: If you are following the development of RADIUSdesk and want to make sure you have the latest SVN you can simply cd to /usr/share/nginx/www/cake2/rd_cake and run svn update to fetch the latest changes.
Change the following directories to be writable by www-data:
sudo chown -R www-data. /usr/share/nginx/www/cake2/rd_cake/tmp
sudo chown -R www-data. /usr/share/nginx/www/cake2/rd_cake/Locale
sudo chown -R www-data. /usr/share/nginx/www/cake2/rd_cake/webroot/img/flags
sudo chown -R www-data. /usr/share/nginx/www/cake2/rd_cake/webroot/img/nas
sudo chown -R www-data. /usr/share/nginx/www/cake2/rd_cake/webroot/img/realms
sudo chown -R www-data. /usr/share/nginx/www/cake2/rd_cake/webroot/img/dynamic_details
sudo chown -R www-data. /usr/share/nginx/www/cake2/rd_cake/webroot/img/dynamic_photos
sudo chown -R www-data. /usr/share/nginx/www/cake2/rd_cake/webroot/files/imagecache
Create the following blank database:
mysql -u root
create database rd;
GRANT ALL PRIVILEGES ON rd.* to 'rd'@'127.0.0.1' IDENTIFIED BY 'rd';
GRANT ALL PRIVILEGES ON rd.* to 'rd'@'localhost' IDENTIFIED BY 'rd';
exit;
Populate the database (trunk):
mysql -u root rd < /usr/share/nginx/www/cake2/rd_cake/Setup/Db/rd.sql
If you use a tagged release:
mysql -u root rd < /usr/share/nginx/www/cake2/rd_cake/Setup/Db/rd_<tagged_version>.sql
If you are upgrading from a tagged release:
mysql -u root rd < /usr/share/nginx/www/cake2/rd_cake/Setup/Db/rd_beta<your_tagged_version>_to_beta<next_tagged_verion>.sql
Edit /etc/nginx/sites-enabled/default
sudo vi /etc/nginx/sites-enabled/default
Add the following section inside the server section:
location /cake2/rd_cake {
rewrite ^/cake2/rd_cake/(.*)$ /cake2/rd_cake/webroot/$1 break;
try_files $uri $uri/ /cake2/rd_cake/webroot/index.php?q=$uri&$args;
}
Reload the Nginx web server:
sudo /etc/init.d/nginx reload
cd /usr/share/nginx/www
sudo bash -c "grep -R --files-with-matches '/var/www' . | sort | uniq | xargs perl -p -i.bak -e 's/\/var\/www\//\/usr\/share\/nginx\/www\//g'"
Your browser should show a JSON encrypted string:
{"data":{"phrases":{"spclCountry":"United Kingdom","spclLanguage":"English","sUsername":"......,"success":true}
Congratulations you are almost there. Next we will install the viewer component
Check out the latest code of the viewer component under the /usr/share/nginx/www/ directory:
cd /usr/share/nginx/www/
sudo svn checkout svn://dvdwalt@svn.code.sf.net/p/radiusdesk/code/trunk/rd ./rd
TIP: If you are following the development of RADIUSdesk and want to make sure you have the latest SVN you can simply cd to /usr/share/nginx/www/rd and run svn update to fetch the latest changes.
For the viewer component you need the ExtJS toolkit. As of this writing the latest version of ExtJS is 4.2.0. The development however was done on 4.1.1. This version is not easy to find on Sencha's download page so we've added it to the SVN repository for easy download :-)
Checkout and unzip the GPL version under the /usr/share/nginx/www/rd directory. NOTE: This is a single big file which will take some time to download over slow connections.
sudo apt-get install unzip
cd /usr/share/nginx/www/
sudo svn checkout svn://svn.code.sf.net/p/radiusdesk/code/extjs ./
sudo mv ext-4.1.1a-gpl.zip ./rd
cd /usr/share/nginx/www/rd
sudo unzip ext-4.1.1a-gpl.zip
Rename the extracted directory to simply ext:
cd /usr/share/nginx/www/rd
sudo mv ext-4.1.1a ext
Copy the ux folder under examples to the src folder
sudo cp -R /usr/share/nginx/www/rd/ext/examples/ux /usr/share/nginx/www/rd/ext/src
Now try to log in on the following URL with username root and password admin:
http://127.0.0.1/rd
Check out the latest code of the dynamic login pages under the /usr/share/nginx/www/ directory:
cd /usr/share/nginx/www/
sudo svn checkout svn://dvdwalt@svn.code.sf.net/p/radiusdesk/code/trunk/rd_login_pages ./rd_login_pages
TIP: If you are following the development of RADIUSdesk and want to make sure you have the latest SVN you can simply cd to /usr/share/nginx/www/rd_login_pages and run svn update to fetch the latest changes.
Edit the /usr/share/nginx/www/rd/app/app.js file and modify the top part to force it to cache the files:
Ext.Loader.setConfig({enabled:true,disableCaching: false});
Edit the /usr/share/nginx/www/rd/index.html file and change this part:
<!-- <x-bootstrap> -->
<script src="ext/ext-dev.js"></script>
<script src="bootstrap.js"></script>
<!-- </x-bootstrap> -->