Sunday, January 31, 2016

How To Upload Slim Framework To Remote Site (Hostinger)


.
How To Upload Slim Framework To Remote Site (Hostinger)
This tutorial demonstrates how to upload Slim Framework to a remote site e.g hostinger.
The steps are applicable to other remote hosting as well.
In the example, we are preparing the site for RESTFUL service.

1) Download pre-packaged Slim Framework

Download a pre-packaged Slim Framework here. This packaged is a modified project taken from http://www.9lessons.info/2014/12/create-restful-services-using-slim-php.html .
The package is a given a name myslimproject.

2) Upload and Unzip the package into your remote site.

Log into your hostinger site.
Go into public_html folder.
The api folder contains two files; .htaccess specifies the url rewrite directives and index.php provides program logics.
file: index.php
<?php
require 'Slim/Slim.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
$app->get('/users','getUsers');
$app->get('/updates','getUserUpdates');
$app->post('/updates', 'insertUpdate');
$app->delete('/updates/delete/:update_id','deleteUpdate');
$app->get('/users/search/:query','getUserSearch');
$app->run();
function getUsers() {
        echo "getUsers method";
}
function getUserUpdates() {
        echo "getUserUpdates method";
}
function getUserUpdate($update_id) {
        echo "getUserUpdate method";
}
function insertUpdate() {
        echo "insertUpdate method";
}
function deleteUpdate($update_id) {
        echo "deleteUpdate method";
}
function getUserSearch($query) {
        echo "getUserSearch method";
}
?>
file: .htaccess
RewriteEngine On
# Some hosts may require you to use the `RewriteBase` directive.
# If you need to use the `RewriteBase` directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
#
# RewriteBase /
Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]

3) Test

for POST etc, you may need other apps like Chrome Postman Extension in order to test.
.

How To Fix: Invalid Command 'RewriteEngine'


.
Error:
Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration

Explanation:
Mod_Rewrite is  an apache module that allows you to manipulate URLS to provide shorter or more relevant ones.

Solution: http://php-steps.blogspot.my/2016/01/how-to-enable-mod-rewrite.html

.

How To Enable Mod Rewrite


.
How To Enable Mod Rewrite
This tutorial demonstrate how to enable Apache mod rewrite using UwAmp server.

1) Download and Run UwAmp server.

UwAmp server is just to help us find the Apache Module Settings quickly. It is really useful for beginners who are struggling to understand so many aspects of a web server.
Download the application from http://www.uwamp.com/en/?page=download or from here.
When you run, you should get a user interface as follows. You should notice the Apache Config button. Click on the button.

2) Apache Config Window

Apache Config window consists of two tabs; Virtual Server and Modules.
Select Modules tab.
You should be able to see the item rewrite_module.
Select the item.
Close the window.
UwAp will automatically restart the server.

3) Write .htaccess specification

We are going to write an instruction into .htaccess so that all urls are rewritten back into the url containing that .htaccess file.
This is useful particularly when we want to create a RESTFUL website.
file:  .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
file:  index.php
<?php
echo 'hello world';
?>
OUTCOME.

4) Test

Get back to UwAmp window and disable the module.
You get the error message…
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at contact@exemple.com to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.

Apache/2.4.10 (Win32) OpenSSL/1.0.1h PHP/5.4.31 Server at localhost Port 80
Your Apache Error Log reports a missing module.
.

Saturday, January 30, 2016

How To Fix Error: Invalid command 'Header'


.
Error:
Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration.

Solution:
Refer this tutorial, http://php-steps.blogspot.my/2016/01/how-to-define-http-header-specification.html


How To Enable Cross-Origin Resource Sharing


.
Cross-origin resource sharing (CORS) is a mechanism that allows restricted resources (e.g. fonts) on a web page to be requested from another domain outside the domain from which the resource originated. (wikipedia)

We can set a website to allow CORS by writing Header specification in .htaccess file (available on Apache server.

Refer this tutorial to set the Header Specification that enables CORS.
.
Besides that, we can also add the following codes into the PHP script that we are sending request to.

<?php
header("Access-Control-Allow-Origin: *");
...

What is HTTP Header?


.
HTTP header fields provide required information about the request or response, or about the object sent in the message body. There are four types of HTTP message headers:
  • General-header: These header fields have general applicability for both request and response messages.
  • Client Request-header: These header fields have applicability only for request messages.
  • Server Response-header: These header fields have applicability only for response messages.
  • Entity-header: These header fields define meta information about the entity-body or, if no body is present, about the resource identified by the request.
.
Source: http://www.tutorialspoint.com/http/http_header_fields.htm
.
Further Reading: http://code.tutsplus.com/tutorials/http-headers-for-dummies--net-8039
.
Related: How to define HTTP Header specification for a website on Apache Server?

How to define HTTP Header specification for a website on Apache Server?


.
How to define HTTP Header specification for a website on Apache Server?
This tutorial shows how to define the HTTP Header specification for a website on Apache Server.
We will be using a portable web server uwamp as it provides a visual interface to access the Apache Module Settings.
Then, we look for the Apache Config file containing the settings.
Finally we write and save the specification in .htaccess file for our chosen website path.

1) Download and Run UwAmp server.

UwAmp server is just to help us find the Apache Module Settings quickly. It is really useful for beginners who are struggling to understand so many aspects of a web server.
Download the application from http://www.uwamp.com/en/?page=download or from here.
When you run, you should get a user interface as follows. You should notice the Apache Config button. Click on the button.

2) Apache Config Window

Apache Config window consists of two tabs; Virtual Server and Modules.
Select Modules tab.
Scroll down until you see the item headers_module. Select the item.
Close the window.
where is it (module setting value) actually saved?
Click on the Code button besides the Apache Config button.
The setting value is actually stored in a file ‘httpd.conf’ (in UwAmp, it is stored as httpd_uwamp.conf’.
So, next time, if you want to enable headers_module, search for the file ‘httpd.conf’ and delete the symbol ‘#’ prefix.

3) Write Header Specification in .htaccess file

We put the .htaccess file into a folder that we would want to enforce our specification.
Assuming we have a folder ‘test’ under localhost which we want to enforce our specification, we would do as follows.
codes:
# Cross domain access
Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
Run the server and browse the url http://localhost/test 

4) Test

Let’s see what happen when we disable the module.
Go back to UwAmp window and disable the headers_module item.
The server should restart automatically.
Browse the url and see the outcome.
Here, we see that when the headers_module is disabled, the server will return the error message:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at contact@exemple.com to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.

Apache/2.4.10 (Win32) OpenSSL/1.0.1h PHP/5.4.31 Server at localhost Port 80

The server also explains more in the server error log file.
Let’s look at the file.
Go to UwAmp window and look at the Tools Section. There is a small drop-down button. Click it and select show Apache error logs.
The file will be automatically opened by the default text editor.
The log gives us sufficient evidence that the error comes from our .htaccess which contains an invalid command. In our case, the command is not recognized because the related module is not included in the server configuration.
C:/Web/UwAmp/www/test/.htaccess: Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration
Select the headers_module again and you should get back the initial output.
.

Friday, January 29, 2016

How To Install OctoberCMS On Hostinger Site


.
How To Install OctoberCMS On Hostinger Site

1) Download OctoberCMS installer file.

2) Upload to Hostinger.

2.1) Upload

2.2) Unzip

2.3) Rename the folder.

Rename the install-master folder into your preferred name, e.g october.

2.3) Apply chmod

3) Browse installer page.

3.1) Browse the installer URL.
e.g. http://notarazi.esy.es/october/install.php
Make sure that your server fulfills the requirement.
(If your hostinger site runs lower version of PHP, follow this tutorial to change the version).
Click Agree & Continue button.

4) Select Database Type

5) Specify Admin Password

6) Select a Theme.

7) Test

7.1) Front End

7.2) Back End

Reference:

.

Labels