Afficher/cacher Sommaire
Note 2017-01-05T17.50.53
yan.me (olibox)
Yunohost Multi yan webapp
Installation sur olibox https://yan.me de Multi_web_app https://github.com/YunoHost-Apps/multi_webapp_ynh
Le dossier /me –> /var/www/webapp_yan/me/
Base de données
Pas public
Les informations sur la base de données
DB_NAME= webapp_me
DB_USER= webapp_me
DB_PASSWORD= i]W5bqvOM56rjtBrkMZ5kphv
DB_HOST= localhost
Le lien https://yan.me/me
Accès au dossier /var/www
sshfs debian@192.168.0.43:/var/www /media/yan.me
Simple REST API
-
Creating a simple REST API in PHP
nano /var/www/webapp_yan/me/index.php
<?php
// get the HTTP method, path and body of the request
$method = $_SERVER['REQUEST_METHOD'];
$request = explode('/', trim($_SERVER['PATH_INFO'],'/'));
$input = json_decode(file_get_contents('php://input'),true);
// connect to the mysql database
$link = mysqli_connect('localhost', 'root', '[96DszbqEN', 'classicmodels');
mysqli_set_charset($link,'utf8');
// retrieve the table and key from the path
$table = preg_replace('/[^a-z0-9_]+/i','',array_shift($request));
$key = array_shift($request)+0;
// escape the columns and values from the input object
$columns = preg_replace('/[^a-z0-9_]+/i','',array_keys($input));
$values = array_map(function ($value) use ($link) {
if ($value===null) return null;
return mysqli_real_escape_string($link,(string)$value);
},array_values($input));
// build the SET part of the SQL command
$set = '';
for ($i=0;$i<count($columns);$i++) {
$set.=($i>0?',':'').'`'.$columns[$i].'`=';
$set.=($values[$i]===null?'NULL':'"'.$values[$i].'"');
}
// create SQL based on HTTP method
switch ($method) {
case 'GET':
$sql = "select * from `$table`".($key?" WHERE id=$key":''); break;
case 'PUT':
$sql = "update `$table` set $set where id=$key"; break;
case 'POST':
$sql = "insert into `$table` set $set"; break;
case 'DELETE':
$sql = "delete `$table` where id=$key"; break;
}
// excecute SQL statement
$result = mysqli_query($link,$sql);
// die if SQL statement failed
if (!$result) {
http_response_code(404);
die(mysqli_error());
}
// print results, insert id or affected row count
if ($method == 'GET') {
if (!$key) echo '[';
for ($i=0;$i<mysqli_num_rows($result);$i++) {
echo ($i>0?',':'').json_encode(mysqli_fetch_object($result));
}
if (!$key) echo ']';
} elseif ($method == 'POST') {
echo mysqli_insert_id($link);
} else {
echo mysqli_affected_rows($link);
}
// close mysql connection
mysqli_close($link);
http://yan.me/index.php/{$table}/{$id}
https://yan.me/me/index.php/{customers}/{customerNumber}
https://github.com/mevdschee/php-crud-api
VirtualHost DebYan
composer
How to install Composer on Debian
To make Composer (globally) available on Debian:
$ cd /usr/src
$ sudo apt-get install curl php7.0-cli
$ curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
Verify installation:
$ composer --version
Composer version 1.3.0 2016-12-24 00:47:03
Phalcon
A full-stack PHP framework delivered as a C-extension (documentation)
Installationb Debian/Ubuntu
To add the repository to your distribution:
# Stable releases
curl -s https://packagecloud.io/install/repositories/phalcon/stable/script.deb.sh | sudo bash
# Nightly releases
curl -s https://packagecloud.io/install/repositories/phalcon/nightly/script.deb.sh | sudo bash
This only needs to be done only once, unless your distribution changes or you want to switch from stable to nightly builds.
To install Phalcon:
sudo apt-get install php5-phalcon
# or for PHP 7
sudo apt-get install php7.0-phalcon
Tutoriel
Phalcon Tutorial 1: Let’s learn by example
Installer base mariadb
sudo apt install mariadb-server-10.0 php7.0-mysql # mp mariadb49spm
Création base “debyan” , table “utilisateur”
mysql -uroot -pmariadb49spm -e "\
CREATE DATABASE debyan DEFAULT CHARACTER SET utf8;\
GRANT ALL PRIVILEGES ON debyan.* TO 'yan'@'localhost' IDENTIFIED BY 'yan49mysql';"
mysql -uyan -pyan49mysql debyan -e "\
CREATE TABLE utilisateur
(
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
nom VARCHAR(100),
prenom VARCHAR(100),
email VARCHAR(255),
date_naissance DATE,
pays VARCHAR(255),
ville VARCHAR(255),
code_postal VARCHAR(5),
nombre_achat INT
);"