PHP

by linode
2 deployments · 0 still active · last rev. 1 year ago

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

"""
PHP StackScript
	
	Author: Ricardo N Feliciano <rfeliciano@linode.com>
	Version: 1.0.1.2
	Requirements:
		- ss://linode/python-library <ssinclude StackScriptID="3">

This StackScript both deploys as well as provides a library of functions for
PHP. The functions in this StackScript are designed to be run across the 
Linode Core Distributions:
	- Ubuntu
	- CentOS
	- Debian
	- Fedora
"""

import os
import subprocess
import sys

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

import pythonlib


def php_apache_mod_install():
	"""Install Apache httpd PHP module."""
	# add logging support

	package = {
		'debian': 'php5',
		'redhat': 'php'
	}

	pythonlib.system_package_install(package[pythonlib.distro['family']])


#def php_fpm_install():


def php_install():
	"""Install PHP.
	
	Defaults to installing the mod_PHP implemention of PHP.
	"""
	# add logging support

	php_apache_mod_install()


def php_install_module(module, update_index=True):
	"""Install a PHP module."""

	prefix = {
		'debian': 'php5-',
		'redhat': 'php-'
	}

	pythonlib.system_package_install(prefix[pythonlib.distro['family']] + module, update_index)


def php_install_module_common():
	"""Install most common PHP modules.

	Install GD, mcrypt, pear, mysql, and the cli."""
	
	php_install_module("gd")
	#php_install_module("mcrypt", False) #not in CentOS7 repos :(
	#php_install_module("pear", False) # both families use php-pear so
	#installing php5-pear in the Debian family will fail
	php_install_module("mysql", False)
	php_install_module("cli", False)
	restart()


def restart():
	if pythonlib.distro['family'] == "debian":
		subprocess.call(['service', 'apache2', 'restart'])
	elif pythonlib.distro['family'] == "redhat":
		subprocess.call(['systemctl', 'restart', 'httpd'])


def main():
	"""Install PHP."""
	# add logging support
	
	pythonlib.init()
	pythonlib.system_update()
	php_install()

	pythonlib.end()


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