Category Archives: Debian&Ubuntu

How to Mount a Remote Folder using SSH on Ubuntu

Connecting to a server across the internet is much more secure using SSH. There is a way that you can mount a folder on a remove server using the SSHFS service.

There are quite a few steps that you’ll have to follow, so get ready and open a terminal window.

First we’ll install the module:

sudo apt-get install sshfs

Now we will use the modprobe command to load it

sudo modprobe fuse

We’ll need to set up some permissions in order to access the utilities. Replace <username> with your username.

sudo adduser <username> fuse
sudo chown root:fuse /dev/fuse
sudo chmod +x /dev/fusermount

Since we’ve added ourselves to a user group, we need to logout and back in at this point before we continue.

Now we’ll create a directory to mount the remote folder in. I chose to create it in my home directory and call it remoteserv.

mkdir ~/remoteserv

Now we have the command to actually mount it. You’ll be prompted to save the server key and for your remote password.

sshfs <username>@<ipaddress>:/remotepath ~/remoteserv

Now you should be able to cd into the directory and start using it as if it was local.

cd ~/remoteserv
root@ubuntu:~/remoteserv$ ls -l

To unmount sshfs enter this command

fusermount -u ~/remoteserv

FAQ: Debian&Ubuntu

  1. How to install enable apache mod_rewrite on ubuntu?

    sudo a2enmod rewrite
    To get installed Apache modules: apache2ctl -t -D DUMP_MODULES

  2. Install PHP 5.4 on Ubuntu 10.04/11.10/12.04

  3. Install LAMP

    sudo apt-get install lamp-server^
    Ubuntu 12.04 LTS (Apache2, BIND, Dovecot, ISPConfig 3)
    Install LAMP and phpMyAdmin on Ubuntu 11.10 

  4. Where is httpd.conf for setting up apache ?

    On Ubuntu the main Apache configuration file is actually apache2.conf. Apache2.conf contains the default configuration for Apache on Ubuntu. Apache2.conf includes httpd.conf for “user configurations”.
    httpd.conf is usually the main configuration file for the Apache web server. This is the case on Red Hat Enterprise Linux (RHEL), CentOS and Mac OS X

    Where is Httpd.conf’s Location on Ubuntu?
    HTTPD – Apache2 Web Server

  5. Zip a Folder in Linux

    To zip a folder:         zip -9 -r <zip file> <folder name>
    To zip a single file:   zip -9 <zip file> <filename>
    Use “-9” for best compression.

Installing memcached on ubuntu

Memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.
Memcached on Ubuntu has two components. A standalone program running on your server and a client PHP extension.
To install memcached, run the following command:

sudo aptitude install memcached php5-memcache php-pear
Creating config file /etc/php5/conf.d/memcache.ini with new version
sudo aptitude install php5-dev  libmemcached-dev
sudo pecl install Memcache
Installing '/usr/lib/php5/20090626+lfs/'

Please choose

Enable memcache session handler support? [yes] : yes

Find your php.ini file and execute following command

php -i | grep php.ini
nano /etc/php5/apache2/php.ini

Add the line to the bottom of the file: memcache.hash_strategy=”consistent”

memcached -d -m 1024 -l -p 11211

If you get a message saying, “can’t run as root without -u switch” then try this:

memcached -d -u www-data -m 1024 -l -p 11211

To active new configuration execute following command

/etc/init.d/apache2 restart
/etc/init.d/memcached restart

Verify memcached

pgrep -fl memcached
netstat -an | grep 11211

Check memcached status

memcached -u www-data -vv
ps -A | grep memcached

There are either procedural, or object oriented functions already available. Here is an example of a script which will store a simple variable and then retrieve it and display it.

/* procedural API */
if (class_exists('Memcache')) {
    $memcache = new Memcache;
	try {
	 /* connect to memcached server */
	$memcache_obj = memcache_connect('localhost', 11211);
	} catch (Exception $e) { print_r($e);}
	if ($memcache_obj) {
	/*set value of item with key 'var_key' using 0 as flag value,
         * compression is not used expire time is 30 seconds*/
	memcache_set($memcache_obj, 'var_key', 'some variable', 0, 30);
	echo memcache_get($memcache_obj, 'var_key');

I’d recommend downloading memcache.php which is a php script showing you a lot of useful information about your memcached servers. Once downloaded, put it in a web facing directory on your server, and modify the $MEMCACHE_SERVERS array with your server addresses.

How to run the shell or bash scripts from php?

I have a bash script that I want to be run from php using a passthru function.
if you don’t need any output you can use shell_exec or exec without
escapeshellcmd function

$command=’/bin/bash / ‘;
$escaped_command = escapeshellcmd($command);
passthru($escaped_command, $output);
$output is returning the exit code that the php interpreter gives to the shell:
0 – successful execution of the program, this means that the script doesn’t work as expected on php side, but does on the unix box;
1 – file not found, run as root or use sudo to access via php;
2 – script completed successfully
127 –file not found;

My script is

#Copy images
echo  | sudo -S cp -av /var/www/

Creating Subdomains using command line

I have a server running Debian 5. I am serving multiple web applications using Apache2.

The setup I currently have is partially successful. I have a static IP. I also have a number of subdomains resolving to my IP address. These subdomains are:

If you have control over your DNS you can setup ‘wildcard hosting’, which means you can have a web server accept connections for any given subdomain. This can be enormously useful for community websites, or other hosting purposes.

Here is an example of the entry you’ll need to add:

* IN A

Once you have your DNS entries setup you can alter your Apache virtual hosts to add an appropriate ServerAlias entry. This will allow Apache to treat a number of hostnames as equivilent.

Create host configuration files in /etc/apache2/sites-available:

nano /etc/apache2/sites-available/

A typical VirtualHost would look something like this:

<VirtualHost *:80>

     DocumentRoot /var/www/wordpress/public_html/
     ErrorLog   /var/www/wordpress/logs/error.log
     CustomLog  /var/www/wordpress/logs/access.log combined

To allow this server to serve multiple other valid hostnames we simply add a ServerAlias setting:

<VirtualHost *:80>
     DocumentRoot /var/www/wordpress/public_html/
     ErrorLog   /var/www/wordpress/logs/error.log
     CustomLog  /var/www/wordpress/logs/access.log combined

Create a symbolic link to those files in the sites-enabled directory:


Activate new configuration:

/etc/init.d/apache2 reload

Check the relation between domain and IP address by ping