Monday, March 14, 2011

EC2 EBS UBUNTU 10.04 VIRTUALMIN

Few notes about how to set up an EBS AMI UBUNTU 10.04 on AMAZON EC2 with Webmnin/Virtualmin.
This is not a comprehensive how-to but may help some people.


UBUNTU 10.04
pick your ami @ http://uec-images.ubuntu.com/releases/10.04/release/
ami-3e02f257


ssh -i /.ssh/yourkeypair.pem ubuntu@your-ip-address

sudo apt-get update

sudo tasksel --section server
tab select
basic ubuntu server, dns server, lamp server, mail server, openssh server, ubuntu entreprise cloud, virtual machine host
**password**

**if you need to change php5 eg:
sudo aptitude install php5-imap
sudo /etc/init.d/apache2 restart


sudo apt-get install phpmyadmin
**password**

WEBMIN
http://www.kelvinwong.ca/2010/05/22/installing-webmin-on-ubuntu-server-10-04-lts-lucid/
sudo aptitude -y install perl libnet-ssleay-perl openssl libauthen-pam-perl libpam-runtime libio-pty-perl libmd5-perl apt-show-versions libapt-pkg-perl

wget http://ftp.debian.org/pool/main/libm/libmd5-perl/libmd5-perl_2.03-1_all.deb
sudo dpkg -i libmd5-perl_2.03-1_all.deb

wget http://sourceforge.net/projects/webadmin/files/webmin/1.530/webmin_1.530_all.deb/download

sudo dpkg -i webmin_1.530_all.deb
OR (if not working) sudo dpkg -i download

sudo /usr/share/webmin/changepass.pl /etc/webmin root PASSWORD
sudo /etc/init.d/webmin start

LOGIN WEBMIN

IMPORTANT UPDATE WEBMIN BEFORE ANYTHING ELSE**********************
WEBMIN CONFIGURATION

install virtualmin (install via webmin modules install from computer)
save on desktop:
http://download.webmin.com/download/virtualmin/virtual-server-3.83.gpl.wbm.gz
http://download.webmin.com/download/virtualmin/virtual-server-theme-7.9.wbt.gz

Configure Postfix:
sudo vi /etc/postfix/main.cf
and add:
virtual_alias_maps = hash:/etc/postfix/virtual
sudo /etc/init.d/postfix reload


sudo vi /etc/dhcp3/dhclient.conf
uncomment #prepend domain-name-servers 127.0.0.1;
Webmin->networking->Hostname and DNS Client
Swap Resolution order as 127.0.0.1 should be first


sudo vi /etc/hosts
replace 127.0.0.1 localhost
by
127.0.0.1 localhost.localdomain localhost
ip domain.com domain

sudo vi /etc/hostname
domain.com

APACHE MOD SUEXE OFF
Virtualmin (Server Templates:Apache Website:Automatically add appropriate SuExec directive? set it to "No")
CLICK "CUSTOM" & no

check ftpdpro server module is on



**Good to have a look to
Webmin->Apache Webserver->Global-configuration->configure Apache modules


*************************************
if error "pma_tracking" in phpmyadmin
*************************************
editing /etc/phpmyadmin/config.inc.php and added
$cfg['Servers'][$i]['tracking'] = 'pma_tracking';
to the $cfg['Servers'][$i] section


*********************
CURL
******************
sudo apt-get install curl libcurl3 libcurl3-dev php5-curl php5-mcrypt
sudo /etc/init.d/apache2 restart



When you set up a website/domain you need to do as following:
Virtualmin->Create virtual server

Now the server is almost ready.
Virtualmin->Services->DNS Domain
create two A records
Click on Address
Name: ns1.yourdomain.com
Address: Your Elastic IP

Name: ns2.yourdomain.com
Address: Your Elastic IP / or you can register to a service like www.dyndns.com www.opendns.com

Back on Edit Master Zone->Click on Name server
(you can edit the existing one)
Name: your domain.com
Name server: ns1.yourdomain.com

Name: your domain.com
Name server: ns2.yourdomain.com /or something else.


****************************************
Last thing: create an image when it works ;-)

Wednesday, September 1, 2010

WP: hide photos uploaded by other in Media Upload and Media Library

Tested on WordPress 3.0

A user with the capacity of uploading doesn't need to see what other have uploaded before.

To do so we need to hack a little bit WP core because this process is unpluggable right now.

We need to change two files:
wp-admin/includes/media.php
wp-admin/edit-attachements-row.php (for this one css can be used instead of a hack)

1. media.php
Around line 1122 replace function get_media_items with this

function get_media_items( $post_id, $errors ) {
$attachments = array();
if ( $post_id ) {
$post = get_post($post_id);
if ( $post && $post->post_type == 'attachment' )
$attachments = array($post->ID => $post);
else
$attachments = get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC') );
} else {
if ( is_array($GLOBALS['wp_the_query']->posts) )
foreach ( $GLOBALS['wp_the_query']->posts as $attachment )
$attachments[$attachment->ID] = $attachment;
}

$output = '';
foreach ( (array) $attachments as $id => $attachment ) {
if ( $attachment->post_status == 'trash' )
continue;

#HACK#
global $current_user;
$getid = get_post($id);
$aut = $getid->post_author;

if (( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) )&& ($current_user->user_level == 10)) {
$output .= "\n<div id='media-item-$id' class='admin media-item child-of-$attachment->post_parent preloaded'><div class='progress'><div class='bar'></div></div><div id='media-upload-error-$id'></div><div class='filename'></div>$item\n</div>";
}
elseif (( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) )&& ($aut==$current_user->ID)){
$output .= "\n<div id='media-item-$id' class='user media-item child-of-$attachment->post_parent preloaded'><div class='progress'><div class='bar'></div></div><div id='media-upload-error-$id'></div><div class='filename'></div>$item\n</div>";

}
#END HACK#
}

return $output;
}

2.edit-attachements-row.php

Around line 45 Before
<tr id='post-<?php echo $id; ?>' class='<?php echo trim( $alt . ' author-' . $post_owner . ' status-' . $post->post_status ); ?>' valign="top">
add
<?php if ($current_user->ID == $post->post_author){#HACK# ?>

Around line 229 Before
<?php endwhile; ?>
add
<?php } #END HACK# ?>

Tuesday, July 6, 2010

Integrating Galleriffic/NextGen to a Wordpress theme

Links: WordPress - Galleriffic - NextGen Gallery
Download nextgen-gallery/view/gallery.php

I've been using the following code on louisebaker.com.au. If you know how to create a wp theme this could help:

Basically what you have to do is to rewrite the output of the NextGen plugin.

create a page template in your theme (eg photo.php) and put galleriffic's code in:
<div id="gallery" class="">
<div id="controls" class="controls"></div>
<div id="loading" class="loader"></div>
<div id="slideshow" class="slideshow"></div>
</div>

don't forget to add the css & javascript links.

Then you need to edit wp-content/plugins/nextgen-gallery/view/gallery.php
find the <!-- Thumbnails --> section. This is where is the output code and replace it by

<div id="thumbs" class="navigation">
<ul class="thumbs noscript">
<!-- Thumbnails -->
<?php foreach ($images as $image) : ?>
<li>
<!--<div id="ngg-image-<?php echo $image->pid ?>" class="ngg-gallery-thumbnail-box" <?php echo $gallery->imagewidth ?> >
<div class="ngg-gallery-thumbnail" >-->
<a class="thumb" href="<?php echo $image->imageURL ?>" title="<?php echo $image->description ?>" <?php echo $image->thumbcode ?> >
<img title="<?php echo $image->alttext ?>" alt="<?php echo $image->alttext ?>" src="<?php echo $image->thumbnailURL ?>" width="78" height="78"<?php // echo $image->size ?> />
</a>
<!--</div>
</div>
<?php if ( $gallery->columns > 0 && ++$i % $gallery->columns == 0 ) { ?>
<br style="clear: both" />
<?php } ?>-->
</li>

All you need now is to call a gallery in a page [nggallery id=4]