Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from fabric.api import *
- from fabric.operations import *
- from fabric.contrib.project import rsync_project
- from fabric.contrib.files import exists
- import sys, os
- abspath = lambda filename: os.path.join(
- os.path.abspath(os.path.dirname(__file__)),
- filename
- )
- # --------------------------------------------
- # LAMP stack cofiguration
- # --------------------------------------------
- class FabricException(Exception):
- pass
- def dev():
- print "Connecting to remote machine"
- env.setup = True
- env.user = 'ubuntu'
- env.ubuntu_version = '16.04'
- env.warn_only = True
- #env.password = 'ubuntu'
- env.key_filename = abspath('keyfile.pem')
- env.hosts = [
- 'A.B.C.D'
- ]
- env.server = 'localhost' #may be public IP also
- env.output_prefix = False
- env.graceful = False
- env.apache_config_path = '/etc/apache2/apache2.conf'
- env.apache_directory_path = '/etc/apache2/mods-enabled'
- env.apache_directory_config = abspath('dir.conf')
- env.php_file = ('info.php')
- env.rsync_exclude = [
- "*.py",
- "*.pyc"
- ]
- return
- # --------------------------------------------
- # Installing Dev Platform
- # --------------------------------------------
- def install():
- print 'Start installing LAMP stack in ubuntu 16.04'
- update()
- install_apache()
- install_mysql()
- install_php()
- test_php()
- print 'Finished installing LAMP'
- return
- def update():
- print 'Start updating the system'
- sudo('apt-get update')
- def install_apache():
- print 'Installing and configuring apache web server'
- sudo('apt-get install apache2 -y')
- sudo("apache2ctl configtest")
- sudo('echo "ServerName %s" >> %s' %(env.server, env.apache_config_path))
- sudo("apache2ctl configtest")
- def install_mysql():
- print 'Installing and configuring mysql'
- sudo('apt-get install mysql-server -y')
- sudo('mysql_secure_installation')
- def install_php():
- print 'Installing php '
- sudo('apt-get install php libapache2-mod-php php-mcrypt php-mysql -y')
- default_config = '/etc/apache2/mods-enabled/dir.conf'
- if exists(default_config):
- sudo('rm %s' %default_config)
- print 'Deleted apache default directory config'
- print 'Install new apache directory configuration'
- put('%s' % (env.apache_directory_config), '%s/' % (env.apache_directory_path), use_sudo=True)
- sudo('systemctl restart apache2')
- def test_php():
- print 'Testing php application'
- sudo('mkdir -p /var/www/html/')
- put('%s' % (env.php_file), '/var/www/html/', use_sudo=True)
- sudo('curl %s/%s' %(env.server, env.php_file))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement