NetAdminTools.com
 
SignalQ Sites:
NetAdminTools - Coprolite - NoNIC - SpotBridge - NAW
RoboCoop - AreWeDown - SolarPower - SysAdminTools
Xfig - Gold Loaf - GeekPapa - FixGMC - MCJ - FixRambler
Categories:
GNU/Linux | Homebrew designs | Perl | Administration | Backup/Recovery | Bugs/Fixes | Certification | Database | Email | File/Print | Hardware | Information Grab Bag | Interoperability | GNU/Linux ABCs | Monitoring | Name Resolution | Network Services | Networking | Remote Control | Security | Desktop | Web | BSD | Solaris | GIAGD | REALbasic

Last 30 Days | Last 60 Days | Last 90 Days | All Articles | RSS | Hail Support


Categories:
·GNU/Linux
·Homebrew designs
·Perl
·Administration
·Backup/Recovery
·Bugs/Fixes
·Certification
·Database
·Email
·File/Print
·Hardware
·Information Grab Bag
·Interoperability
·GNU/Linux ABCs
·Monitoring
·Name Resolution
·Network Services
·Networking
·Remote Control
·Security
·Desktop
·Web
·BSD
·Solaris
·GIAGD
·REALbasic
·All Categories


Programming With PHP - Part 1
Topic: Web   Posted:2003-02-03
Printer Friendly: Print

spacerspacer
In this series of articles, we will explore the fundamentals of PHP programming with MySQL. For a good reference, try this book. It helped us. In this installment of Programming With PHP, we will set up the Red Hat RPMs, configure our directories, and code a simple "Hello World" app.

We are running Red Hat 8.0 on srv-33, our test box:

[root@srv-33 website]# rpm -qa | grep php
php-4.2.2-8.0.5
php-mysql-4.2.2-8.0.5
[root@srv-33 website]# rpm -qa | grep httpd 
httpd-2.0.40-8
[root@srv-33 website]#

If you don't have these RPMs, get them. Compiling these from source is beyond the scope of this article.

Let's make a directory to hold our web files. Because PHP is a programming language that interacts with users, it is important to be paranoid about security. Run your Apache server as the user apache, and make sure that apache only has read and execute access where needed. We set up a mount point off of root, but you could use opt, usr/local, whatever you like:

# mkdir -p /webstuff/website/
# ls -dl webstuff
drwxr-xr-x    3 root     root
# chmod 750 webstuff -R
# ls -dl webstuff
drwxr-x---    3 root     root
# chgrp apache webstuff -R
# ls -dl webstuff
drwxr-x---    3 root     apache
# cd webstuff
# ls -l
drwxr-x---    2 root     apache

We'll use website.com for our example. (Yes, it is taken, but it is a good name for training). Now we are going to add a virtual host to our /etc/httpd/conf/httpd.conf file:

<VirtualHost *>
DocumentRoot /webstuff/website/
ServerName www.website.com
ServerAlias website.com
ServerAdmin webmaster@website.com
</VirtualHost>

Restart Apache:

# /etc/rc.d/init.d/httpd restart

Since we are using a phony website name, we need to add an entry in /etc/hosts (or winnt/system32/drivers/etc/hosts :)) on our client with the browser:

10.50.100.51    www.website.com

We are all set up. Now, let's create a small PHP program in /webstuff/website/:

[root@srv-33 website]# cat index.php
<?php
echo "Hello World!";
?>

Browse to http://www.website.com to run the program. Here is a screenshot of our simple PHP program running.




Please read our Terms of Use
Microsoft, Windows, Windows XP, Windows 2003, Windows 2000, and NT are either trademarks or registered trademarks of Microsoft Corporation. NetAdminTools.com is not affiliated with Microsoft Corporation. Linux is a registered trademark of Linus Torvalds, and refers to the Linux kernel. The operating system of most distributions that contain the Linux kernel is GNU/Linux. All logos and trademarks in this site are property of their respective owner. Copyright 1997-2008 NetAdminTools.com

Created by:
MCJ
MCJ CMS