-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwordpress_apache_setup.sh
102 lines (89 loc) · 3.47 KB
/
wordpress_apache_setup.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
#!/bin/bash
# Tested on Ubuntu 20.04
# Variáveis de configuração
DB_NAME="my_database"
DB_HOST="my-database-instance.123456789012.us-east-1.rds.amazonaws.com"
DB_USER="my_username"
DB_PASSWORD="my_password"
TABLE_PREFIX="myprefix_"
SSL_CERT="/etc/ssl/certs/apache-selfsigned.crt"
SSL_KEY="/etc/ssl/private/apache-selfsigned.key"
# Instalando depdnências
sudo apt update -y &&
sudo apt install -y apache2 \
ghostscript \
libapache2-mod-php \
mysql-server \
php \
php-bcmath \
php-curl \
php-imagick \
php-intl \
php-json \
php-mbstring \
php-mysql \
php-xml \
php-zip || exit 1
# Instalando o Wordpress
sudo mkdir -p /srv/www &&
sudo chown www-data: /srv/www || exit 1
sudo -u www-data curl https://wordpress.org/latest.tar.gz | tar zx -C /srv/www || exit 1
# Sobrescrevendo o arquivo de configuração do Wordpress
sudo cp /srv/www/wordpress/wp-config-sample.php /srv/www/wordpress/wp-config.php || exit 1
sudo sed -i "s/database_name_here/$DB_NAME/" /srv/www/wordpress/wp-config.php || exit 1
sudo sed -i "s/localhost/$DB_HOST/" /srv/www/wordpress/wp-config.php || exit 1
sudo sed -i "s/username_here/$DB_USER/" /srv/www/wordpress/wp-config.php || exit 1
sudo sed -i "s/password_here/$DB_PASSWORD/" /srv/www/wordpress/wp-config.php || exit 1
sudo sed -i "s/wp_/$TABLE_PREFIX/" /srv/www/wordpress/wp-config.php || exit 1
# Configurando o Apache para o Wordpress
sudo tee /etc/apache2/sites-available/wordpress.conf <<EOF
<VirtualHost *:80>
DocumentRoot /srv/www/wordpress
<Directory /srv/www/wordpress>
Options FollowSymLinks
AllowOverride Limit Options FileInfo
DirectoryIndex index.php
Require all granted
</Directory>
<Directory /srv/www/wordpress/wp-content>
Options FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
EOF
sudo tee /etc/apache2/sites-available/wordpress-ssl.conf <<EOF
<VirtualHost _default_:443>
DocumentRoot /srv/www/wordpress
SSLEngine on
SSLCertificateFile $SSL_CERT
SSLCertificateKeyFile $SSL_KEY
<Directory /srv/www/wordpress>
Options FollowSymLinks
AllowOverride All
DirectoryIndex index.php
Require all granted
</Directory>
<Directory /srv/www/wordpress/wp-content>
Options FollowSymLinks
Require all granted
AllowOverride All
</Directory>
ErrorLog /var/log/apache2/errorSSL.log
LogLevel warn
CustomLog \${APACHE_LOG_DIR}/accessSSL.log combined
</VirtualHost>
EOF
# Gerando certificado auto-assinado
echo -e "BR\nSaoPaulo\nSaoPaulo\nTest\nTest\nWordpress\[email protected]" \
| sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout "$SSL_KEY" -out "$SSL_CERT" || exit 1
sudo chown www-data: /srv/www || exit 1
sudo a2dissite 000-default || exit 1
sudo a2ensite wordpress || exit 1
sudo a2ensite wordpress-ssl || exit 1
sudo a2enmod ssl || exit 1
sudo a2enmod rewrite || exit 1
sudo service apache2 reload || exit 1
echo "----------------------------------------------------------------------------"
echo "Grab the values below and paste them in the /srv/www/wordpress/wp-config.php file:"
sudo curl -s https://api.wordpress.org/secret-key/1.1/salt/ | sudo tee -a /srv/www/wordpress/wp-config.php >/dev/null
echo "----------------------------------------------------------------------------"