-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram.py
More file actions
88 lines (63 loc) · 1.96 KB
/
program.py
File metadata and controls
88 lines (63 loc) · 1.96 KB
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
"""
Install and configure Wordpress on an Amazon AWS EC2 instance.
Used Apache2, PHP 7.0, MySQL and Let's encrypt (SSL is optionnal)
"""
# Libraries
import time
import boto3
import paramiko
from functions import *
from variables import *
# Beginning of the program
url = input('Enter the URL as \'example.com\' (without \'www\' or \'http(s)\'): ')
ssl = input('Do you want an HTTPS website ? (o/n): ').lower() # HTTPS is powered by LetsEncrypt
# Create the boto3 ressource
ec2 = boto3.resource(
'ec2',
aws_access_key_id = AWS_ACCESS_KEY,
aws_secret_access_key = AWS_SECRET_KEY,
region_name = AWS_REGION_NAME
)
# Create a new EC2 instance
instances = ec2.create_instances(
ImageId = AWS_AMI_ID,
MinCount = 1,
MaxCount = 1,
InstanceType = AWS_INSTANCE,
KeyName = AWS_KEY_NAME
)
instance = instances[0]
print("Please wait until the installation..")
# Wait for the instance to enter the running state
instance.wait_until_running()
# Reload the instance attributes
instance.load()
# Save the ip of the instance
ip = instance.public_ip_address
# Wait a bit for the instance's initialisation
time.sleep(4)
# SSH connection
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(str(ip), username='admin', key_filename=AWS_KEY_FILENAME)
sftp = ssh.open_sftp()
# Install and configure Apache2
install_apache2(ssh, sftp, url)
# Install SSL certificate if desired
if ssl == 'o':
install_ssl(ssh, sftp, url, ip)
auto_renew_ssl(ssh, sftp, url)
# Install and configure PHP
install_php(ssh)
# Install and configure MySQL
install_mysql(ssh, sftp)
# Pre-install Wordpress
install_wp(ssh, sftp, url)
# End of the SSH connection
ssh.close()
print('IP of your machine : ' + ip)# Display the public IP of the AWS instance
print('The installation is finished !')
# Send SMS
message = "Your Wordpress site on EC2 is installed ! Go to it on : {} ({})".format(url, ip)
send_sms(message, YOUR_PHONE_NUMBER)
# End of the program