About this tutorial

Section 1. About this tutorial

Should I take this tutorial?
This tutorial shows you how to use two open source, cross-platform tools for creating a
dynamic Web site: PHP and MySQL. When we are finished, you will know how dynamic sites
work and how they serve the content, and you will be ready to serve your own dynamic
content from your site.

Section 2. Introduction and installation

The need for dynamic content
The Web is no longer static; it’s dynamic. As the information content of the Web grows,
so does the need to make Web sites more dynamic. Think of an e-shop that has 1,000
products. The owner has to create 1,000 Web pages (one for each product), and
whenever anything changes, the owner has to change all those pages. Ouch!!!
Wouldn’t it be easier to have only one page that created and served the content on the
fly from the information about the products stored in a database, depending on the
client request?
Nowadays sites have to change constantly and provide up-to-date news, information,
stock prices, and customized pages. PHP and SQL are two ways to make your site
dynamic.
PHP PHP is a robust, server-side, open source scripting language that is extremely
flexible and actually fun to learn. PHP is also cross platform, which means your PHP
scripts will run on Unix, Linux, or an NT server.
MySQL SQL is the standard query language for interacting with databases. MySQL is
an open source, SQL database server that is more or less free and extremely fast.
MySQL is also cross platform.

Installing MySQL

Next comes MySQL. We will follow the same procedure (replacing those xs again with
our version number). Download the source from the MySQL site and save it in /tmp/src.
The latest version I found was mysql-3.22.32.tar.gz.
# cd /tmp/src/
# gunzip -dc mysql-x.xx.xx.tar.gz | tar xv
# cd mysql-x.xx.xx
# ./configure –prefix=/usr/local/mysql
# make
# make install
MySQL is installed. Now you need to create the grant tables:
# scripts/mysql_install_db
Then start the MySQL server:
# /usr/local/bin/safe_mysqld &
And test your installation by typing:
mysql -uroot -p
At the password prompt, just press Enter. You should see something like:
Welcome to MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5 to server version 3.22.34
Type ‘help’ for help.
mysql>
If you see this, you have MySQL running properly. If you don’t, try installing MySQL
again. Type status to see the MySQL server status. Type quit to exit the prompt.

Installing PHP

We will follow a similar procedure to install PHP. Download and save the source from the
PHP site to /tmp/src:
# cd /tmp/src/
# gunzip -dc php-x.x.xx.tar.gz | tar xv
# cd php-x.x.xx
# ./configure –with-mysql=/usr/local/mysql –with-apxs=/usr/local/apache/bin/apxs
# make
# make install
Copy the ini file to the proper directory:
# cp php.ini-dist /usr/local/lib/php.ini
Open httpd.conf in your text editor (probably located in /usr/local/apache/conf directory), and
find a section that looks like the following:
# And for PHP 4.x, use:
#
#AddType application/x-httpd-php .php

#AddType application/x-httpd-php-source .phps
Just remove those #s before the AddType line so that it looks like:
# And for PHP 4.x, use:
#
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
Save your file and restart apache:
# /usr/local/apache/bin/apachectl stop
# /usr/local/apache/bin/apachectl start
Then test whether you have PHP installed properly. Type the following code in a text editor
and save it as test.php in a directory accessible by your Web server:

<HTML>
<?php
phpinfo();
?>
</HTML>

Set the permission of the file to executable by typing at console chmod 775 test.php,
and then view it with your browser. You should see a detailed description of the environment
variables in PHP similar to the image below. If you don’t, then PHP was not installed
properly. Try reinstalling it. Make sure there is a section “MySQL” in the php info; if not,
MySQL connectivity will not work.

 

Leave a Reply

Your email address will not be published. Required fields are marked *


*