PHP, Perl, MySQL web programming tutorials, howtos for beginners and novice users

Posted on in Categories Apache, FAQ, Howto, Linux, MySQL, UNIX last updated June 6, 2007

The motto of this site is learn with pictures, not words:

In Pictures tutorials began as part of a research study we conducted for the U.S. Department of Education. The goal: to make it easier for people with learning disabilities to learn computer subjects.

As part of the study, we created simple, illustration-based tutorials. Everyone who tested them–not just people with learning disabilities–said the new tutorials enabled them to learn faster and easier than conventional text-heavy books.

The site offers tutorials on common Linux web programming subject:
=> PHP

=> Perl

=> MySQL

Great work! (Thanks to E@zyVG for a hat tip)

Howto optimize Apache and PHP for performance

Posted on in Categories Apache, Linux, Sys admin, Tips, Tuning, UNIX last updated May 28, 2007

Learn what slows Apache web server down, and how to get the most out of PHP.

Linux, Apache, MySQL, and PHP (or Perl) form the basis of the LAMP architecture for Web applications. Many open source packages based on LAMP components are available to solve a variety of problems. As the load on an application increases, the bottlenecks in the underlying infrastructure become more apparent in the form of slow response to user requests. The previous article showed you how to tune the Linux system and covered the basics of LAMP and performance measurement. This article focuses on the Web server components, Apache and PHP.

From the article:

Applications using the LAMP (Linux®, Apache, MySQL, PHP/Perl) architecture are constantly being developed and deployed. But often the server administrator has little control over the application itself because it’s written by someone else. This series of three articles discusses many of the server configuration items that can make or break an application’s performance. This second article focuses on steps you can take to optimize Apache and PHP.

This article focused on tuning the Web server, both Apache and PHP. With Apache, the general idea is to eliminate extra checks the Web server must do, such as processing the .htaccess file. You must also tune the Multi-Processing Module you’re using to balance the system resources used with the availability of idle workers for incoming requests. The best thing you can do for PHP is to install an opcode cache. Keeping your eye on a few resource settings also ensures that scripts don’t hog resources and make the system slow for everyone else.

Tuning LAMP systems, Part 2: Optimizing Apache and PHP

Can someone steal my PHP script without hacking server?

Posted on in Categories Apache, Howto, lighttpd, Linux distribution, Networking, php, Security, Tips, Troubleshooting last updated May 2, 2007

Adarsh asks:

Can someone steal my PHP code or program without hacking my Linux box? Can someone snoop script over plain HTTP session?

Short answer is no. PHP is server side thingy.

However a misconfigured webserver can easily give out php file to all end users. You need to make sure that mod_php / mod_fastcgi loaded and correct MIME type is setup. To avoid such problem always test your server before moving to production environment. Most Linux distro configures both Apache and PHP out of box.

How do I stop downloading php source code?

The first step should be stopping a webserver.
# /etc/init.d/httpd stop
OR
# /etc/init.d/lighttpd stop

If you are using Lighttpd…

Next bind webserver to 127.0.0.1 for testing purpose. Open lighttpd websever config file and bind server address to 127.0.0.1
# vi /etc/lighttpd/lighttpd.conf
Bind to localhost/127.0.0.1:
server.bind = "127.0.0.1"
Start lighttpd:
# /etc/init.d/lighttpd start
Now follow these instructions to configure php as fastcgi module. Now test your configuration using url http://127.0.0.1/test.php. PHP should work on server. If not working, refer to server log file.

If you are using Apache…

Open httpd.conf file and bind apache to 127.0.0.1:
# vi httpd.conf
The Listen directive instructs Apache to listen to more than one IP address or port; by default it responds to requests on all IP interfaces, but only on the port given by the Port directive.
Listen 127.0.0.1:80
Start apache:
# /etc/init.d/httpd start
Now make sure php is installed use apt-get or rpm command to verify the same:
# rpm -qa | grep -i php
OR
# dpkg --list | grep -i php
If PHP is not installed just follow these instructions to install PHP. Next make sure httpd.conf or php.conf has following directives:
LoadModule php4_module modules/libphp4.so
AddType application/x-httpd-php .php

Note: the path may differ in your setup. Now restart httpd:
# /etc/init.d/httpd restart
A sample php code:

<HTML><HEAD>PHP</TITLE></HEAD>
<BODY>
<?php   phpinfo(); ?>
</BODY>
</HTML>

Finally when php started to work properly, make sure you bind back a server IP address from 127.0.0.1 to public IP address.

Another option is keep your source code out of webroot and server all php requests from php application server using mod_proxy and multiple back-end servers.

Howto Setup Active Directory Authentication With Apache WebServer

Posted on in Categories Apache, Linux, Windows server last updated April 28, 2007

Recently I was doing some consultancy work and they need to authenticate users using Active Directory service. However you need to compile Apache web server to add LDAP bindings. Apache LDAP allows an LDAP directory to be used to store the database for HTTP Basic authentication.

Next load LDAP module, configure directory security and you are done.

You don’t have to install and use samba package 🙂

There is a good howto that explains configuration parameters and other stuff.

How to Configure Apache Authentication with Active Directory

Open Source Parking Spoofing Headers to Benefit Apache

Posted on in Categories Apache, lighttpd last updated April 4, 2007

OpenSourceParking.com is a domain parking service that helps Free Software and Open Source. Domain parking provides a place-holder web page for an undeveloped domain name.

According to netcraft:

An open source initiative to reverse gains for Microsoft web server software appears to be using edited server headers to try and improve the showing of the Apache web server. Sites using the Open Source Parking service report that they are running on Apache, but appear to actually be hosted on lighttpd. Both Apache and lighttpd are open source web servers, but Apache leads in the Netcraft survey with a 59 percent market share, while lighttpd is a newcomer with just 1.2% share.

This may be implemented for security reasons. There is no need to create a fake open source parking spoofing headers to benefit Apache. Both are open source and robust web servers. Personally this site runs using Lighttpd because of limited resources. Generally I use lighttpd to push static content (images, cached HTML pages and other files) and use Apache for real work :).

How to optimize a web page for faster and better experience

Posted on in Categories Apache, High performance computing, Howto, lighttpd, Linux, Tips, Tuning, UNIX last updated March 21, 2007

You may have noticed that most my webpage are loading bit faster. Here is what I did:

a) CSS code moved to its own file and included CSS at the top

b) Removed unnecessary (read as fancy web 2.0 stupid stuff) external javascript snippets

c) I’ve moved external javascript to bottom of page/template engine. For example google analytics JS code moved to bottom of webpage.

d) Turn on Apache gzip/mod_deflate compression

e) Turn on WordPress caching

f) Turn on php script caching (I’m using eAccelerator)

g) Tweak MySQL for optimization. Turn on query cache and other settings.

h) If possible switch to lighttpd or use squid / lighttpd as caching server for old good Apache.

If you have tons of cash to burn (assuming that your web app demands performance):

  • Consider using CDN (Content Delivery Network) such as Akamai or SAVVIS.
  • Server load balancing

However there are some external JS script snippets such as Google Adsense which slows down loading of a webpage. In few months I may roll out a new template and I will try to fix this issue 🙂

I’m interested to know what other people’s experiences with web page optimization. Feel free to share your tips.

Apache httpd debugging Logs on steroids

Posted on in Categories Apache, Debian Linux, FreeBSD, Gentoo Linux, Howto, Linux, Suse Linux, Ubuntu Linux, UNIX last updated February 1, 2007

This article talks about little known or unknown Apache httpd log mods and tips.

Apache httpd’s standard text logfiles are well understood and useful, but they don’t always give you enough information to troubleshoot problems. Apache 2.x provides several new modules that produce more logfile information–the number of bytes transferred, the rewrite rule matching, which requests complete and why, and the complete output of all headers. Rich Bowen explores these options.

Making Apache httpd Logs More Useful

Extract and decompile .chm file to view as html file under Linux

Posted on in Categories Apache, Debian Linux, Download of the day, Linux desktop, RedHat/Fedora Linux, Suse Linux, Ubuntu Linux last updated January 22, 2007

You can view .chm file using gnochm or kchmviewer under Linux. However sometime you cannot install these programs. There is a third alternative – arCHMage.

From the man page:
arCHMage is an extensible reader and decompiler for files in the CHM format. This is the format used by Microsoft HTML Help, and is also known as Compiled HTML. arCHMage is based on python-chm binding to chmlib from GnoCHM project.

It allows you extract .chm to directory.

Step # 1: Use apt-get command

If you are using Debian / Ubuntu, type the command:
# apt-get install archmage

Step # 2: Extract .chm to directory (directory will be created):

Type the command:
$ archmage file.chm output

Open your browser and type url file:///home/you/output or file:///home/you/output/index.html

Other usage

You can view chm file using inbuilt http-server.

View chm file using Webserver

You can run archmage as http-server, which will publish chm file contents on specified port:
# archmage -p 8888 /path/to/file.chm &

Open a browser and type ulr http://localhost:8888/ or http://server-ip:8888/

Force apache to publish chm files

You can force Apache to publish chm file contents if there is trailing slash in request to that file. First make sure you have working mod_python. Now open httpd.conf /apache2.conf file:
# vi httpd.conf

Add following lines to your httpd.conf:
AddHandler python-program .chm
PythonHandler archmod.mod_chm

Save and close the file. Restart apache.
# /etc/init.d/httpd restart

Now upload file.chm to document root of your Apache webserver. Now view file by typing URL: http://you.com/file.chm/

Note: trailing slash at the end of URL.

Download arCHMage

=> Download arCHMage

Howto migrate from Microsoft Internet Information Server (IIS) to Apache on Linux

Posted on in Categories Apache, RedHat/Fedora Linux, Tips, Windows server last updated January 6, 2007

This is an interesting article.

For people migrating from Windows to Linux, the Apache Web server is entirely different world from Microsoft Internet Information Server. Apache can be alienating to IIS / Windows administrators, because migrating to Apache is more than just copying files.

The IIS to Apache migration process needs to be handled with the same care and perspective as the process of migrating desktops and their attendant applications. In some cases, IIS to Apache may be even more difficult and may have a larger impact on users and administrators.

In this article, author talk about the process of migrating a site from IIS to Apache, with Red Hat Linux as the specific target.