-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create LAMP CSAR #211
Create LAMP CSAR #211
Changes from 25 commits
555ed22
c1a37d0
95a1a05
98e2945
184e1d5
1f85a7a
c400ce3
c626eee
1589402
c65bac1
4239e62
3197946
839e8e5
998f2f7
c94f782
7882540
34f2dc7
0d940fe
23741e4
dda0626
b8df471
d28bae1
fe8130d
0ce405c
376fc80
0191a5a
f8eb6ae
1d3ba14
9685f1a
f259aea
5a62c52
5a83798
8f23b33
62cacc2
86c5d31
05e9d5d
0106724
ef9751e
0db48a5
d758fca
4c77efe
0284d0c
1ac9d53
bf8e5b5
e6102cc
917a289
a5419f3
81af335
77d3a15
52912e4
83b3104
9e01ffb
e860c2a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
sudo apt-get install apache2 -y | ||
sudo apt-get install libapache2-mod-php7.0 | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
sudo service apache2 start |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
# install php on a linux machine with php-mysql | ||
sudo apt-get install php -y | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as |
||
sudo apt-get install php-mysql -y |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
// include the credentials to connect to the db | ||
//include_once "mysql-credentials.php"; | ||
|
||
$db_host = "127.0.0.1"; | ||
$db_user = "root"; | ||
$db_password = "abc"; | ||
$db_name = "mydb"; | ||
$db_port = 3306; | ||
|
||
// get task from post after task was entered in form | ||
$post = $_POST['task']; | ||
if ($post != "") { | ||
saveToDb($post); | ||
} | ||
/** | ||
* saved task to db | ||
*/ | ||
function saveToDb($task) | ||
{ | ||
$conn = newDbConnection(); | ||
$task = htmlspecialchars($task); | ||
if (!$conn->query("INSERT INTO tasks(task) VALUES('".$task."')")) { | ||
echo("Creating task failed"); | ||
} | ||
$conn->close(); | ||
} | ||
/** | ||
* reads from db and prints it in html | ||
*/ | ||
function readFromDb() | ||
{ | ||
$sql = "select * from tasks"; | ||
$conn = newDbConnection(); | ||
$result = $conn->query($sql); | ||
$conn->close(); | ||
if ($result->num_rows > 0) { | ||
// output data for each row | ||
while ($row = $result->fetch_assoc()) { | ||
echo htmlspecialchars("id: " . $row['id']. " - Task: " . $row['task'])."<br>"; | ||
} | ||
return; | ||
} | ||
echo "0 results"; | ||
} | ||
/** | ||
* generates new DB connection with given credentials | ||
*/ | ||
function newDbConnection() | ||
{ | ||
extract($GLOBALS); | ||
$conn = new mysqli($db_host, $db_user, $db_password, $db_name, $db_port); | ||
if ($conn->connect_error) { | ||
die("Connection failed: " . $conn->connect_error); | ||
} | ||
return $conn; | ||
} | ||
?> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>SimpleTaskApp</title> | ||
<style> | ||
body { | ||
font-family: sans-serif; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>SimpleTaskApp</h1> | ||
<!-- form to enter tasks --> | ||
<form class="insertTask" action="myphpapp.php" method="post"> | ||
<input type="text" name="task" /> | ||
<button type="submit" name="button">submit</button> | ||
</form> | ||
<?php | ||
//print tasks out of the db | ||
readFromDb(); | ||
?> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
$db_host = "127.0.0.1"; | ||
$db_user = "root"; | ||
$db_password = "abc"; | ||
$db_name = "mydb"; | ||
$db_port = 3306; | ||
?> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
sudo mv myphpapp.php /var/www/html/ | ||
sudo mv mysql-credentials.php /var/www/html/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
# Setup MySQL root password and create user | ||
cat << EOF | mysql -u root --password=abc | ||
CREATE DATABASE mydb; | ||
USE mydb; | ||
create table tasks (id INT not null auto_increment,task varchar(255), primary key(id)); | ||
EXIT | ||
EOF |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
sudo mysqladmin -u root -p password abc |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
# install mysql-server without password promt. | ||
# insert a fix pw | ||
echo "mysql-server mysql-server/root_password password abc" | sudo debconf-set-selections | ||
echo "mysql-server mysql-server/root_password_again password abc" | sudo debconf-set-selections | ||
sudo apt-get install mysql-server -y | ||
sudo systemctl enable mysql.service |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
sudo systemctl start mysql.service |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
tosca_definitions_version: tosca_simple_yaml_1_0 | ||
description: Template for deploying a LAMP stack. | ||
metadata: | ||
template_name: lamp-stack-template | ||
template_author: stupro-toscana | ||
template_version: 1.0 | ||
|
||
|
||
topology_template: | ||
node_templates: | ||
my_app: | ||
type: tosca.nodes.WebApplication | ||
requirements: | ||
- host: apache_web_server | ||
- database_endpoint: my_db | ||
interfaces: | ||
Standard: | ||
create: my_app/install_php.sh | ||
start: | ||
implementation: | ||
primary: my_app/start_myphpapp.sh | ||
dependencies: | ||
- myphpapp.php | ||
- mysql-credentials.php | ||
|
||
apache_web_server: | ||
type: tosca.nodes.WebServer.Apache | ||
requirements: | ||
- host: server | ||
interfaces: | ||
Standard: | ||
create: apache_web_server/webserver_install.sh | ||
start: apache_web_server/webserver_start.sh | ||
|
||
my_db: | ||
type: tosca.nodes.Database.MySQL | ||
properties: | ||
name: { mydb } | ||
user: { root } | ||
password: { abc } | ||
port: { 3306 } | ||
capabilities: | ||
database_endpoint: | ||
properties: | ||
port: { 3306 } | ||
requirements: | ||
- host: mysql_dbms | ||
interfaces: | ||
Standard: | ||
create: my_db/db_create.sh | ||
|
||
mysql_dbms: | ||
type: tosca.nodes.DBMS.MySQL | ||
properties: | ||
root_password: { abc } | ||
port: { 3306 } | ||
requirements: | ||
- host: server | ||
interfaces: | ||
Standard: | ||
create: mysql_dbms/mysql_dbms_install.sh | ||
start: mysql_dbms/mysql_dbms_start.sh | ||
configure: mysql_dbms/mysql_dbms_configure.sh | ||
|
||
server: | ||
type: tosca.nodes.Compute | ||
capabilities: | ||
host: | ||
properties: | ||
num_cpus: 1 | ||
disk_size: 25 GB | ||
mem_size: 2048 MB | ||
os: | ||
properties: | ||
type: linux | ||
distribution: ubuntu | ||
version: 16.04 | ||
outputs: | ||
endpoint: | ||
description: endpoint of the php-app | ||
value: { get_attribute: [ server, public_address ] } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
sudo apt-get install apache2 -y | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I Really dont like the idea of having duplicate code here, maybe consider putting both variants in the same directory. Just change the name of the |
||
sudo apt-get install libapache2-mod-php7.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
sudo service apache2 start | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. service is deprecated; use |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
# install php on a linux machine with php-mysql | ||
sudo apt-get install php -y | ||
sudo apt-get install php-mysql -y |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
// include the credentials to connect to the db | ||
include_once "mysql-credentials.php"; | ||
|
||
// get task from post after task was entered in form | ||
$post = $_POST['task']; | ||
if ($post != "") { | ||
saveToDb($post); | ||
} | ||
/** | ||
* saved task to db | ||
*/ | ||
function saveToDb($task) | ||
{ | ||
$conn = newDbConnection(); | ||
$task = htmlspecialchars($task); | ||
if (!$conn->query("INSERT INTO tasks(task) VALUES('".$task."')")) { | ||
echo("Creating task failed"); | ||
} | ||
$conn->close(); | ||
} | ||
/** | ||
* reads from db and prints it in html | ||
*/ | ||
function readFromDb() | ||
{ | ||
$sql = "select * from tasks"; | ||
$conn = newDbConnection(); | ||
$result = $conn->query($sql); | ||
$conn->close(); | ||
if ($result->num_rows > 0) { | ||
// output data for each row | ||
while ($row = $result->fetch_assoc()) { | ||
echo htmlspecialchars("id: " . $row['id']. " - Task: " . $row['task'])."<br>"; | ||
} | ||
return; | ||
} | ||
echo "0 results"; | ||
} | ||
/** | ||
* generates new DB connection with given credentials | ||
*/ | ||
function newDbConnection() | ||
{ | ||
extract($GLOBALS); | ||
$conn = new mysqli($db_host, $db_user, $db_password, $db_name, $db_port); | ||
if ($conn->connect_error) { | ||
die("Connection failed: " . $conn->connect_error); | ||
} | ||
return $conn; | ||
} | ||
?> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>SimpleTaskApp</title> | ||
<style> | ||
body { | ||
font-family: sans-serif; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>SimpleTaskApp</h1> | ||
<!-- form to enter tasks --> | ||
<form class="insertTask" action="myphpapp.php" method="post"> | ||
<input type="text" name="task" /> | ||
<button type="submit" name="button">submit</button> | ||
</form> | ||
<?php | ||
//print tasks out of the db | ||
readFromDb(); | ||
?> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
$db_host = "127.0.0.1"; | ||
$db_user = "root"; | ||
$db_password = "abc"; | ||
$db_name = "mydb"; | ||
$db_port = 3306; | ||
?> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
sudo mv myphpapp.php /var/www/html/ | ||
sudo mv mysql-credentials.php /var/www/html/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
# Setup MySQL root password and create user | ||
cat << EOF | mysql -u root --password=abc | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use root pw from template |
||
CREATE DATABASE mydb; | ||
USE mydb; | ||
create table tasks (id INT not null auto_increment,task varchar(255), primary key(id)); | ||
EXIT | ||
EOF |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
sudo mysqladmin -u root -p password db_root_password | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what exactly do you intend to do here? AFAIK valid syntax would be: sudo mysqladmin -u root -p $db_root_password now you started the mysqladmin shell, but what now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with this command you could change your root pw There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i looked it up. correct syntax would be: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
# install mysql-server without password promt. | ||
# insert a fix pw | ||
echo "mysql-server mysql-server/root_password password abc" | sudo debconf-set-selections | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't you use the my_mysql_rootpwd from the template? |
||
echo "mysql-server mysql-server/root_password_again password abc" | sudo debconf-set-selections | ||
sudo apt-get install mysql-server -y | ||
sudo systemctl enable mysql.service |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
sudo systemctl start mysql.service | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw, when using sytemctl it's always save to drop the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think you have to add
-y
here too.You could also consider concatenation of both commands like that:
sudo apt-get install -y apache2 libapache2-mod-php7.0