-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-docker-lamp.sh
executable file
·195 lines (155 loc) · 4.07 KB
/
create-docker-lamp.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/bin/bash
# Creating a directory structure
mkdir -p docker/nginx
mkdir -p docker/php
mkdir -p env
mkdir -p logs/nginx
mkdir -p src
# default.conf
echo "# docker/nginx/default.conf
server {
listen 80;
index index.php index.htm index.html;
root /var/www/html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
location ~ \.php$ {
try_files \$uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
fastcgi_param PATH_INFO \$fastcgi_path_info;
}
}" > docker/nginx/default.conf
# Dockerfile for nginx
echo "# docker/nginx/Dockerfile
FROM nginx:1.23
ADD default.conf /etc/nginx/conf.d/default.conf" > docker/nginx/Dockerfile
# Dockerfile for php
echo "# docker/php/Dockerfile
FROM php:8.2-fpm
RUN apt-get update
RUN docker-php-ext-install pdo pdo_mysql mysqli" > docker/php/Dockerfile
# mysql.env
echo "MYSQL_HOSTNAME=mysql
MYSQL_ROOT_PASSWORD=rootpassword
MYSQL_DATABASE=helloworld
MYSQL_USER=helloworld
MYSQL_PASSWORD=helloworldpassword" > env/mysql.env
# index.php
echo "# src/index.php
<?php
echo phpinfo();" > src/index.php
# mysqlinfo.php
echo "# src/mysql.php
<?php
\$hostname = \"mysql\";
\$dbname = \"helloworld\";
\$username = \"helloworld\";
\$password = \"helloworldpassword\";
try {
\$conn = new PDO( \"mysql:host=\$hostname;dbname=\$dbname\", \$username, \$password );
// Configure PDO error mode
\$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
echo \"Connected successfully\";
}
catch( PDOException \$e ) {
echo \"Failed to connect: \" . \$e->getMessage();
}
// Perform database operations
// Close the connection
\$conn = null;" > src/mysql.php
# docker-compose.yml
echo "# docker-compose.yml
version: \"v2.20.2-desktop.1\"
services:
nginx:
container_name: nginx
build: ./docker/nginx
command: nginx -g \"daemon off;\"
links:
- php
ports:
- \"80:80\"
volumes:
- ./logs/nginx:/var/log/nginx
- ./src:/var/www/html
php:
container_name: php
build: ./docker/php
links:
- mysql
ports:
- \"9000:9000\"
volumes:
- ./src:/var/www/html
working_dir: /var/www/html
mysql:
image: mysql:8.0.32
container_name: mysql
env_file:
- ./env/mysql.env
ports:
- \"3306:3306\"
volumes:
- ./database/mysql:/var/lib/mysql
command: '--default-authentication-plugin=mysql_native_password'
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: pma
links:
- mysql
environment:
PMA_HOST: mysql
PMA_PORT: 3306
PMA_ARBITRARY: 1
restart: always
ports:
- 8085:80" > docker-compose.yml
# Readme.md
echo "Script by Marbosoft
1. Run script
./create-docker-lamp.sh
2. Build Docker env
docker-compose build
3. Docker up
docker-compose up
4. Make sure the environment is raised regularly on http://localhost/
5. Check if mysql can be accessed from PHP on http://localhost/mysql.php
6. Delete all files from src directory
7. Download and extract Wordpress to src directory
5. Rename wp-config-sample.php to wp-config.php and change
<?php
....
....
define( 'DB_NAME', 'helloworld' );
/** Database username */
define( 'DB_USER', 'helloworld' );
/** Database password */
define( 'DB_PASSWORD', 'helloworldpassword' );
/** Database hostname */
define( 'DB_HOST', 'mysql' );
....
....
6. Also add following lines:
....
....
/* Add any custom values between this line and the \"stop editing\" line. */
define( 'FS_METHOD', 'direct' );
define( 'UPLOADS', 'wp-content/uploads' );
/* That's all, stop editing! Happy publishing. */
....
....
7. Change permissions
sudo chown -R www-data:www-data <path to src>/wp-content
8. Open Wordpress installation on http://localhost/
9. Install Wordpress
10. PHPMyAdmin address: http://localhost:8085/
11. To stop the docker click on CTRL + C; If you are a docker starter with docker-compose up -d, then use command docker-compose down
...
Enjoy the programming.
Bojan Marković
^^^^^^^^^^^^^^
Your Marbosoft" > Readme.md