What is Difference between worker and prefork

Apache (HTPD) is  very popular and widely deployed web server arround the world. A-Patchy server comes with multiple modules. The term MPM is used for multiprocessing module. We can check for default mpm by running this command “ httpd -l ”

Apache 2 is available with following 2 MPM modules.

PREFORK
WORKER

(mpm_winnt This Multi-Processing Module is optimized for Windows NT.)
(mpm_netware Multi-Processing Module implementing an exclusively threaded web server optimized for Novell NetWare)

A) Prefork MPM

A prefork mpm handles http requests just like older Apache 1.3. As the name suggests it will pre-fork necessary child process while starting Apache. It is suitable for all those websites which don’t want threading for compatibility. i.e for non-thread-safe libraries . It is also known as the best MPM for isolating each incoming http request.

How it works: – A single control (master) process is responsible for launching multiple child processes which serves incoming http requests. Apache always tries to maintain several spare (not-in-use) server processes, which stand ready to serve incoming requests. In this way, clients do not need to wait for a new child processes to be forked before their requests can be served.
We can adjust this spare process through the Apache configuration. Default settings are usually enough for small amount of traffic. One can always tune those Directives / Values as per their requirements.

Pre-Fork is the default module given by Apache.

# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# ServerLimit: maximum value for MaxClients for the lifetime of the server
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule prefork.c>
StartServers       8
MinSpareServers    5
MaxSpareServers   20
ServerLimit      256
MaxClients       256
MaxRequestsPerChild  4000
</IfModule>

B) Worker MPM

A worker mpm is an Multi-Processing Module (MPM) which implements a hybrid multi-process multi-threaded server. By using threads to serve requests, it is able to serve a large number of requests with fewer system resources than a process-based server.

The most important directives used to control this MPM are ThreadsPerChild, which controls the number of threads deployed by each child process and MaxClients, which controls the maximum total number of threads that may be launched.

Strength : Memory usage and performance wise its better than prefork
Weakness : worker will not work properly with languages like php

How it works : – A single control process (the parent) is responsible for launching child processes. Each child process creates a fixed number of server threads as specified in the ThreadsPerChild directive, as well as a listener thread which listens for connections and passes them to a server thread for processing when they arrive.

Apache always tries to maintain a group of spare or idle server threads, which stand ready to serve incoming requests. In this way, clients do not need to wait for a new threads or processes to be created before their requests can be served. The number of processes that will initially launched is set by the StartServers directive. During operation, Apache assesses the total number of idle threads in all processes, and forks or kills processes to keep this number within the boundaries specified by MinSpareThreads and MaxSpareThreads. Since this process is very self-regulating, it is rarely necessary to modify these directives from their default values. The maximum number of clients that may be served simultaneously (i.e., the maximum total number of threads in all processes) is determined by the MaxClients directive. The maximum number of active child processes is determined by the MaxClients directive divided by the ThreadsPerChild directive

# worker MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule worker.c>
StartServers         4
MaxClients         300
MinSpareThreads     25
MaxSpareThreads     75
ThreadsPerChild     25
MaxRequestsPerChild  0
</IfModule>

Apache / HTTPD : No space left on device: Cannot create SSLMutex

It is true that life teaches you new lesson every day… Yesterday for first time I came across the server where I was unable to restart apache / httpd service on server. It looked bit strange but after checking error.log if found following errors ..

Apache: No space left on device: Cannot create SSLMutex

After searching on web I found that Apache is leaving a bunch of stray semaphore sets lying around after an attempted restart of httpd / apache. In lay man’s term “semaphore” is a dead object in memory or locked process in operation… huh !!!! Don’t worry, there is a way out for this .. we need to list and grep those processes (dead processes)  and terminate all such locked instances of apache. Use following command to list those processes.

ipcs -s | grep apache

Most likely you will see a fairly large list here. You need too, and it is safe too, have these deleted. The following command will again do the trick:

ipcs -s | grep apache | awk ' { print $2 } ' | xargs -n 1 ipcrm -s 

Note: If your apache is running as nobody or another user, be sure to substitute that other user in place of  apache above.
————————————————————————————————————-

;Cannot create SSLMutex solution

;
At the heart of the problem, is most likely a poorly configured Apache server. By default, SSMutex is configured to the default setting, as it was on this one server of ours. If you read the Apache.org pages for mod_ssl configuration, they have this to say about the default setting:

;

The following Mutex types are available:

none | no

This is the default where no Mutex is used at all. Use it at your own risk. But because currently the Mutex is mainly used for synchronizing write access to the SSL Session Cache you can live without it as long as you accept a sometimes garbled Session Cache. So it’s not recommended to leave this the default. Instead configure a real Mutex.

;

There are of course optional configuration settings. At the very least, it is suggested that you set SSLMutex to sem, which will let Apache choose which SSLMutex type to use.

You will most likely find this setting in the ssl.conf file located at /etc/httpd/conf.d.

Configure Sendmail to log “Subject” line for each email sent.

Hi Friends,
In this article we will learn how to configure sendmail so that you can log “Subject” in /var/log/maillog as by default sendmail does not log Subject to maillog file.

This is really interesting. Business people many times are interested in getting mail log files analyzed. To analyse mail logs they need various field to appera in mail logs. e.g. “From”“To”“Subject” etc from the sent email. By default sendmail logs From and To fields but it does not log Subject field. In this article you will learn how to enable sendmail to log “Subject”.

  • First of all take backup of your “sendmail.mc” and “sendmail.cf” files. Default location for those files is /etc/mail.
  • Now open “sendmail.mc” in your favourite editor and add following lines in it and save it. I usually prefere to add it at boottom of file so you can easily identify your modifications.

LOCAL_CONFIG
Klog syslog
HSubject: $>+CheckSubject

LOCAL_RULESETS
SCheckSubject
R$* Press TAB Key $: $(log Subject: $1 $) $1

This last line is very crusial. after R$* press tab key as suggested. Then after $: press space key.
After log there is a space key, after Subject: there is a space key after $1 there is a space key. After closing bracket there is a space key before $1.

  1. Now you need to regenerate sendmail.cf file. use m4 macro to do so. 

    #m4 sendmail.mc > sendmail.cf

  • Now restart sendmail and you verify your maillog file. You will see Subject line for each mail which is being sent from or relayed from your email server

Basic MySQL administration

CONTENTS:

About this Tutorial
MySQL Administration
Working with Tables
MySQL Commands vs. Postgres Commands

About this Tutorial
I’ll be adding to this tutorial in the coming weeks. If you have ideas of things you’d really like to see here, email me.
MySQL Administration
This section goes over the basics of maintaining a database rather than actual data. It includes creation of databases, creation of users, granting of privileges to users, changing passwords, and other activities from within the mysql CLI front end to MySQL.
Entering and Exiting the mysql Program

Your starting point for MySQL maintenance is the mysql program:

[nilesh@nilesh]$ mysql
ERROR 1045: Access denied for user: 'nilesh@localhost' (Using password: NO)
[nilesh@nilesh]$

OOPs! User nilesh is apparently password protected, so we must run mysql to query for a password, and then type in the password (which of course types invisibly)…

[nilesh@nilesh]$ mysql -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 41 to server version: 4.0.18

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> quit
Bye
[nilesh@nilesh]$

In the preceding, you ran mysql with the -p option so that it would query for the password, you typed in the password, and then you exited the mysql program by typing quit.

By the way, if the account has no password (this is sometimes an installation default), you would just press Enter when prompted for the password.

Perhaps you want to log in as root instead of nilesh. This would probably be the case if you wanted to add a database or any other high responsibility action. Here’s how you log in as root:

[nilesh@nilesh]$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 42 to server version: 4.0.18

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> quit
Bye
[nilesh@nilesh]$

The -u root tells mysql to log you in as root, and as previously discussed, the -p tells mysql to query for a password.

In mysql, when you see a prompt like this:

mysql>

you are in the mysql program. For the rest of this section, most examples will begin and end in mysql.

There are more than one root account, and you must password protect all of them. Read on…

mysql> use mysql
Database changed
mysql> select host, user, password from user;
+-----------------------+--------+------------------------------------------+
| host                  | user   | password                                 |
+-----------------------+--------+------------------------------------------+
| localhost             | root   | 195CABF93F868C84F7FB2CD44617E468487551B6 |
| localhost.localdomain | root   | 195CABF93F868C84F7FB2CD44617E468487551B6 |
| localhost             |        |                                          |
| localhost.localdomain |        |                                          |
| localhost             | nilesh | 195CABF93F868C84F7FB2CD44617E468487551B6 |
+-----------------------+--------+------------------------------------------+
5 rows in set (0.00 sec)

mysql>

As you can see, there’s a root account at localhost and another to localhost.localdomain. Both must be password protected. In reality, all accounts should be password protected.

Exploring Your MySQL Installation
From within mysql you can find quite a bit of information concerning your installation. As what user are you logged into mysql? What databases exist? What tables exist in a database? What is the structure of a table? What users exist?

Because different operations require different privileges, to save time we’ll perform all these actions logged into mysql as root.

Let’s start with finding out your username within mysql:

mysql> select user();
+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)

mysql>

Now let’s list all the users authorized to log into mysql:

mysql> use mysql
Database changed
mysql> select host, user, password from user;
+-----------------------+--------+------------------------------------------+
| host                  | user   | password                                 |
+-----------------------+--------+------------------------------------------+
| localhost             | root   | 195CABF93F868C84F7FB2CD44617E468487551B6 |
| localhost.localdomain | root   | 195CABF93F868C84F7FB2CD44617E468487551B6 |
| localhost             |        |                                          |
| localhost.localdomain |        |                                          |
| localhost             | nilesh | 195CABF93F868C84F7FB2CD44617E468487551B6 |
+-----------------------+--------+------------------------------------------+
5 rows in set (0.00 sec)
mysql>

Notice there are two root logons — one at localhost and one at localhost.localdomain. They can have different passwords, or one of them can even have no password. Therefore, YOU’D BETTER check to make sure they’re both password protected. DO NOT forget the password(s). If you lose all administrative passwords, you lose control of your mysql installation. It’s not like Linux where you can just stick in a Knoppix CD, mount the root directory, and erase the root password in /etc/passwd.
User Maintenance
Before discussing user maintenance, it’s necessary to understand what properties exist for each user. To do that, we’ll use mysql -e option to execute SQL commands and push the output to stdout. Watch this:

[nilesh@nilesh]$ mysql -u root -p -e “use mysql;describe user;” | cut -f 1
Enter password:
Field
Host
User
password
Select_priv
Insert_priv
Update_priv
Delete_priv
Create_priv
Drop_priv
Reload_priv
Shutdown_priv
Process_priv
File_priv
Grant_priv
References_priv
Index_priv
Alter_priv
Show_db_priv
Super_priv
Create_tmp_table_priv
Lock_tables_priv
Execute_priv
Repl_slave_priv
Repl_client_priv
ssl_type
ssl_cipher
x509_issuer
x509_subject
max_questions
max_updates
max_connections
[nilesh@nilesh]$

The word “Field” is a heading, not a piece of information about a user. After that, the first three fields are the user’s host, username and password. The password is encoded. If you hadn’t included the cut command, you’d have seen that the same username can exist in multiple hosts, even if both hosts refer to the same physical machine. That’s why it’s vital to MAKE SURE TO password protect ALL users. The next several fields after password are privileges that can be granted to the user, or not.

As will be discussed later, there’s a way to grant ALL privileges to a user. From a security point of view this is very dangerous, as ordinary looking users can be turned into backdoors. I’d suggest always granting and revoking specific privileges. Here is a list of the privileges that MySQL users can have, and what those privileges allow them to do:

USER FIELD
PRIVILEGE FUNCTION

Select_priv Select Ability to use the select command. In other words, ability to read.

Insert_priv Insert Ability to insert new data — insert a new row.

Update_priv Update Ability to change existing data — change contents of a row.

Delete_priv Delete Ability to delete rows of existing data.

Create_priv Create Ability to create a new table.

Drop_priv Drop Ability to drop a table.

Reload_priv Reload

Shutdown_priv Shutdown

Process_priv Process

File_priv File

Grant_priv Grant Ability to grant and revoke privileges to others.

References_priv References

Index_priv Index Ability to create new indexes or drop indexes.

Alter_priv Alter Ability to change the structure of a table.

Show_db_priv

Super_priv

Create_tmp_table_priv
Ability to create temporary tables.

Lock_tables_priv
Ability to lock tables.

Execute_priv
Repl_slave_priv
Repl_client_priv

The root user, or any user given sufficient privileges, can create new users with the grant command:

mysql> grant select on test2.* to myuid@localhost identified by 'mypassword';
Query OK, 0 rows affected (0.00 sec)

mysql> select host, user, password from user;
+-----------------------+--------+------------------------------------------+
| host                  | user   | password                                 |
+-----------------------+--------+------------------------------------------+
| localhost             | root   | 195CABF93F868C84F7FB2CD44617E468487551B6 |
| localhost.localdomain | root   | 195CABF93F868C84F7FB2CD44617E468487551B6 |
| localhost             |        |                                          |
| localhost.localdomain |        |                                          |
| localhost             | nilesh | 195CABF93F868C84F7FB2CD44617E468487551B6 |
| localhost             | myuid  | 195CABF93F868C84F7FB2CD44617E468487551B6 |
+-----------------------+--------+------------------------------------------+
6 rows in set (0.00 sec)

mysql>

In the preceding, we grant one privilege, select, on every table in the test2 database (test2.*), to user myuid at host localhost (myuid@localhost), giving that user the password “mypassword”. We then query table user in the mysql database (mysql.user) in order to see whether user myuid has been created. Indeed he has.

Granting select privilege is insufficient for any user using any app that modies data. Let’s give myuid more privileges in the test2 database:

mysql> grant Insert, Update, Delete, Create on test2.* to myuid@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql>

Now user myuid can not only select, but can insert rows, update rows, delete rows, and create tables and databases. Conspicuously missing is the ability to drop tables and databases — that can be more dangerous, in the hands of a careless but not malicious user, than some of the other abilities.

Privileges granted by the grant command are not kept in the mysql.user table, but instead in the mysql.db table. You can see results by issuing this command from the operating system:

[nilesh@nilesh] mysql -u root -p -e 'select * from mysql.db where host="localhost" and user="myuid";' > temp.txt
Enter password:
[nilesh@nilesh]

The results look like this:

Host    Db    User    Select_priv    Insert_priv    Update_priv    Delete_priv    Create_priv    Drop_priv    Grant_priv    References_priv    Index_priv    Alter_priv    Create_tmp_table_priv    Lock_tables_priv
localhost    test2    myuid    Y    Y    Y    Y    Y    N    N    N    N    N    N    N

You can revoke privileges like this:

mysql> revoke Delete, Create on test2.* from myuid@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql>

If you redo the select on mysql.db, you’ll see that those two privileges are now marked N.

To actually delete a user, you use a SQL statement to delete him from the mysql.users table after revoking all his privileges.

When deleting the user from mysql.user, if you forget the where clause, or any of its tests, especially the test on column user, you will delete too many users — possibly all users, in which case you’ll have no way to operate the database. BE VERY CAREFUL!

Now that you understand the potential landmines, here’s how you delete a user:

mysql> revoke all on test2.* from myuid@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> delete from mysql.user where user='myuid' and host='localhost';
Query OK, 1 row affected (0.00 sec)

mysql>

Exploring Your Databases
You can refer to a table in two ways: By name after connecting to its database with a use statement, and with the databasename.tablename syntax. The former is much more common in applications, but the latter is often used in database administration, especially when you must access the system database (mysql) in order to perform work on a different database.

The first item for exploration is to find all databases:

mysql> show databases;
+-------------------+
| Database          |
+-------------------+
| depot_development |
| depot_production  |
| depot_test        |
| mysql             |
| test              |
| test2             |
+-------------------+
6 rows in set (0.00 sec)

mysql>

In the preceding, you went into the mysql program, determined what databases existed. Now let’s explore the test database:

mysql> use test;
Database changed
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| dogs           |
| people         |
+----------------+
2 rows in set (0.00 sec)

mysql>

So the database test has two tables, dogs and people. Let’s examine the columns in each of those tables:

mysql> show columns from dogs;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| owner | varchar(20) |      | PRI |         |       |
| name  | varchar(20) |      | PRI |         |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> show columns from people;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| lname | varchar(20) |      | PRI |         |       |
| fname | varchar(20) |      |     |         |       |
| mname | varchar(16) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql>

Another way to get the same information is with the describe command:

mysql> describe dogs;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| owner | varchar(20) |      | PRI |         |       |
| name  | varchar(20) |      | PRI |         |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> describe people;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| lname | varchar(20) |      | PRI |         |       |
| fname | varchar(20) |      |     |         |       |
| mname | varchar(16) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql>

Working with Tables
The following script creates and loads the table. Explanations appear to the right of the code:

####################################################
# CREATE THE DATABASE
####################################################
#drop database if exists test2;
#create database test2;
#use test2;

####################################################
# REINITIALIZE THE TABLES. ASSUME USER IS ALREADY
# CONNECTED TO THE PROPER DATABASE FROM WITHIN
# mysql OR psql.
####################################################
drop table if exists members;
drop table if exists families;

####################################################
# CREATE THE TWO TABLES FORMING A 1 TO MANY RELATIONSHIP.
# FAMILIES IS THE ONE, AND MEMBERS IS THE MANY.
# CREATE UNIQUE INDEX SUCH THAT FAMILY_ID PLUS NAME IN
# MEMBERS IS FORCED TO BE UNIQUE.
####################################################
create table families (
id int not null auto_increment,
name varchar(20) not null,
primary key (id)
);
show tables;

create table members (
id int not null auto_increment,
family_id int not null,
name varchar(16) not null,
primary key (id),
foreign key (family_id) references families
on delete restrict
on update cascade
);

create unique index familymember on members (family_id, name);

describe families;
describe members;

####################################################
# LOAD families WITH THREE ROWS
####################################################
insert into families (name) values (‘Albertson’);
insert into families (name) values (‘Becker’);
insert into families (name) values (‘Cintez’);

####################################################
# LOAD members WITH THREE ROWS FOR THE ‘Albertson’
# FAMILY. USE MONOLITHIC SQL STATEMENTS TO ACCOMPLISH
# THIS.
####################################################
insert into members (family_id, name)
select families.id, ‘Alvin’ from families
where families.name = ‘Albertson’;
insert into members (family_id, name)
select families.id, ‘Andrea’ from families
where families.name = ‘Albertson’;
insert into members (family_id, name)
select families.id, ‘Arthur’ from families
where families.name = ‘Albertson’;

####################################################
# LOAD members WITH THREE ROWS FOR Becker and Cintez
# FAMILY. INSTEAD OF MONOLITHIC SQL STATEMENTS,
# LOOK UP families.id FROM families.name, AND THEN
# USE THAT id TO INSERT THE MEMBERS.
# SETTING @id TO NULL PREVENTS USAGE OF PREVIOUS VALUES WHEN
# THE SELECT”S WHERE CLAUSE FAILS
####################################################

select @id:=null;
select @id:=id from families where name=’Becker’;
insert into members (family_id, name) values(@id, ‘Betty’);
insert into members (family_id, name) values(@id, ‘Ben’);
insert into members (family_id, name) values(@id, ‘Bob’);

select @id:=null;
select @id:=id from families where name=’Cintez’;
insert into members (family_id, name) values(@id, ‘Charles’);
insert into members (family_id, name) values(@id, ‘Christina’);
insert into members (family_id, name) values(@id, ‘Cindy’);

####################################################
# SHOW EACH FAMILY AND ITS MEMBERS
####################################################
select families.id, families.name, members.name
from families, members where
(members.family_id = families.id);

Use this only if creating
a new database, otherwise
leave commented out

Drop the tables if they exist
to make room for new tables
of the same name

The families table is the 1 of
1 to many.

The members table is the many
of the 1 to many.
members.family_id matches
families.id.

Foreign key means you can’t
delete a family that
still has members

This index prevent two family
members from having the same
first name

Show the structures of the two
tables just created

Load the families table.

Monolithic insert from select

Monolithic insert from select

Monolithic insert from select

The following inserts are
performed more procedurally,
by first finding families.id
based on families.name, and
then using that id as
members.family_id.

Prevent ghosts of selects past
Find id from families.name
Do the insert

Prevent ghosts of selects past
Find id from families.name
Do the insert

Join the tables in the
where clause, and find
all family members

The preceding code exercised the creation of databases and tables, insertion of rows, and viewing a one to many relationship with a join created in a where clause. The preceding is pretty much DBMS independent, and runs on both MySQL and Postgres. However, certain legitimate SQL queries don’t work on some versions of MySQL:

MySQL Commands vs. Postgres Commands

 

TASK
MySQL
Postgres
DISCUSSION
Comments in SQL code # as first printable on line Anything between /* and */ According to my experimentation, MySQL comments produce an error in Postgres, and vice versa, which is too bad.
Connect to database use dbname; \c dbname
Find all databases show databases; \l Postgres command is a lower case L, not numeral 1. It errors out if  you end it with a semicolon. It can be used in a script file.
Find all tables in current database show tables; \dt \dt shows only user level tables. Use \dS to see system level tables.
Show structure of one table describe tblname; \d tblname Postgres version doesn’t show length of varchar.
Change database use dbname; \c dbname
Add user grant select on dbname.* to username@userhost identified by ‘userpassword’; create user username with encrypted password=’userpassword’; WARNING: I currently am having problems getting created Postgres users to be able to authenticate.
Grant privileges grant privlist on dbname.* to username@userhost identified by ‘userpassword’; grant privlist on tbllist to slitt; In Postgres, tbllist must be an explicit, comma delimited list of tables. No wildcards.
Change user password grant select  on dbname.* to username@userhost identified by “userpassword”; alter user username encrypted password ‘userpassword’; WARNING: I currently am having problems getting created Postgres users to be able to authenticate.

How-to | Welcome to Linux how-to

CONTENTS:

About this Tutorial
MySQL Administration
Working with Tables
MySQL Commands vs. Postgres Commands

About this Tutorial
I’ll be adding to this tutorial in the coming weeks. If you have ideas of things you’d really like to see here, email me.
MySQL Administration Continue reading

What is PHP? server-side-scripting

What is PHP? <?php … ?>

PHP (Hypertext Preprocessor) is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. PHP is a scripting language designed to fill the gap between SSI (Server Side Includes) and Perl, intended largely for the web environment. PHP has gained quite a following in recent times, and it is one of the forerunners in the Open Source software movement. Its popularity derives from its C-like syntax, and its simplicity. PHP is currently divided into two major versions: PHP 4 and PHP 5, although PHP 4 is deprecated and is no longer developed or supplied with critical bug fixes. PHP 6 is currently under development.

PHP started out as a small open source project that evolved as more and more people found out how useful it was. Rasmus Lerdorf unleashed the first version of PHP way back in 1994.

  • PHP is a server side scripting language that is embedded in HTML. It is used to manage dynamic content, databases, session tracking, even build entire e-commerce sites.
  • It is integrated with a number of popular databases, including MySQL, PostgreSQL, Oracle, Sybase, Informix, and Microsoft SQL Server.
  • PHP is pleasingly zippy in its execution, especially when compiled as an Apache module on the Unix side. The MySQL server, once started, executes even very complex queries with huge result sets in record-setting time.
  • PHP supports a large number of major protocols such as POP3, IMAP, and LDAP.

Common uses of PHP:

  • Access control on websites / web applications using php. you can restrict users to access some pages of your website.
  • PHP performs system functions, i.e. from files on a system it can create, open, read, write, and close them.
  • PHP can handle forms, i.e. gather data from files, save data to a file, through email you can send data, return data to the user.
  • You add, delete, modify elements within your database through PHP.
  • Access cookies variables and set cookies.
  • It can encrypt data.

“Hello Web World” Script in PHP:

To get a taste of PHP, first start with simple PHP scripts. Since “Hello, Web World!” is an essential example, first we will create a friendly little “Hello, World!” script.

As mentioned earlier, PHP is embedded in HTML. That means that in amongst your normal HTML (or XHTML if you’re cutting-edge) you’ll have PHP statements like this:

<html>
<head>
<title>Hello Web World</title>
<body>
    <?php echo "Hello, Web World!";?>
</body>
</html>

It will produce following result:

Hello, Web World!

If you examine the HTML output of the above example, you’ll notice that the PHP code is not present in the file sent from the server to your Web browser. All of the PHP present in the Web page is processed and stripped from the page; the only thing returned to the client from the Web server is pure HTML output.

All PHP code must be included inside one of the three special markup tags ate are recognised by the PHP Parser.

<?php PHP code goes here ?>

<?    PHP code goes here ?>

<script language="php"> PHP code goes here </script>

Most common tag is the <?php…?> and we will also use same tag in our tutorial.

From the next chapter we will start with PHP Environment Setup on your machine and then we will dig out almost all concepts related to PHP to make you comfortable with the PHP language.
Is PHP a buzz word ?
Why php is so popular ?
PHP uh.. never heard of it ? what is php?
php a hypertext preprocessor?
A powerful server-side-scripting language, PHP.