Skip to content

Commit

Permalink
READMEing, fixing the sudo call with -t option, tests ok via Apache2 …
Browse files Browse the repository at this point in the history
…& php built-in server
  • Loading branch information
ronanguilloux committed Mar 22, 2013
1 parent 8e70783 commit def7367
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 15 deletions.
42 changes: 28 additions & 14 deletions README.md
Expand Up @@ -8,13 +8,13 @@ Website integration example of the [php-gpio](https://github.com/ronanguilloux/p
Hardware prerequisites
----------------------

After having installed & wired your LED & resistor on a breadboard,
After having installed & wired your LED & resistor on a breadboard,
add appropriate modules from the Linux Kernel:

For LEDs, enable the gpio module :

``` bash
$ sudo modprobe w1-gpio
$ sudo modprobe w1-gpio
```

([see a complete circuit diagram for a single LED + explanations & schemas here](https://projects.drogon.net/raspberry-pi/gpio-examples/tux-crossing/gpio-examples-1-a-single-led/))
Expand All @@ -25,23 +25,33 @@ Installation

The recommended way to install php-gpio-web is through [composer](http://getcomposer.org).

Just run these three commands to install it (`curl` needed):
Install a webserver, git, php5 & curl:

``` bash
$ sudo apt-get install git
$ wget http://getcomposer.org/composer.phar
$ php composer.phar create-project --stability='dev' ronanguilloux/php-gpio-web
$ sudo apt-get install git php5 apache2 libapache2-mod-php5 curl
```

Clone this repo & install vendors (dependencies)

``` bash
$ git clone git://github.com/ronanguilloux/php-gpio-web.git
$ cd php-gpio-web
$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar install
```

Configure apache2 vhost


Blink with style
----------------

Fetch the ready-to-use blinker file inside your project

``` bash
$ cd php-gpio-web
$ cp vendor/ronanguilloux/php-gpio/blinker .
$ cd php-gpio-web
$ cp vendor/ronanguilloux/php-gpio/blinker .
$ chmod a+x blinker
```

To run this blinker with sudo permissions but without password inputting,
Expand All @@ -52,24 +62,28 @@ and your webserver application needs only one php file to be specified in /etc/s
Edit your `/etc/sudoers` file:

``` bash
$ sudo visudo
$ sudo visudo
```

Then add this two lines in your `/etc/sudoers` file :

```
www-data ALL=NOPASSWD: /path/to/blinker
myCurrentLinuxLogin ALL=NOPASSWD: /path/to/blinker
www-data ALL=NOPASSWD:/path/to/the/blinker
```

Just replace myCurrentLinuxLogin by your own linux user login
The blinker file provided is ready to use the API.
Replace /pat/to/the/blinker with your project path

The blinker file provided is ready to use the API. You do not need to install apache2-suexec nor suPHP.


Run it!
-------

Via the PHP built-in web server:

``` bash
$ php -S "`hostname -I`:8080" -t web/
$ php -S "`hostname -I`:8080" -t web/
```

Via Apache2: cf. the apache2.conf example file

19 changes: 19 additions & 0 deletions apache2.conf
@@ -0,0 +1,19 @@
<VirtualHost *:80>
Servername php-gpio-web
DocumentRoot /path/to/the/php-gpio-web/web
DirectoryIndex index.php
<Directory /path/to/the/php-gpio-web/web>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php [QSA,L]
</IfModule>
</Directory>
ErrorLog /var/log/apache2/error.php-gpio-web.log
LogLevel warn
CustomLog /var/log/apache2/access.php-gpio-web.log combined
</VirtualHost>
2 changes: 1 addition & 1 deletion web/index.php
Expand Up @@ -16,7 +16,7 @@
$app = new Silex\Application();

$app->get('/blink/{id}', function ($id) use ($app) {
$msg = exec("sudo /usr/bin/php ../blinker $id 90000");
$msg = exec("sudo -t /usr/bin/php ../blinker $id 90000");
$code = ("" === trim($msg)) ? 200 : 500;
return new Response($msg, $code);
});
Expand Down

0 comments on commit def7367

Please sign in to comment.