Last active
December 20, 2015 07:19
-
-
Save amineasli/6092796 to your computer and use it in GitHub Desktop.
A Makefile for managing web projects on Ubuntu Server. It assumes that these environments are already setup and running correctly : LAMP environment : https://help.ubuntu.com/community/ApacheMySQLPHP, GIT server : http://git-scm.com/book/en/Git-on-the-Server-Setting-Up-the-Server, FTP server : https://help.ubuntu.com/10.04/serverguide/ftp-server…
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
AuthUserFile /path/.htpasswd | |
AuthName "Authorization required" | |
AuthType Basic | |
require valid-user |
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
all: | |
cat Makefile | |
ifndef NAME | |
$(error You didn\'t define NAME!) | |
endif | |
#Database credentials | |
ROOT = root | |
MPASS = mypass | |
HOST = localhost | |
#Configuations variables | |
PROJECT = /home/projects | |
WWW = $(HOME)/dev/web | |
GITHOME = $(HOME)/$(NAME).git | |
HOME = $(PROJECT)/$(NAME) | |
#Commands and system variables | |
MCLIENT = /usr/bin/mysql | |
MSERVER = mysql | |
RPASS := $(shell makepasswd --char=5) | |
HTPASS := $(shell makepasswd --char=5) | |
MKDIR = /bin/mkdir -p | |
FSHELL = /usr/bin/false | |
CHOWN = chown -R | |
CHMOD = chmod -R | |
FTPD = vsftpd | |
SERV = /usr/bin/service | |
ESC = $(shell echo $(WWW) | sed 's/\//\\\//g') | |
ESCH = $(shell echo $(HOME) | sed 's/\//\\\//g') | |
APACHE = /etc/apache2/sites-available/ | |
RM = /bin/rm -fR | |
LOG = $(NAME).txt | |
HOOKS = $(HOME)/hooks | |
GIT = /usr/bin/git | |
project-create: log-create db-create ftp-create site-create git-create | |
project-delete: log-delete db-delete ftp-delete site-delete git-delete | |
ftp-create: | |
$(MKDIR) $(HOME) | |
useradd $(NAME) -d $(PROJECT)/$(NAME) -s /usr/bin/false -p `echo $(RPASS) | makepasswd --clearfrom=- --crypt-md5 | awk '{print $$2}'` | |
$(CHMOD) a-w $(HOME) | |
$(MKDIR) $(HOME)/dev | |
$(CHOWN) $(NAME) $(HOME) | |
$(MAKE) ftp-restart | |
echo "FTP User = $(NAME)" >> $(LOG) | |
echo "FTP Password = $(RPASS)" >> $(LOG) | |
echo "FTP Home Directory = $(HOME)" >> $(LOG) | |
ftp-delete: | |
userdel $(NAME) | |
$(MAKE) ftp-restart | |
ftp-restart: ftp-stop ftp-start | |
ftp-stop: | |
$(SERV) $(FTPD) stop | |
ftp-start: | |
$(SERV) $(FTPD) start | |
db-create: | |
$(MCLIENT) --user=$(ROOT) --password=$(MPASS) -e "CREATE DATABASE $(NAME); GRANT ALL PRIVILEGES ON $(NAME).* TO '$(NAME)'@'$(HOST)' IDENTIFIED BY '$(RPASS)' WITH GRANT OPTION; FLUSH PRIVILEGES;" | |
echo "Database = $(NAME)" >> $(LOG) | |
echo "Database User = $(NAME)" >> $(LOG) | |
echo "Database Password = $(RPASS)" >> $(LOG) | |
db-delete: | |
$(MCLIENT) --user=$(ROOT) --password=$(MPASS) -e "GRANT USAGE ON *.* TO '$(NAME)'@'$(HOST)'; DROP USER '$(NAME)'@'$(HOST)'; DROP DATABASE IF EXISTS $(NAME); FLUSH PRIVILEGES;" | |
mysql-restart: mysql-stop mysql-start | |
mysql-stop: | |
$(SERV) $(MSERVER) stop | |
mysql-start: | |
$(SERV) $(MSERVER) start | |
site-create: | |
sed -e 's/\/var\/www/$(ESC)/' -e 's/error/error-$(NAME)/' -e 's/access/access-$(NAME)/' -e 's/host/$(NAME)/' -e 's/\/yourpath/$(ESC)/' < vhost > $(APACHE)$(NAME) | |
$(MKDIR) $(WWW) | |
htpasswd -b -c $(HOME)/.htpasswd $(NAME) $(HTPASS) | |
sed -e 's/\/path/$(ESCH)/' < .htaccess > $(WWW)/.htaccess | |
$(CHOWN) $(NAME):www-data $(WWW) | |
$(CHMOD) 775 $(WWW) | |
$(CHMOD) g+s $(WWW) | |
a2ensite $(NAME) | |
$(MAKE) apache-reload | |
echo "Website Home Directory = $(WWW)" >> $(LOG) | |
echo "Password Authorization = $(HTPASS)" >> $(LOG) | |
site-delete: | |
a2dissite $(NAME) | |
$(RM) $(APACHE)$(NAME) | |
$(RM) $(WWW) | |
$(RM) $(HOME)/.htpasswd | |
$(MAKE) apache-reload | |
apache-restart: apache-stop apache-start | |
apache-stop: | |
$(SERV) apache2 stop | |
apache-start: | |
$(SERV) apache2 start | |
apache-reload: | |
$(SERV) apache2 reload | |
git-create: | |
$(MKDIR) $(GITHOME) | |
cd $(GITHOME) ; $(GIT) --bare init | |
sed -e 's/theproject/$(NAME)/g' < post-receive > $(GITHOME)/hooks/post-receive | |
$(CHMOD) +x $(GITHOME)/hooks/post-receive | |
$(CHOWN) git $(GITHOME) | |
echo "Git Repository = $(GITHOME)" >> $(LOG) | |
git-delete: | |
$(RM) $(GITHOME) | |
log-create: | |
touch $(LOG) | |
log-delete: | |
$(RM) $(LOG) |
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
#!/bin/sh | |
unset GIT_INDEX_FILE | |
export GIT_WORK_TREE=/home/projects/theproject/dev/web | |
export GIT_DIR=/home/projects/theproject/theproject.git | |
git checkout -f |
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
<VirtualHost *:80> | |
ServerAdmin contact@localhost | |
DocumentRoot /var/www | |
ServerName host.localhost | |
<Directory /> | |
Options FollowSymLinks | |
AllowOverride None | |
</Directory> | |
<Directory /var/www/> | |
Options Indexes FollowSymLinks MultiViews | |
AllowOverride All | |
Order allow,deny | |
allow from all | |
</Directory> | |
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ | |
<Directory "/usr/lib/cgi-bin"> | |
AllowOverride None | |
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch | |
Order allow,deny | |
Allow from all | |
</Directory> | |
ErrorLog /var/log/apache2/error.log | |
# Possible values include: debug, info, notice, warn, error-pac, crit, | |
# alert, emerg. | |
LogLevel warn | |
CustomLog /var/log/apache2/access.log combined | |
</VirtualHost> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To create a project simply execute the following command : sudo make project-create NAME=my_project_name