-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsymfony.sh
127 lines (106 loc) · 3.07 KB
/
symfony.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# ======================
# From Debian to Web App
# ======================
# This page contains a list of terminal commands that
# create a Symfony web application with routing, templates
# and user accounts.
#
# You can start from a fresh debian installation. Or with a
# fresh debian container:
#
# docker run -v $(pwd):/var/www --rm -it -p 80:80 debian:11-slim
#
# You can copy+paste each command to see the application take
# shape or copy the whole page and paste it in one go.
# You can also download it here: https://...
# ======================
# Let's configure Debian
# ======================
# Do not show dialogs during the upgrade
export DEBIAN_FRONTEND=noninteractive
# Update the packages
apt update -y && apt upgrade -y
# =====================
# Let's install Symfony
# =====================
apt install -y unzip git php php-xml php-curl composer
cd /var/www
composer create-project symfony/website-skeleton mysite --no-interaction
chown -R www-data:www-data mysite
cd mysite
# Ensure composer doesn't ask us questions about recipes and allow contrib recipes
composer config extra.symfony --json '{"allow-contrib": true}'
# apache-pack will write the public/.htaccess file that
# routes all requests to public/index.php.
composer require symfony/apache-pack
# ====================
# Let's install Apache
# ====================
apt install -y apache2 libapache2-mod-php
cat << 'EOF' > /etc/apache2/sites-enabled/000-default.conf
ServerName mysite.local
<Directory /var/www/mysite/public>
AllowOverride All
</Directory>
<VirtualHost *:80>
DocumentRoot /var/www/mysite/public
</VirtualHost>
EOF
service apache2 start
# Yay, we have a working Symfony instance!
# You can see it at 127.0.0.1
read -p 'Symfony is running! Hit enter to continue.'
# ===================
# Let's use templates
# ===================
cat << 'EOF' > templates/index.html.twig
<h1>Hello World</h1>
EOF
cat << 'EOF' > src/Controller/HomepageController.php
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class HomepageController extends AbstractController
{
/**
* @Route("/", name="homepage")
*/
public function index(): Response
{
return $this->render('index.html.twig', [
'controller_name' => 'HomepageController',
]);
}
}
EOF
# Yay, we have static site!
read -p 'Serving a static site! Hit enter to continue.'
# =========================
# Let's use a base template
# =========================
# Let's create a base template
cat << 'EOF' > templates/base.html.twig
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
<style>
body {background: #60a060}
</style>
</head>
<body>{% block content %}{% endblock %}</body>
</html>
EOF
# And use it for the index page:
cat << 'EOF' > templates/index.html.twig
{% extends "base.html.twig" %}
{% block content %}
<h1>Hello World</h1>
{% endblock %}
EOF
# =======================
# Let's add user accounts
# =======================
# ... To be written ...