search files by content text using find and grep

Image

This post is about a simple task – but I always forget the syntax. Search recursively for files inside the current directory with a special text in the file content.

find . -name "*.*" -print | xargs grep "SEARCHTEXT" --color=auto

This snippet searches for all files of the current directory that match the name parameter *.* (so you could e.g. search for all .css files with -name “*.css”). The result is displayed with grep – using the nice color-highlighting.

This is especially useful for remove access on linux machines or other unix-based devices.

Plesk 8 installation on debian 4

Installing Plesk 8.x on debian 4.x “etch” seems a bit uncommon, but the mixture of a rockstable and secure base system as debian and the common webserver management interface Plesk makes sense.

How to install Plesk on debian

  1. Install a fresh debian and perform a dist-upgrade:
    apt-get update && apt-get dist-upgrade
  2. Add the following line to the apt sources list located at /etc/apt/sources.list (replace 8.2.1 and etch with your versions)
    deb http://autoinstall.plesk.com/debian/PSA_8.2.1 etch all
  3. Force apt-get to update database with new information from Plesk
    apt-get update
  4. Install Plesk base system with apt-get, say Yes to accept the packages from Plesk that have a problematic signature.
    apt-get install psa
  5. Install Plesk Autoupdate module with apt-get:
    apt-get install psa-autoinstaller
  6. Install package with PHP5 suport for Plesk
    apt-get install psa-php5-configurator
  7. Restart PSA – don’t forget this! Otherwise you’ll get 404 errors instead the login page.
    /etc/init.d/psa restart
  8. Access the fresh installed Plesk interface with your browser (replace your-server-name with the url/ip of your server). The default login is admin, the default password setup.
    https://your-server-name:8443/
  9. That’s it. The rest can be done via the Plesk interface.

More information can be found in the Plesk v8.2.1 build82070918.10 for Debian-4.0 x86_64 Release Notes.

Change admin password

Change admin password in Plesk

Plesk provides a nice script to change the admin password: /usr/local/psa/admin/bin/ch_admin_passwd

More information how to use it can be found at http://support.theplanet.com/knowledgebase/users/kb.php?id=10598

You should shutdown mysql before performing this and not break the execution of the script. It takes some time! Otherwise you might get this:

Broken database PSA in MySQL

After changing the passwort as described above, the following error message was displayed in the mysql log file and on the console – e.g. when starting plesk.:

Incorrect information in file: psa/xxx.frm

This indicates a broken database index. Since the tables in the psa database are InnoDB tables, the InnoDB recovery tools are interesting. I tried and googled for about an hour, without success. Finally, I just tried to restart the whole server. And then the server was available again, Plesk was running and the errors where gone.

What was the reason? Interupting the password changing script might have caused the trouble. The database files haven’t been closed properly on the filesystem level, which has been fixed with the reboot of the operating system.

Subdomain working as catch-all

In this article you’ll learn to configure Plesk that it uses one subdomain as catch-all for all non-existing subdomains.

Why you would need catch all subdomains

Maybe you have a few subdomains. But sometimes your visitors are accessing non-existing subdomains. So the best solution would be to either redirect them to your main website or at least show them a list of available pages.
Here comes the catch-all subdomain : There you can either configure Apache that it redirects all accesses to the main webpage (via 301, as written e.g. in this article Migrate domain names with .htaccess ) or just have a static (or dynamic, of course) page displayed to the user.

Step-by-step configuration

  1. Create a subdomain z-WILDCARD in Plesk – of course in the admin section of the right domain.
    Why do we need this name? ’cause this entry should be the last entry in the list of subdomains, otherwise this “trick” will not work. So if you have a domain as e.g. zabalula , than you should maybe name the subdomain zzzz-WILDCARD or similar.
  2. Add special configuration (catchall for all subdomains) to the vhosts.conf file of this subdomain.
    Normally it’s located in /srv/www/vhosts/domain.com/subdomains/z-WILDCARD/conf/vhosts.conf. You have to create it – normally you need the root user to do this. Copy the following content into the file:
    ServerAlias *.domain.com
  3. Apply the new configuration – recreate the Apache configuration. You have to run the tool websrvmng which is a Plesk tool that manages and creates the webserver configuration. Execute the following as root user.
    /usr/local/psa/admin/sbin/websrvmng -u --vhost-name=domain.com
  4. Finally – restart Apache to load the new configuration, also as root.
    apache2ctl restart

That’s it – now you can try accessing non-existing subdomains as e.g. doesnotexists.domain.com and you should see the Plesk page displayed for new pages. Next step would be to e.g. add the 301 redirect or use a custom page.

Note: This has been tested with Plesk 8 and Suse Linux. Please leave a comment if this also works on other version of Plesk / linux – or something did not work.

Enable mod_rewrite on SuSE Linux

Description of the problem

By default, SuSE doesn’t enable the mod_rewrite rewrite module. It’s installed, but not enabled.
Follow these steps to install it.

Solution – enable mod_rewrite on SuSE linux

  1. Edit the file /etc/sysconfig/apache2as root:
    1. search for APACHE_MODULES, you should find a line like this
      APACHE_MODULES="suexec access actions alias auth auth_dbm autoindex cgi dir env expires include log_config mime negotiation setenvif userdir ssl php4"
    2. Add rewrite to the content in the list between the “
    3. Save the changes and quit
  2. run SuSEconfig to update the apache configuration files
  3. run /etc/init.d/apache2 restart to restart the Apache server

Now, the mod_rewrite is enabled and integrated.

Check if mod_rewrite is installed and integrated in Apache

You can check this e.g. with the following php file. Create a file in your document root of your webserver (default on SuSE: /srv/www/htdocs) and copy the following content into this file:

<?php phpinfo(); ?>

When you view this file with your browser, search for rewrite – you should find one entry. If not – check if you did all steps 1 to 3.

Test .htaccess rewrite rule on SuSE linux Apache

The next step is to create an initial .htaccess rewrite rule to test if it’s working now. Create a file .htaccess in your document root (default on SuSE: /srv/www/htdocs) with the following content:

Options +FollowSymlinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule user/(.*)$ /user.php?user=$1
</IfModule>

This is a simple rule that redirects all urls with the format user/something to the script /user.php with the something as parameter user. The IfModule prevents Apache errors when mod_rewrite should disappear.

If this doesn’t work – there is another pitfall of the default SuSE Apache installation: you’re not allowed to create custom .htaccess files! So – lets enable them

Enable custom Apache .htaccess mod_rewrite files on SuSE linux

  1. Edit the file /etc/apache2/default-server.confwith your prefered editor
    1. Search for AllowOverride – it should be below the line <Directory "/srv/www/htdocs">
    2. Change AllowOverride None to AllowOverride All – this will allow custom .htaccess rewrite rules
    3. Save your changes and exit
  2. run SuSEconfig to update the apache configuration files
  3. run /etc/init.d/apache2 restart to restart the Apache server

That’s all, now you can test the .htaccess rewrite rule again and it will work.