How to migrate website to Amazon EC2 and RWS

We have just migrated a site from Windows Server to Amazon RDS and EC2. Basically, we needed to move to the cloud separating database from the web server. RDS now runs MySQL 5.7 and EC2 runs on Amazon Linux with Apache. Before the start, on our Windows server, we installed putty to be able to connect to the web server and WinSCP to transfer all the files.

Initial desicion was to keep MySQL, but when choosing between Linux distributions, Amazon Linux seemed like a good option. It is based on CentOS, however, it has been heavily modified to suit AWS. After reading quite a bit about it and looking at different benchmark case studies, it looked like a good choice. It is fast and responsive. It is built and maintained by Amazon for better integration with management tools pre-installed. It is getting updated on a 6-month release cycle and upgrading usually goes without any problems. However, this may be not the best option if you need special packages and community support. It took us some time to decide between AL and Ubuntu.

Step 1, Set Up and Adding Security Groups.

Reference http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_SettingUp.html if needed to sign up, create user and login. Once logged in, select the region where our servers will reside in the top right corner, in our case, Oregon.  We now need to create two security groups, one used for RDS database instance and one for EC2 web instance. Click home button and navigate to “VPC” under “Networking”.

Go to “Security Groups” -> “Create Security Group” to create new security group for our RDS instance. Give it a name and description, such as site-name-rds. Select VPC and click create.

Select created group and edit inbound rules. We need to add ip address from which we will be connecting, which is the server we will be transferring database from.

Your ip will be masked as XXX.XXX.XXX.XXX, replace as needed.  Select MySQL/Aurora (3306), add XXX.XXX.XXX.XXX/32 ip address. It is followed by /32 for exact match ip. Use XXX.XXX.XXX.0/24 for a range of all ip addresses in the subnet.

We will later add one more ip of EC2 web instance to this group.

Once again, go to “Security Groups” -> “Create Security Group” to create new security group for our EC2 instance. Give it a name and description, such as site-name-web. Select VPC and click create.

To allow all incoming traffic over HTTP and HTTPS lets add:

HTTP(80) 0.0.0.0/0 and HTTPS(443) 0.0.0.0/0.

Next, we need to be able to SSH, so lets add:

SSH(22) XXX.XXX.XXX.XXX/32

Save.

Step 2, Set Up RDS Instance.

Reference http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_GettingStarted.CreatingConnecting.MySQL.html if needed.

Make sure that the right region where our servers will reside is selected in the top right corner, in our case, Oregon. Click home button and navigate to “RDS” under “Database”.

Click Launch DB Instance. Select MySQL and then MySQL version. We will use 5.7.11, db.t2.small that will give us 1 vCPU and 2Gib RAM. Since this is a production instance, we will use Multi-AZ Deployment for maximum availability. We will also use 12GB on General Purpose SSD for our databases.

Next, we name our insance site-name-cloud-db, chose db username and password and proceed to “Next Step”. Here we pick the right VPC, Subnet Group, leave it publicly accessible and pick our site-name-rds security group. We leave everything else as is, changing only backup window to 14 days.

Launch DB Instance. It is now being created. You can click “View Your DB Instances” and watch the status. Once changed to “available”, we can start using it.

Step 3, Set Up EC2 Instance.

Reference http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Tutorials.WebServerDB.CreateWebServer.html if needed.

Make sure that the right region where our servers will reside is selected in the top right corner, in our case, Oregon. Click home button and navigate to “EC2” under “Compute”.

Before we begin, lets get a key pair that we will need to connect to the server once it is set up. For reference, use http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/get-set-up-for-amazon-ec2.html#create-a-key-pair . On the left side menu, under “network & security” click “Key Pairs”. Click create key pair, give it a name, such as my-site-key-pair, click create and it will be automatically downloaded. Save it in the safe location on your machine.

Next, click on “Instances” on the left menu and click “Launch Instance”.

Select Amazon Linux AMI. For our simple server we pick t2.micro with 1 vCPU and 1GiB of Memory.

Click “Next” to configure instance details, where we left everything default. On the next screen we changed the storage to suit our needs, which is 100GiB general purpose SSD. On the next screen we create a tag of site-name-web and move forward. Next screen gives us an option to pick existing security group site-name-web create earlier.

Click Launch, verify that information is correct, pick key pair created earlier and click “Launch Instances”. It is now being created. Click “View Instances” and watch the status. Once changed to “running”, we can start using it.

Step 4, Add ip of new EC2 Instance to RDS Security Group.

Run this command on EC2 server to get the ip address and get ip in inet addr under eth0

ifconfig

Edit security group for your site-name-rds and add ip or subnet as:

MySQL/Aurora (3306) 172.XX.X.0/24

Save.

Step 5, Set Up putty and Connect.

Launch PuTTYgen. Make sure SSH-2-RSA option is checked. Click “Load”, in the drop down option select “All Files”, locate the .pem file downloaded earlier after creating Key Pairs, “save private key” with the same name and .ppk extension.

Now you need to get your public dns name. Once EC2 instance is loaded, click on it and in the “Description” below copy Public DNS.

Start putty. In the Host Name field enter user@public-dns, such as ec2-user@ec2-XX-XX-XXX-XX.us-west-2.compute.amazonaws.com. Amazon Linux instances get created with ec2-user by default. Confirm that selected port is 22 and connection type is SSH.

Enter the name in “saved sessions”, such as site-name-aws and click save.

On the left hand side menu in putty navigate to Connection – SSH – Auth. Click Browse and locate .ppk key created using PuTTYgen earlier. Go back to “Session” menu, click save and then open. Click “Yes” if it displays a message and you should be on the server and ready to configure.

Step 6, Set Up Web Server.

First, lets update the packages

sudo yum update -y

Next, install apache, php 5.6 and mysql driver

sudo yum install -y httpd24 php56 php56-mysqlnd

Next, additional packages, if needed. For instance, we use gd image library and need to add it

sudo yum install php56-gd

Soap package:

sudo yum install php56-soap

Imagick, which requires php devel, php pear and a few others

sudo yum install kernel-devel gcc gcc-c++

sudo yum install php56-devel

sudo yum install php-pear # This line installs pecl as well as pear

sudo yum install ImageMagick-devel

sudo pecl install imagick

which requires us to open php.ini and append a line at the end of the file to load the library

sudo vi /etc/php.ini

press “i” to edit the file, add this line at the end

extension=imagick.so

click “esc” and “zz” while holding “shift” to save.

Lets start apache

sudo service httpd start

Change config to autostart on boot

sudo chkconfig httpd on

Add www group and current user to that group along with apache group

sudo groupadd www

sudo usermod -a -G www ec2-user

Lets change permissions on www folder, exit the server and re-login

sudo chown -R root:www /var/www

exit

This is it for the web server, however, we host a couple websites on it. We will create virtual hosts next

cd /var/www/

sudo mkdir vhosts

cd vhosts

sudo mkdir site-1(actual name of the site)

sudo mkdir site-2(actual name of the site)

sudo chown -R root:www /var/www

sudo chmod 2775 /var/www

find /var/www -type d -exec sudo chmod 2775 {} \;

find /var/www -type f -exec sudo chmod 0664 {} \;

cd /etc/httpd/conf.d

sudo touch vhost.conf

sudo vi /etc/httpd/conf.d/vhost.conf

paste and replace site-1.com and site-2.com with actual sites:


# Leave this alone. This setting tells Apache that

# this vhost should be used as the default if nothing

# more appropriate is available.

ServerName default:80

# REQUIRED. Set this to the directory you want to use for

# your “default” site files.

DocumentRoot /var/www/html

# Optional. Uncomment this and set it to your admin email

# address, if you have one. If there is a server error,

# this is the address that Apache will show to users.

#ServerAdmin you@example.com

# Optional. Uncomment this if you want to specify

# a different error log file than the default. You will

# need to create the error file first.

#ErrorLog /var/www/vhosts/logs/error_log

 

# REQUIRED. Set this to the host/domain/subdomain that

# you want this VirtualHost record to handle.

ServerName site-1.com

# Optional. You can specify additional host names that

# serve up the same site. This can be top-level, domains,

# sub-domains, and can even use wildcard subdomains such

# as *.yourdomain.com – just separate each host name

# with a single space.

ServerAlias www.site-1.com

# REQUIRED. Set this to the directory you want to use for

# this vhost site’s files.

DocumentRoot /var/www/vhosts/site-1

# Optional. Uncomment this and set it to your admin email

# address, if you have one. If there is a server error,

# this is the address that Apache will show to users.

#ServerAdmin you@example.com

# Optional. Uncomment this if you want to specify

# a different error log file than the default. You will

# need to create the error file first.

ErrorLog /var/www/vhosts/logs/site-1_error_log

# REQUIRED. Let’s make sure that .htaccess files work on

# this site. Don’t forget to change the file path to

# match your DocumentRoot setting above.

AllowOverride All

 

# REQUIRED. Set this to the host/domain/subdomain that

# you want this VirtualHost record to handle.

ServerName site-2.com

# Optional. You can specify additional host names that

# serve up the same site. This can be top-level, domains,

# sub-domains, and can even use wildcard subdomains such

# as *.yourdomain.com – just separate each host name

# with a single space.

ServerAlias www.site-2.com

# REQUIRED. Set this to the directory you want to use for

# this vhost site’s files.

DocumentRoot /var/www/vhosts/site-2

# Optional. Uncomment this and set it to your admin email

# address, if you have one. If there is a server error,

# this is the address that Apache will show to users.

#ServerAdmin you@example.com

# Optional. Uncomment this if you want to specify

# a different error log file than the default. You will

# need to create the error file first.

ErrorLog /var/www/vhosts/logs/site-2_error_log

# REQUIRED. Let’s make sure that .htaccess files work on

# this site. Don’t forget to change the file path to

# match your DocumentRoot setting above.

AllowOverride All

Next, lets create log directory

cd /var/www/vhosts/

sudo mkdir logs

Restart apache

sudo service httpd restart

Step 7, Set Up SSL Keys and SSL Virtual Directories.

Download and install WinSCP and import connection configuration from Putty.

Export current certificates from existing site. In our case it was windows server and we used this resource for reference – https://www.sslshopper.com/move-or-copy-an-ssl-certificate-from-a-windows-server-to-an-apache-server.html that gave us site.pfx file. Upload the file to /home/ec2-user via WinSCP.

Now, in our ssh session (putty) we need to convert and store the keys:

cd /home/ec2-user/

openssl pkcs12 -in estoresbyzome.pfx -out estoresbyzome.txt -nodes

copy each key and certificate from and including opening —- , to and including closing of each section while pasting it into site.key, site.crt, and if there is more than 2 – intermidiateCA.crt. Then move them to private folder and change permissions.

sudo cp site.key /etc/pki/tls/private/site.key

sudo cp site.crt /etc/pki/tls/private/site.crt

sudo cp intermediateCA.crt /etc/pki/tls/private/intermediateCA.crt

cd /etc/pki/tls/private/

sudo chmod 600 site.key

sudo chmod 600 site.crt

sudo chmod 644 intermediateCA.crt

Install mod ssl for apache and restart

sudo yum install -y mod24_ssl

sudo service httpd restart

Next, we need to change ssl certificate and key in ssl.conf

sudo vi /etc/httpd/conf.d/ssl.conf

to


SSLCertificateFile /etc/pki/tls/private/site.crt

SSLCertificateKeyFile /etc/pki/tls/private/site.key

sudo service httpd restart

Add virtual host entries:

cd /etc/httpd/conf.d/

sudo vi vhost.conf

At the end of the file add:


ServerName site-1.com

ServerAlias www.site-1.com

DocumentRoot /var/www/vhosts/site-1

SSLEngine on

SSLCertificateFile /etc/pki/tls/private/site.crt

SSLCertificateKeyFile /etc/pki/tls/private/site.key

ErrorLog /var/www/vhosts/logs/site-1_error_log

 

ServerName site-2.com

ServerAlias www.site-2.com

DocumentRoot /var/www/vhosts/site-2

SSLEngine on

SSLCertificateFile /etc/pki/tls/private/site.crt

SSLCertificateKeyFile /etc/pki/tls/private/site.key

ErrorLog /var/www/vhosts/logs/site-2_error_log

Save and restart apache, this should be it

sudo service httpd restart

Step 8, Display Maintenance Message on Live Site.

Since our site uses the same header, displaying maintenance message is as easy as pasting html and php exit at the top of it:


<!doctype html>
<title>Site Maintenance</title>
<style>
body { text-align: center; padding: 150px; }
h1 { font-size: 50px; }
body { font: 20px Helvetica, sans-serif; color: #333; }
article { display: block; text-align: left; width: 650px; margin: 0 auto; }
a { color: #dc8100; text-decoration: none; }
a:hover { color: #333; text-decoration: none; }
</style>

<p><img src="img/logo.gif" alt="Site" title="Site" width="150" height="100" align="left"></p>
<article>
<h1>We&rsquo;ll be back soon!</h1>
<div>
<p>Sorry for the inconvenience but we&rsquo;re performing some maintenance at the moment. We&rsquo;ll be back online shortly!</p>
<p>&mdash; Site-1 Team</p>
</div>
</article>
<?php
exit;
?>

Step 9, Backup Database.

Stop the production db and start with locked tables if exit in the header doesn’t stop complete access before the backup.

mysqldump -u root -p -h 127.0.0.1 site-1-db > c:\Backups\site-1-db(build_date).sql

mysqldump -u root -p -h 127.0.0.1 site-2-db > c:\Backups\site-2-db(build_date).sql

Step 10, Stop Production Database.

Since we are running a Windows server, run this command in command line

net stop mysql

Step 11, Create, Restore the Database and Update Schema.

mysql -u zome -p -h site-cloud-db.your-database-endpoint.us-west-2.rds.amazonaws.com

create database site-2;

exit;

mysql -u zome -p -h site-cloud-db.your-database-endpoint.us-west-2.rds.amazonaws.com site-1-db < c:\Backups\right_backup.sql

mysql -u zome -p -h site-cloud-db.your-database-endpoint.us-west-2.rds.amazonaws.com site-2-db < c:\Backups\right_backup_2.sql

We also had a couple of MyISAM tables and converted them to InnoDB, connect to instance

mysql -u zome -p -h site-cloud-db.your-database-endpoint.us-west-2.rds.amazonaws.com

login and check if there are any MyISAM

use INFORMATION_SCHEMA;

SELECT * FROM `TABLES` where engine = 'MyISAM' and (TABLE_SCHEMA = 'site-1-db' OR TABLE_SCHEMA = 'site-2-db’ ) ORDER BY `ENGINE` DESC

use site-1-db;

ALTER TABLE `myisam-table1` ENGINE=INNODB;

ALTER TABLE `myisam-table2` ENGINE=INNODB;

etc.

Step 12, Transfer Files and change db connections.

Login via WinSCP and transfer all the files to the right vhost directories. Change site configurations to point to the new database.

Step 13, change permissions to write directories for apache.

To make directories writable to apache execute the following command on the directories that need write access:
sudo chown -R root:apache directory-name

Step 14, Test.

To test before going live edit the c:\windows\system32\drivers\etc\hosts file on local machine to point to the right server by specifying ip address:
XXX.XXX.XXX.XXX site-1.com www.site-1.com
XXX.XXX.XXX.XXX site-2.com www.site-2.com

Step 15, Change DNS to Point to the New Site.

If you are using AWS for DNS, navigate to Route 53, if not, point your domain A record to the new ip address. Perform the last set of testing and the site in now on AWS.

This is it

How to set up magento 2 with sample data using Vagrant box on Windows 10 with Ubuntu guest

I have been trying different configurations to set up magento 2 with sample data using Vagrant within the last few days. I am using Windows 10 as host machine and now successfully running Ubuntu 14.04 Trusty Tahr on a guest machine with magento 2 and sample data.

Basically, you will need to set up virtual environment first, download VitualBox and Vagrant. VirtualBox lets you create and run virtual machine within your environment, so head to https://www.virtualbox.org/wiki/Downloads, download and install the latest release first. Vagrant lets you create scripts to preinstall and configure all the packages on a virtual machine. Once configured, you can run a virtual machine with the same configuration from anywhere, destroy and re-create a box that suits your development needs in one simple command. So head to https://www.vagrantup.com/downloads.html to download and install Vagrant.

Next comes the configuration part. We have tried many. Magento 2 is complicated, resource hungry and slow as is. Our goal was to set up a shared folder that we can use for development and a virtual box to run the beast. After tinkering around different file systems and configurations, we have found a simple solution with minimal configuration that gave us satisfactory results. We also need to deploy magento 2 sampledata package, which provides some sample data to play with. It was not possible to get it installed with out of the box configurations due to dependency issues, so we made a little adjustment as explained below.

Basically, vagrant-magento2-apache-base by Alan Kent gave us a headstart on the configuration. Please follow https://github.com/alankent/vagrant-magento2-apache-base and clone the repository but do not start Vagrant with vagrant up yet as we need to make additional changes to the configuration. Using default settings resulted in the following error message when trying to install  sampledata package:


[ReflectionException]
Class Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\Media does not exist

Instead of using magento2 folder that has a copy of magento2 from the repo, we will get a fresh copy from official repo.magento.com. In order to do so, you need to be registered or register with magento connect – https://www.magentocommerce.com/magento-connect/. Login, go to “My Account” -> “Developers” -> “Secure Keys”. Get your public and private keys that are used as a username and password to access Magento GitHub repository.

Next, default configuration that we used, has /magento2 folder with magento code. We are not going to use it. Instead, we need to create a new folder to which we will install the latest magento 2 from the repo from the vagrant machine. Create a new folder in the same folder where you placed /magento2 and /vagrant-magento2-apache-base using Alan’s sample configuration. We will call it /magento_code, but feel free to change the name as you wish.

First, lets update vagrant configuration. Go to /vagrant-magento2-apache-base and open configuration – Vagrantfile in text editor. Replace:


config.vm.synced_folder "../magento2", "/var/www/magento2", :mount_options => ["dmode=777","fmode=666"]

with


config.vm.synced_folder "../magento_code", "/var/www/magento2", :mount_options => ["dmode=777","fmode=666"]

respectively to reflect the changes we made to switch shared folder to a blank folder where magento 2 will be installed during the first vagrant setup run.

While we are here, we need to make additional changes to actually install magento 2 on startup. At the end of the file, right after:


config.vm.provision "shell", path: "scripts/install.sh"

add these two lines, changing your repo.magento.com username (public key) and password (private key). Also, head to github.com and grab your github oauth, as you will need it as well:


config.vm.provision "shell", inline: "echo '{\"http-basic\": {\"repo.magento.com\": {\"username\": \"your_magento_connect_username\",\"password\": \"your_magento_connect_password\"}}, \"github-oauth\": {\"github.com\": \"your_github_oauth\"}}' >> /root/.composer/auth.json"
config.vm.provision "shell", inline: "composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition /var/www/magento2/"

This will install magento2 on startup into /var/www/magento2, which is linked to your empty folder /magento_code

One other change I had to make is adding php5-5.6 repository to vagrant-magento2-apache-base/scripts/install.sh as it is required to run magento2.

Open the file in the text editor and add:


#edit for php 5.6
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php5-5.6
sudo apt-get update

right before #Install MySQL.

Next, open deploy.sh in the same /config folder and add –use-sample-data at the end of install command for magento2, your file should look something like:


#!/bin/sh


# Show what we execute
set -x


cd /var/www/magento2/

# Wipe out all caches
/bin/rm -rf var/*

# Set up, rebuilding database from scratch.
# Port 8080 must match what you expose via Vagrantfile.
php bin/magento setup:install \
--cleanup-database \
--db-host=localhost \
--db-name=magento \
--db-user=magento \
--db-password=secret \
--backend-frontname=admin \
--base-url=http://127.0.0.1:8080/ \
--language=en_US \
--timezone=America/Los_Angeles \
--currency=USD \
--admin-lastname=Smith \
--admin-firstname=John \
--admin-email=john.smith@example.com \
--admin-user=admin \
--admin-password=admin123 \
--use-secure=0 \
--use-sample-data

This is it for configuration. We now follow instructions as described on sample config page and install additions. Open command line, go to /vagrant-magento2-apache-base and enter:


vagrant up

Once the machine is built:


vagrant ssh

Once you are logged in, type:


sudo sh /vagrant/scripts/deploy.sh

This should deploy everything we have predefined.

Next are the set of commands to set up magento 2 as we need it:


cd /var/www/magento2/
php bin/magento setup:static-content:deploy

to deploy static content if the default images on localhost:8080 do not load. Next:


php bin/magento sampledata:deploy

to actually deploy the sample data package. Next:


composer update

to update the dependencies. Next:


php bin/magento setup:upgrade

to upgrade the magento 2 installation with sample data.

This is it. You now should have a fresh magento 2 install with sample data and a virtual box ready for development. Enjoy!

How to show images on new magento 2 installation in Ubuntu

On a new magento 2 install sometimes images and javascript files do not load. To fix it, one of the options is to redeploy static content.

Here is the command to execute from magento2 install directory:

vagrant@vagrant-ubuntu-trusty-64:/var/www/magento2$ php bin/magento setup:static-content:deploy

How to replace Windows new line characters in Ubuntu

I have tried executing a bash script edited in Windows, which gave me an error:

vagrant@vagrant-ubuntu-trusty-64:/var/www/magento2$ sh /vagrant/scripts/deploy.sh
: not foundripts/deploy.sh: 2: /vagrant/scripts/deploy.sh:
/vagrant/scripts/deploy.sh: 4: set: Illegal option -

I tried executing it with bash, which gave me more details showing windows new line character as a problem:

vagrant@vagrant-ubuntu-trusty-64:/var/www/magento2$ bash /vagrant/scripts/deploy.sh
/vagrant/scripts/deploy.sh: line 2: $'\r': command not found
: invalid option/deploy.sh: line 4: set: -

To solve this problem, I replaced Windows new lines with Linux:

sed -i 's/\r$//' /vagrant/scripts/deploy.sh

If you have this problem, replace filename with the name of your file:

sed -i 's/\r$//' filename

Linux Web Hosting

 

 I have purchased Web Hosting Deals site several years ago, just couldn’t get to it yet. Still in it’s original form. I am planning to redo the whole site at some point, sign up with more hosting companies and do complete feature reviews of linux hosting companies.

Meanwhile, please feel free to comment and let us know which Linux hosts you use and why.

How to fix flashing screen after nvidia driver update in Ubuntu

Just tried updating to the latest nvidia drivers and the screen was flashing after reboot. I have tried reinstalling drivers from other repositories but nothing worked. Had to use nouveau to get back to boot and still looking for a solution to get my desktop back to previous state. Anyhow, here is how to switch to nouveau:

At the flashing screen press “Ctrl + Alt + F1” to get to terminal at Ubuntu log in screen.

Log in using your credentials.

Stop X11 by entering this command:

sudo stop lightdm

Remove all nvidia packages by entering this command:

sudo apt-get purge nvidia-*

Install nouveau package by entering this command:

sudo apt-get install xserver-xorg-video-nouveau

Restart:

sudo reboot

or

sudo shutdown -r now

Hope it helps!

How to find files within daterange in Ubuntu

I got a virus that hit all php files on one of my servers and had to find all the files that got affected withing the date of the attack. There are a few methods that you can use:

1) To find the files modified within the last day, type:

find /directory_path -mtime -1 -print

where -1 is 24 hours, -2 – 48, and so on.

2) To find the files within modified date range is trickier. You have to create 2 files with start and end dates like listed below, just replace 20111110 and 20111120 with needed dates.

touch -t 201111101059 /tmp/file1
touch -t 201111201200 /tmp/file2
find . -newer /tmp/file1 -a ! -newer /tmp/file2

That’s it.

How to install gitweb in Ubuntu

After being told that I live in the stone age for using svn, I decided to try out git. Finally I got some time to continue learning git and setting the new environment. As a step one, we learned how to install git on Ubuntu. Then, I decided that I wanted to host my own repositories and we learned how to set up gitosis on Ubuntu. Now, after updating to Ubuntu 11.10 – Oneiric Ocelot, I am ready to continue setting up everything I need to start conveniently using git. So, in this post, I will be setting up the gitweb and documenting the process.

Gitweb is a convenient GUI that allows us to quickly see the project and diffs right in the browser. Before we move on to installing git web, make sure you have installed apache. Now, lets move on to installing gitweb:

sudo apt-get install gitweb

Now lets look in our /var/www folder:

cd /var/www

ls

I didn’t have gitweb folder here, so I created it:

sudo mkdir /var/www/gitweb

gitweb files should be in /usr/share/gitweb and we need them in our /var/www/gitweb, so lets create a symbolic link that will point to the files:

cd /var/www/gitweb

sudo ln -s /usr/share/gitweb/* .

To check if these are symbolic links, you can type:

ls -l

it should show what these files are linked to.

Next, locate the path to your git repositories. As per our install, we have it in /home/git/repositories. So, lets edit gitweb config to point to the right directory:

sudo gedit /etc/gitweb.conf

and replace:

$projectroot = "/var/cache/git";

to our path to git repositories, /home/git/repositories in my case to:

$projectroot = "/home/git/repositories";

Save the file and lets move on to next step – editing apache configuration. Open apache config for gitweb:

sudo gedit /etc/apache2/conf.d/gitweb

And edit it as follows (replace the paths if yours are different):

    RewriteEngine on
    RewriteRule ^/gitweb/([a-zA-Z0-9_\-]+\.git)/?(\?.*)?$ /cgi-bin/gitweb.cgi/$1 [L,PT]

    Alias /gitweb /home/git/repositories

    Options Indexes FollowSymlinks ExecCGI
    DirectoryIndex /cgi-bin/gitweb.cgi
    AllowOverride None

and save. Now its time to restart apache to apply the changes:

sudo /etc/init.d/apache2 restart

I got an error at first saying:

Syntax error on line 1 of /etc/apache2/conf.d/gitweb:
Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
The Apache error log may have more information.
...fail!

Which was because I needed to add rewrite package to apache:

sudo a2enmod rewrite

This time apache started with no errors.

Now you should be able to go to http://localhost/gitweb and see the gitweb page. If you have no public repositories yet, you may see “404 – No projects found” notice. To test it out, I went to my repo folder:

cd /home/git/repositories/

and changed the permissions on my gitosis-admin.git:

sudo chmod -R 755 gitosis-admin.git

Refresh the localhost/gitweb and ta-da! It shows a repository where I could click around and check things out. Since I didn’t want this repo to show publicly, I had to change the permissions back to:

sudo chmod -R 750 gitosis-admin.git

This is it for now. In the next git series posts I will try to go over creating new repositories, adding users, general git usage, installing redmine for project management and anything else I may find useful.

How to restore Unity when it disappears in Ubuntu 11.10

Well, after playing around the compizConfig Setting Manager I somehow screwed up the whole system. Unity along with any kind of menu was gone. Terminal Windows did not come up when pressing ALT+F# and even ctrl+alt+delete were not working. The only way terminal was able to come up was by pressing Ctrl+Alt+T . I did

unity --reset

but it did not work. What worked for me was typing:

ccsm

and enabling it again, disabling everything else that was conflicting. Hope this helps in case you are looking for the solution. :)

How to configure Unity in Ubuntu 11.10

I have been poking around the new Unity settings in Oneiric Ocelot.

First, check if you have compizconfig settings manager. If not, install by typing the following command in the terminal window:


sudo apt-get install compizconfig-settings-manager

Then go to unity dash and start typing compiz – it should show you the settings manager. Click it and go to “Desktop” options. I guess unity is a part of compiz now and this is where you can find “Ubuntu Unity Plugin” settings to edit the appearance.

I am kind of upset to see that there is no option to move the dock around. :(