Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
AJAX and PHP: Building Responsive Web Applications

You're reading from   AJAX and PHP: Building Responsive Web Applications Enhance the user experience of your PHP website using AJAX with this practical tutorial featuring detailed case studies

Arrow left icon
Product type Paperback
Published in Mar 2006
Publisher Packt
ISBN-13 9781904811824
Length 284 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Toc

Table of Contents (17) Chapters Close

AJAX and PHP
Credits
About the Authors
About the Reviewers
Preface
1. AJAX and the Future of Web Applications FREE CHAPTER 2. Client-Side Techniques with Smarter JavaScript 3. Server-Side Techniqueswith PHP and MySQL 4. AJAX Form Validation 5. AJAX Chat 6. AJAX Suggest and Autocomplete 7. AJAX Real-Time Charting with SVG 8. AJAX Grid 9. AJAX RSS Reader 10. AJAX Drag and Drop Preparing Your Working Environment Index

Preparing Your *nix Playground


Almost all the UNIX and Linux distributions include Apache, PHP, and MySQL; however, you should check the versions of these programs. It would be good to have MySQL 4.1 or newer, and it’s very important to have at least PHP 5. The code in this book will not work with older versions of PHP.

Installing Apache

To install Apache on your Unix-based server, follow these simple steps:

  1. First, download the latest Apache Unix Source code for your system from http://httpd.apache.org/download.cgi and decompress it with a command such as:

    tar -zxvf httpd-2.0.55.tar.gz
  2. To compile and install the Apache Web Server on your system, go to the folder containing the sources and execute the following commands, while logged in as root:

    ./configure --prefix=/usr/local/apache2 --enable-so --enable-ssl --with-ssl --enable-auth-digest
    
    make
    
    make install

Installing MySQL

The official website of MySQL is http://www.mysql.com. At the time of this writing the latest stable version is MySQL 5.0, and you can download it from http://dev.mysql.com/downloads/mysql/5.0.html. However, it’s good to know that we made our SQL queries compliant with the SQL 92 standard, so you should be able to reuse them with other database systems with minimum of translation effort. Chapter 2 of the MySQL 5 manual covers installation procedures for all supported platforms, and you can read it here: http://dev.mysql.com/doc/refman/5.0/en/installing.html.

If your Linux distribution supports RPMs, you’ll need to download the RPMs for Server, Client programs, and Libraries and header files. Install MySQL as explained in the manual at http://dev.mysql.com/doc/refman/5.0/en/linux-rpm.html. If your platform doesn’t support RPMs, install MySQL as explained at http://dev.mysql.com/doc/refman/5.0/en/installing-binary.html.

After installing MySQL, you should change the MySQL administrator’s password (the root@localhost user), which is blank by default. Read more about MySQL passwords at http://dev.mysql.com/doc/mysql/en/Passwords.html. One way to change root’s password is to execute:

mysqladmin -u root password ‘your_new_password.’

Alternatively, you can access MySQL through a console program or by using a database administration tool such as phpMyAdmin, and execute this command:

SET PASSWORD FOR root@localhost=PASSWORD(‘your_new_password’);

You can now test your MySQL server by executing the following command in your console:

#mysql -u root -p

Installing PHP

Every time you want to get a new PHP library working on Linux, you need to recompile the PHP module. That’s why it’s recommended to make a good compilation, with all the needed libraries, from the start.

  1. Go to http://www.php.net/downloads.php and get the complete source code archive of PHP 5.x and extract the contents into a directory. At the time of writing, the latest PHP version was 5.1.2.

  2. Go to the folder where you extracted the PHP source and execute the following commands:

    ./configure --with-config-file-path=/etc --with-mysql=/usr/include/mysql 
    --with-apxs2=/usr/local/apache2/bin/apxs --with-zlib --with-gd --with-xsl
    
    make
    
    make install

    Note

    If you are compiling PHP for XAMPP, you need to use the following configure command instead:

    ./configure --with-config-file-path=/opt/lampp/etc --with-mysql=/opt/lampp --with-apxs2=/opt/lampp/bin/apxs --with-zlib --with-gd
    

    After executing make and make install, you need to copy the newly created php_src/libs/libphp5.so file to /opt/lampp/modules/libphp5.so.

  3. Copy php.ini-recommended to /etc/php.ini by executing the following command:

    cp php.ini-recommended /etc/php.ini.
  4. Open the Apache configuration file (httpd.conf), find the DirectoryIndex entry, and make sure you have index.php at the end of the line:

    DirectoryIndex index.html index.html.var index.php
  5. Restart your Apache Web Server using the following command:

    /usr/local/apache2/bin/apachectl restart
  6. Create a folder called ajax under the htdocs folder (by default /usr/local/apache2/htdocs/).

  7. To make sure your PHP installation works, create a file named test.php in the ajax folder you’ve just created, with the following contents in it:

    <?php
    phpinfo();
    ?>
  8. Finally, point your web browser to http://localhost/test.php, to ensure PHP was correctly installed under Apache (you should get a page similar to Figure A.3).

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image