Looking for Open Source Help??? Here is Blog for it's A-to-Z. Attempt is to crawl along all the codes & concepts
Wednesday, June 27, 2007
What you need to get started with PHP
Before you can write and test your PHP scripts, there's one thing you'll need - a server! Fortunately, you don't need to go out and buy one. In fact, you won't be spending any extra money. That's why PHP is so popular! But because PHP is a server-sided scripting language, you either have to get some web space with a hosting company that supports PHP, or make your computer pretend that it has a server installed. This is because PHP is not run on your PC - it's executed on the server. The results are then sent back to the client PC (your computer).
Don't worry if this all sounds a little daunting - we've come across an easier way to get you up and running. We're going to be using some software called "EasyPHP". This allows you to test your PHP scripts on your own computer. Over a million people have downloaded this software. It installs everything you need, if you have a Windows PC (Win9x/Me/NT/2000/XP). We'll explain how to get it installed in a moment, and where to get it from. But just a word for non-windows users.
Apple Users
If you have OS 10, then try this guy's site to get up and running with PHP. The link to click on is "PHP Apache Module (NEW version 5)"
http://www.entropy.ch/software/macosx/
Another useful page is:
http://farm.tucows.com/blog/_archives/2004/7/20/108833.html
You can also have a look at this site:
http://www.phpmac.com/browse.php?type=tut&cat=2
Linux Users
There's quite a few sites out there to help Linux users get up and running with the Apache server and PHP. Here's two sites that are worth checking out:
http://www.e-gineer.com/v1/instructions/install-php4x-for-apache1xx-on-linux.htm
http://www.phpfreaks.com/tutorials/12/0.php
If you know any better ones, we'd be interested in hearing from you!
Windows Users
OK, back to Easy PHP and Windows. First, you need to download the software. You can get it from here (this site is nothing to do with ours, by the way):
Download Easy PHP
Be sure to click the link for Installation Guide, as well as the link for Downloads. The file you need to download is EasyPHP. Once you have downloaded the file, double click to install.
Quick Tips to Optimize MySQL
Since MySQL optimization is a significant topic and often specific to your application, let’s instead focus on obtaining some quick results that can lead to more in-depth investigation and customization.
First, you should also deploy MySQL on the right hardware. MySQL is memory hungry, so install as much RAM as you can afford. Once installed, tune MySQL to use memory for its various buffers. Fast disks and sufficient CPU are next, respectively.
Next, the official MySQL binaries, unlike many applications, come extremely well-tuned. If you’re not an expert user, you are almost certainly better off using the packages pre-built for your platform.
On the topic of packages, many distributions ship with MySQL pre-installed. This is convenient, but may not allow you to stay current with the latest stable version of MySQL. You’ll need to make a decision on whether it’s best for your organization to forgo distribution support for MySQL (say, if you’re using an enterprise distribution) and benefit from the enhancements and bug fixes provided by MySQL AB. If you’re not using a distribution that comes with a support contract, this may be less of a concern.
Regardless of which option you choose, you may find that you lack a MySQL configuration file present, which results in general, default settings. By default, MySQL is extremely resource-friendly, but that can be a performance killer. If you don’t have an /etc/my.cnf file, creating one should be your first step in tuning.
What settings to change and the values of those parameters are specific to your hardware and workload, so you’ll need to do some research to find your own optimal settings. How do you know if your settings are appropriate?
Two tools can help you deduce an answer: mytop and mysqlreport. The former is described online at http://www.linux-mag.com/2001-12/mysql_01.html; mysqlreport transforms the values from the SHOW STATUS command into an easy-to-read report that provides an in-depth understanding of how MySQL is running. You can download mysqlreport from http://hackmysql.com/mysqlreport.
Spend a little time experimenting and reading the MySQL documentation and benchmark your changes with mytop and mysqlreport.
Once you know MySQL is running like a well-oiled machine, there are other things you can do to improve performance.
*Be sure to enable the query cache — but also be sure that you’re code takes advantage of that cache. The cache for a table is invalidated every time the table is written to. Hence, if you write to a table to update a timestamp with every page view, the cache is almost of no use. One way to avoid “cache misses” is to create a HEAP table, write the timestamps to that table, and then regularly batch the updates to your main table.
*Remember that MySQL optimization goes beyond just tuning mysqld. You should also look closely at query optimization and making sure you have the proper indexes on your tables. An errant JOIN, even on relatively small tables, can result in a huge dataset being returned and significant table locking. Using EXPLAIN will help you better understand how MySQL will process the query you are looking into.
*If you’re not sure which queries to optimize, enable the slow query log, which logs queries that take more than a specified amount of time. By focusing on slow queries in your real world environment, you can hasten overall, actual performance.
*Mix MySQL storage engines on a per-table basis. You can use MyISAM tables for heavily read tables or for tables that require FULLTEXT search. Use InnoDB tables if you need row level locking and transactions.
*If you reach the maximum capacity of a single machine, replicate your databases to multiple machines. Send all writes to the single master and distribute the reads to as many slaves as you need to keep up with demand.
Even simple, gross optimization efforts like the ones described here can make a remarkable difference. With appropriate hardware and a little work, MySQL scales much further than it did just a few years ago, and is now powering some of the busiest sites on the web.
-from http://www.linux-mag.com.
Linux Magic SysRq Key
According to the Linux kernel documentation:
It is a 'magical' key combo you can hit which the kernel will respond to regardless of whatever else it is doing, unless it is completely locked up.
The sysrq key is one of the best (and sometimes the only) way to determine what a machine is really doing. It is useful when a system appears to be "hung" or for diagnosing elusive, transient, kernel-related problems.
How do I enable and disable the SysRq key?
To use it, you need to have it enabled in your kernel (CONFIG_MAGIC_SYSRQ).
It usually is.
For security reasons, Red Hat Enterprise Linux disables the SysRq key by default. To enable it, run:
# echo 1 > /proc/sys/kernel/sysrq
To disable it:
# echo 0 > /proc/sys/kernel/sysrq
kernel.sysrq = 1
Since enabling sysrq gives someone with console access extra abilities, it is recommended to disable it when not troubleshooting a problem or to ensure that console access is properly secured.
There are several ways to trigger a sysrq event. On a normal system, with an AT keyboard, sysrq events can be triggered from the console with the following key combo:
Alt+PrintScreen+ [CommandKey]
For instance, to tell the kernel to dump memory info (command key "m"), you would hold down the Alt and Print Screen keys, and then hit the m key.
Note that this will not work from an XWindows screen. You should first change to a text virtual terminal. Hit Ctrl+Alt+F1 to switch to the first virtual console prior to hitting the sysrq key combo.
On a serial console, you can achieve the same effect by sending a Breaksignal to the console and then hitting the command key within 5 seconds.
If you have a root shell on the machine (and the system is responding enough for you to do so), you can also write the command key character to the /proc/sysrq-trigger file. This is useful for triggering this info when you are not on the system console or for triggering it from scripts.
# echo 'm' > /proc/sysrq-trigger
If you find that holding three keys is difficult, you do have some other choices. You can trigger it manually:
echo t > /proc/sysrq-trigger
Or, you can make the Alt-SysRq "sticky" by:
echo 1 > sysrq-sticky
With that done, you can hold Alt-SysRq, release it, and then leisurely press "t" or whatever key you wanted.
You could also change the SysRq itself in /proc/sys/kernel/sysrq-key (it's normally 84 - Alt-SysRq for Intel).
When I trigger a sysrq event that generates output, where does it go?
When a sysrq command is triggered, the kernel will print out the information to the kernel ring buffer and to the system console. This information is normally logged via syslog to /var/log/messages.
Unfortunately, when dealing with machines that are extremely unresponsive, syslogd is often unable to log these events. In these situations, provisioning a serial console is often recommended for collecting the data.
· m - dump information about memory allocation
· t - dump thread state information
· p - dump current CPU registers and flags
· c - intentionally crash the system (useful for forcing a disk or netdump)
· s - immediately sync all mounted filesystems
· u - immediately remount all filesystems read-only
· b - immediately reboot the machine
· o - immediately power off the machine (if configured and supported)
Alt+SysRq+r takes keyboard and mouse control from the X server. This can be useful if the X-Server crashed, you can change to a console and kill the X-Server or check the error log.
Alt+SysRQ+k kills all processes on the current terminal. Its a bad idea to do this on a console where X is running. The graphic will stop and you cant see what you type.
Alt+SysRQ+b is like a reset: a reboot without umounting or sync.
Alt+SysRQ+o shuts down via APM.
Alt+SysRQ+s writes all data from the disc cache to the hard discs, its a sync.
Alt+SysRQ+u remounts all mounted file system read-only. After using this key, you can reboot the system with Alt+SysRQ+b without harming the system.
Alt+SysRQ+m prints memory information to the console.
Alt+SysRQ+e sends SIGTERM to all processes except init.
Alt+SysRQ+i sends SIGKILL to all processes except init.
Alt+SysRQ+l sends SIGKILL to all processes, inclusive init. (The system is not working after using this.)...
Linux is very stable, but sometimes a kernel panic could happen, sometimes this stops the X-server and you can’t change to the console. What should be done? Hitting the reset button and risk filesystem integrity?
NO! There is a possibility to shut down the system cleanly or find out the source of the kernel panic.
To shut down the system after a really bad kernel panic, do the following:
Alt+SysRQ+e (sends TERM-signal, processes can shutdown properly (e.g. save data))
Alt+SysRQ+u (a sync will be done when unmounting anyway)
Alt+SysRQ+i (for the processes that didn't listen for the TERM signal, this is a kill -9 process)
Alt+SysRQ+b (reboot).
Monday, June 11, 2007
PHP(Part: III):-MySQL Installation
- Run the MSI file and use the following settings
- Typical Setup
- Skip Sign-Up
- make sure "Configure the MySQL Server now" is checked
- "Detailed Configuration"
- "Developer Machine"
- "Multifunctional Database"
- "InnoDB Tablespace Settings" - leave everything default
- "Decision Support (DSS)/OLAP"
- make sure "Enable TCP/IP Networking" is checked and leave the port number at 3306 (at this point, if you have a firewall, it will usually try to access itself on the localhost)
- "Standard Character Set"
- check "Install As Windows Service"
- enter your root password and I would recommend leaving "Enable root access from remote machines" unchecked
- then hit "execute" and it'll install and set it up.
3.Getting PHP5 to work with MySQL -
Unfortunately PHP5 removed built-in support for MySQL. To get it to work, the easiest way is to copy the mysql library file by hand. Open the folder you unzipped your PHP to. Copy the libmysql.dll file (should be located like E:\php\libmysql.dll ) into your Window's System folder (usually C:\Windows\System32\ although might be C:\WinNT\System\ or something).
Then open up your php.ini in a text editor and search for ;extension=php_mysql.dll and remove the ; infont of that line
Restart Apache and see if you get any errors. If it complains about "php_mysql.dll" either your extension directory isn't correct or windows can't find libmysql.dll
Testing MySQLTesting MySQL is not exactly easy. However, here are the common connection strings for PHP and CGI. I recommend downloading phpMyAdmin and using it to create and manage your databases, etc.
PHP Connection test
?>?>?>?>?>?>
PHP(Part: II):-PHP Installation
PHP (Part: I):-Apache Installation
Apache 2.2.X:-
1.Download & Unpack
Download and install Apache from http://httpd.apache.org/download.cgi. Look for the "Win32 Binary (MSI Installer)" version. (you might want to change the download mirror first to get better speeds)
My file was named: apache_2.2.4-win32-x86-no_ssl.msi
2.Install
When you install Apache, you'll get a prompt for "Server Information." Here is the settings I used:Network Domain: localhost
Server Name: localhost
Admin Email: (your any email)
[checked]: for All Users, on Port 80, as a Service
3.Starting/Stopping Apache
After installing, Apache2 automatically starts. The icon in the System Tray means it started. The icon means the "Monitor Apache Servers" is running, but Apache2 isn't started.You can easily start/stop/restart Apache and Apache2 via that icon in your System Tray. If you get "The requested operation has failed!" error while starting apache use the "Test Configuration" shortcut in the Start Menu to find the error (if the text window pops up then closes before you can read it, your config file is fine).
4.Testing
Now the ultimate test. To see if it's serving. Open your browser and head to: http://127.0.0.1/ or http://localhost/If it shows the It works! you have your server software installed and running.
5.Making Apache point to your files
Using Notepad open E:\Apache2_2\conf\httpd.conf (in the start-menu there should also be a "Edit the Apache HTTP Server httpd.conf Configuration File" shortcut) and search for DocumentRoot. Change it from something like DocumentRoot "E:/Apache2_2" to the location where your HTML files and site are located. In my case: DocumentRoot "E:/public_html"
6.Then scroll down about one page and change: