LEMP Stack

by zonmob
111 deployments · 44 still active · last rev. 7 months ago

Installs a full LEMP stack (Nginx, MySQL(MariaDB), PHP) on a Linode. Uses MySQL for Debian and Ubuntu; MariaDB for CentOS and Fedora (the new defaults). This can also be used as a library for other StackScripts.

Compatible with: CentOS 7, Debian 8, Ubuntu 14.04 LTS
						#!/usr/bin/env python

"""
LEMP StackScript
    
    Author: Hieu Bui Duc <hieubd@zonmob.com>
    Version: 1.0.0.0
    Requirements:
        - ss://linode/python-library <ssinclude StackScriptID="3">
        - ss://linode/nginx <ssinclude StackScriptID="16509">
        - ss://linode/mysql <ssinclude StackScriptID="7">
        - ss://linode/php <ssinclude StackScriptID="8">

This StackScript both deploys and provides a library of functions for
creating a LAMP stack. The functions in this StackScript are designed to be 
run across Linode's core distributions:
    - Ubuntu
    - CentOS
    - Debian
    - Fedora

StackScript User-Defined Variables (UDF): 

<UDF name="db_root_password" label="MySQL/MariaDB root password" />
<UDF name="db_name" label="Create Database" default="" example="create this empty database" />
"""

import os
import sys

try: # we'll need to rename included StackScripts before we can import them
    os.rename("/root/ssinclude-3", "/root/pythonlib.py")
    os.rename("/root/ssinclude-16509", "/root/nginx.py")
    os.rename("/root/ssinclude-7", "/root/mysql.py")
    os.rename("/root/ssinclude-8", "/root/php.py")
except:
    pass

import pythonlib
import nginx
import mysql
import php


def main():
    """Install Nginx, MySQL/MariaDB, and PHP."""
    # add logging support
    pythonlib.init()
    
    if os.environ['DB_ROOT_PASSWORD'] != "":
        db_root_password = os.environ['DB_ROOT_PASSWORD']
    else:
        db_root_password = False
    
    if os.environ['DB_NAME'] != "":
        db_name = os.environ['DB_NAME']
    else:
        db_name = False

    pythonlib.system_update()
    nginx.nginx_install()
    mysql.mysql_install(db_root_password, db_name)
    php.php_install()
    php.php_install_module_common()

    pythonlib.end()


if __name__ == "__main__":
    sys.exit(main())