Kategori arşivi: Ubuntu

git workflow ubuntu www

on ubuntu:

install git

create repo (home git repos)

make .git repo and sub files’ group and owner -> git

in repo hook folder, create “post-receive” and paste this:

#!/bin/sh
git –work-tree=/var/www/[cloned-git-folder] –git-dir=/home/git/repos/[repo-name].git checkout -f

(above work-tree and git-dir commands starts with two – sign)

clone git in var/www

make cloned www folder group -> www-data, owner -> git

connect ssh repo with git user because remote git repo post-receive file’s owner and group is git user


in usr/local/bin create command file like “pull-reponame”

paste this:

#!/bin/sh
cd /var/www/[cloned-repo-folder]
git stash && git pull

you can make owner any user and group git

add execute permission to git group

add any user to git group to allow running this command shortcut

ubuntu 14 apache ssl activate, create self signed certificate, configure virtual host

sudo a2enmod ssl
sudo service apache2 restart
sudo mkdir /etc/apache2/ssl
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/your_domain.key -out /etc/apache2/ssl/your_domain.crt
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:New York
Locality Name (eg, city) []:New York City
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Your Company
Organizational Unit Name (eg, section) []:Department of Kittens
Common Name (e.g. server FQDN or YOUR name) []:your_domain.com
Email Address []:your_email@domain.com
sudo nano /etc/apache2/sites-available/default-ssl.conf
<IfModule mod_ssl.c>
  <VirtualHost _default_:443>
       		....
  </VirtualHost>

  <VirtualHost _default_:443>
	ServerName www.your_domain.com
	ServerAlias your_domain.com
	DocumentRoot /var/www/your_domain.com
		
	ErrorLog ${APACHE_LOG_DIR}/error_your_domain_com_ssl.log
	CustomLog ${APACHE_LOG_DIR}/access_your_domain_ssl.log common	
			
	SSLEngine on
	SSLCertificateFile /etc/apache2/ssl/apache.crt
        SSLCertificateKeyFile /etc/apache2/ssl/apache.key
  </VirtualHost>
</IfModule>
sudo a2ensite default-ssl.conf
sudo service apache2 restart
RewriteEngine on

RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

RewriteCond %{HTTPS} !on
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
https://your_domain.com

apache maintanance

Create a file called maintenance.conf with the following in it:

#RewriteEngine On
#RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
#RewriteCond %{REQUEST_FILENAME} !/maintenance.html
#RewriteRule ^.*$    /maintenance.html [L]

Then setup your vhosts like:

<VirtualHost *>
  ServerAdmin admin@website.com
  DocumentRoot /var/www/website
  ServerName  website.com
  ServerAlias www.website.com      

  Include conf/maintenance.conf
</VirtualHost>

Then when you want to enable maintenance mode, just uncomment those lines in maintenance.conf and restart apache.

Alternatively you could make maintenace.conf.disabled and maintenace.conf.enabled. Then create a symbolic link for maintenance.conf to point to the enabled or disabled version of the file and bounce apache.

You could even wrap doing that in a script. One called enabled-maintence-mode.sh and disable-maintenance-mode.sh that would remove and create the symbolic links respectively and restart apache.