Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. from fabric.api import *
  2. from fabric.operations import *
  3. from fabric.contrib.project import rsync_project
  4. from fabric.contrib.files import exists
  5.  
  6. import sys, os
  7.  
  8. abspath = lambda filename: os.path.join(
  9. os.path.abspath(os.path.dirname(__file__)),
  10. filename
  11. )
  12.  
  13. # --------------------------------------------
  14. # LAMP stack cofiguration
  15. # --------------------------------------------
  16.  
  17. class FabricException(Exception):
  18. pass
  19.  
  20. def dev():
  21. print "Connecting to remote machine"
  22.  
  23. env.setup = True
  24. env.user = 'ubuntu'
  25. env.ubuntu_version = '16.04'
  26. env.warn_only = True
  27. #env.password = 'ubuntu'
  28. env.key_filename = abspath('keyfile.pem')
  29. env.hosts = [
  30. 'A.B.C.D'
  31. ]
  32.  
  33. env.server = 'localhost' #may be public IP also
  34. env.output_prefix = False
  35. env.graceful = False
  36.  
  37. env.apache_config_path = '/etc/apache2/apache2.conf'
  38. env.apache_directory_path = '/etc/apache2/mods-enabled'
  39. env.apache_directory_config = abspath('dir.conf')
  40. env.php_file = ('info.php')
  41.  
  42.  
  43. env.rsync_exclude = [
  44. "*.py",
  45. "*.pyc"
  46. ]
  47. return
  48.  
  49.  
  50. # --------------------------------------------
  51. # Installing Dev Platform
  52. # --------------------------------------------
  53.  
  54. def install():
  55. print 'Start installing LAMP stack in ubuntu 16.04'
  56. update()
  57. install_apache()
  58. install_mysql()
  59. install_php()
  60. test_php()
  61. print 'Finished installing LAMP'
  62. return
  63.  
  64. def update():
  65. print 'Start updating the system'
  66. sudo('apt-get update')
  67.  
  68. def install_apache():
  69. print 'Installing and configuring apache web server'
  70. sudo('apt-get install apache2 -y')
  71. sudo("apache2ctl configtest")
  72. sudo('echo "ServerName %s" >> %s' %(env.server, env.apache_config_path))
  73. sudo("apache2ctl configtest")
  74.  
  75. def install_mysql():
  76. print 'Installing and configuring mysql'
  77. sudo('apt-get install mysql-server -y')
  78. sudo('mysql_secure_installation')
  79.  
  80. def install_php():
  81. print 'Installing php '
  82. sudo('apt-get install php libapache2-mod-php php-mcrypt php-mysql -y')
  83. default_config = '/etc/apache2/mods-enabled/dir.conf'
  84. if exists(default_config):
  85. sudo('rm %s' %default_config)
  86. print 'Deleted apache default directory config'
  87.  
  88. print 'Install new apache directory configuration'
  89. put('%s' % (env.apache_directory_config), '%s/' % (env.apache_directory_path), use_sudo=True)
  90. sudo('systemctl restart apache2')
  91.  
  92. def test_php():
  93. print 'Testing php application'
  94. sudo('mkdir -p /var/www/html/')
  95. put('%s' % (env.php_file), '/var/www/html/', use_sudo=True)
  96. sudo('curl %s/%s' %(env.server, env.php_file))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement