Last active
July 7, 2017 16:41
-
-
Save shudarshon/a4268b46f5af0703cdf5ed2940c6bfea to your computer and use it in GitHub Desktop.
This script installs LAMP stack in Ubuntu 16.04 which is based on fabric library of python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<IfModule mod_dir.c> | |
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm | |
</IfModule> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
phpinfo(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment