WordPress LAMP Stack

Complete WordPress installation with Apache, MySQL, and PHP

Script Author

Rowan de Haas's avatar
Rowan de Haas
Script Author

Script Details

Created 11 months ago
Size 2 KB

Tags

Script Content

Raw
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
#cloud-config
package_update: true
package_upgrade: true

packages:
  - apache2
  - mysql-server
  - php
  - php-mysql
  - php-curl
  - php-gd
  - php-xml
  - php-mbstring
  - php-zip
  - libapache2-mod-php
  - wget
  - unzip

write_files:
  - path: /etc/apache2/sites-available/wordpress.conf
    content: |
      
          ServerName example.com
          ServerAlias www.example.com
          DocumentRoot /var/www/wordpress
          
          
              AllowOverride All
              Require all granted
          
          
          ErrorLog ${APACHE_LOG_DIR}/wordpress_error.log
          CustomLog ${APACHE_LOG_DIR}/wordpress_access.log combined
      

runcmd:
  # Configure MySQL
  - mysql -e "CREATE DATABASE wordpress;"
  - mysql -e "CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'StrongPassword123!';"
  - mysql -e "GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';"
  - mysql -e "FLUSH PRIVILEGES;"
  
  # Download and install WordPress
  - cd /tmp && wget https://wordpress.org/latest.tar.gz
  - tar -xzf /tmp/latest.tar.gz -C /var/www/
  - chown -R www-data:www-data /var/www/wordpress
  - chmod -R 755 /var/www/wordpress
  
  # Enable Apache modules and sites
  - a2enmod rewrite
  - a2ensite wordpress.conf
  - a2dissite 000-default.conf
  - systemctl reload apache2

How to Use This Script

Cloud Provider Examples

Amazon EC2

aws ec2 run-instances
  --image-id ami-12345678
  --instance-type t3.micro
  --user-data file://script.yaml

DigitalOcean

doctl compute droplet create
  --image ubuntu-22-04-x64
  --size s-1vcpu-1gb
  --user-data-file script.yaml
  my-droplet

Google Cloud

gcloud compute instances create
  my-instance
  --metadata-from-file
  user-data=script.yaml