|
|
  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.
|
|