Chapter 1: Managing Your Servers In This Chapter ✓ Reviewing tools for client-side development ✓ Installing a local server with XAMPP TE ✓ Setting essential security settings RI ✓ Gathering server-side development tools AL ✓ Understanding the client-server relationship ✓ Choosing a remote server MA ✓ Managing the remote servers ✓ Choosing and registering a domain name D W GH TE eb pages are a complex undertaking.
870 Understanding Clients and Servers ✦ Clients are limited. Web browsers and other client-side software are often limited so that programs accessed over the Internet can’t make major changes to the local file system. For this reason, most client programs operate in a sort of “sandbox” to prevent malicious coding. ✦ Clients can be turned off without penalty. It doesn’t really cause anybody else a problem if you turn off your computer.
Understanding Clients and Servers 871 Notepad++ for Windows and prefer VI or Emacs for other operating systems. ✦ Integrated Development Environment: Komodo Edit and Aptana Studio are specialized text editors with added features for Web programming. They understand all the main Web languages and have syntax help, code coloring, and preview features. Using one of these tools can be extremely helpful (both are free.) For client-side development, you don’t necessarily need access to a server.
872 Creating Your Own Server with XAMPP ✦ An FTP server: Sometimes, you want the ability to send files to your server remotely. The FTP server allows this capability. Again, you probably don’t need this item for your own machine, but you definitely should know about it when you use a remote host. ✦ phpMyAdmin: There’s a command-line interface to MySQL, but it’s limited and awkward. The easiest way to access your MySQL databases is to use the phpMyAdmin program.
Creating Your Own Server with XAMPP 873 XAMPP installation is pretty painless: Simply download the installer and respond to all the default values. If you use Vista or Windows 7, you may want to change where the package is installed because the program files directory causes problems for some users. Running XAMPP After you install XAMPP, you can manage your new tools with the XAMPP Control Panel. Figure 1-1 shows this program in action.
874 Creating Your Own Server with XAMPP Testing your XAMPP configuration Ensure that Apache and MySQL are running, and then open your Web browser. Set the address to http://localhost, and you see a screen like the one shown in Figure 1-2. Figure 1-2: The XAMPP main page. This page indicates that XAMPP is installed and working. Feel free to experiment with the various items in the Demos section. Even though you may not know yet what they do, you should know what some of their capabilities are.
Creating Your Own Server with XAMPP 875 htdocs directory. You didn’t specify a particular file to load. If Apache isn’t given a filename and it sees the file named index.html or index.php, it displays that file, instead. So, in the default htdocs directory, the index. php program is immediately being called. Although this program displays the XAMPP welcome page, you don’t usually want that to happen. Rename index.php to index.php.old or something similar.
76 Creating Your Own Server with XAMPP Setting the security level When you have a Web server and a data server running, you create some major security holes. You should take a few precautions to ensure that you’re reasonably safe: ✦ Treat your server only as a local asset. Don’t run a home installation of Apache as a production server. Use it only for testing purposes. Use a remote host for the actual deployment of your files. It’s prepared for all the security headaches. ✦ Run a firewall.
Creating Your Own Server with XAMPP 877 ✦ Change the MySQL root password. If you haven’t already done so, use the security link to change the MySQL root password, as shown in Figure 1-5. (I show an alternative way to change the password in Book VI, Chapter 1.) Figure 1-5: Changing the MySQL root password. ✦ Add an XAMPP Directory password. Type a password into the lower half of the security form to protect your xampp directory from unauthorized access.
878 Choosing a Web Host ✦ The firewall is the first line of defense. If your firewall blocks external access to your servers, the only real danger your system faces is from yourself. Begin with a solid firewall and ensure that you don’t allow access to port 80 (Apache) or port 3306 (MySQL) unless you’re absolutely sure that you have the appropriate security measures in place. ✦ I left phpMyAdmin open.
Choosing a Web Host 879 You can find a number of free hosting services at sites like http://freewebhosts.com. Finding a hosting service When looking for a hosting service, ask yourself these questions: ✦ Does the service have limitations on the types of pages you can host? Some servers are strictly for personal use, and some allow commercial sites. Some have bandwidth restrictions and close your site if you draw too many requests.
880 Choosing a Web Host ✦ How easily can you upgrade if you want? Does a particular hosting plan meet your needs without being too expensive? ✦ Does the service offer you a subdomain, and can you register your own? You may also want to redirect a domain that you didn’t get through the service. (See the section “Naming Your Site,” later in this chapter, for information on domain names.
Managing a Remote Site 881 ✦ You get a nice batch of extras. The free service comes with FTP and e-mail support and also a MySQL database. ✦ Customer support is excellent. Most free hosting services offer no customer support. Freehostia provides good support, even to the free services. (I asked a couple of questions before anyone there knew that I was writing this book, and I was impressed with the speed and reliability of the responses.) Choose whichever hosting service works for you.
882 Managing a Remote Site There’s usually some sort of file management tool that might look like the one shown in Figure 1-7. Figure 1-7: This file management tool allows you to manipulate the files on your system. In this particular case, all my Web files are in the www/aharrisbooks.net directory, so I click to see them. Figure 1-8 shows what you might see in an actual directory. This page allows you to rename, upload, and edit existing files and change file permissions.
Managing a Remote Site 883 Figure 1-8: Now, you can see some files here. Book VIII Chapter 1 Managing Your Servers Figure 1-9: The hosting service has a limited text editor.
884 Managing a Remote Site What’s with all the permissions? Permissions are typically treated as binary numbers: 111 means “read, write, execute.” This (111 value) is also a 7 permission because 111 binary translates to 7 in base ten (or base eight, but let’s skip that detail for now). A permission is read as three digits, each one a number indicating the permissions, so 644 permission means rw- r-- r--. This example can be translated as “The owner should be able to read and write this file.
Managing a Remote Site 885 Fortunately, most hosts have the FTP (File Transfer Protocol) system available. FTP is a client/server mechanism for transferring files efficiently. To use it, you may have to configure some sort of FTP server on the host to find out which settings, username, and password you should use. Figure 1-10 shows the Freehostia Control Panel with this information displayed. Figure 1-10: Configuring the FTP server. You also need an FTP client.
886 Managing a Remote Site Figure 1-11: FireFTP is a complete FTP program that runs inside Firefox. If you want to connect to your server with FTP, follow these steps: 1. Look up the configuration settings. You may have to dig around in the server documentation, but you should find the server name, username, and password to access your server. Sometimes, you have to configure these elements yourself. 2. Create a profile for your server.
Naming Your Site 887 Figure 1-12: The profile editor for FireFTP. 5. Drag the file to transfer it. FireFTP automatically determines the type of transfer you need to make. 6. Wait for the transfer to complete. It usually takes some time to transfer a large number of files. Be sure the transfer is complete before you close the FTP window. 7. Manipulate remote files. You can right-click on the remote file system to display a context menu.
888 Naming Your Site ✦ Every computer on the Internet has an IP (Internet Protocol) address. When you connect to the Internet, a special number is assigned to your computer. This IP address uniquely identifies your computer. Client machines don’t need to keep the same address. For example, my notebook has one address at home and another at work. The addresses are dynamically allocated. A server needs a permanent address that doesn’t change. ✦ IP addresses are used to find computers.
Naming Your Site 889 Figure 1-13: This Control Panel shows all the options, including domain and subdomain tools. Book VIII Chapter 1 Managing Your Servers Figure 1-14: Use this page to create a subdomain for your account.
890 Naming Your Site 4. Look for a domain search tool. Often, you have a tool, like the one shown in Figure 1-15, that allows you to search for a domain. 5. Search for the domain name you want. You can type a domain name to see whether it’s available. Figure 1-15: I’m searching for aharris books.net — it seems like a good domain name! 6. If the domain name is available to register and you want to own it, purchase it immediately.
Managing Data Remotely 891 7. Register the domain. The domain-purchase process involves registering yourself as the domain owner. Figure 1-16 shows a typical form for this transaction. WHOIS information provides your information to people inquiring about the domain name. Figure 1-16: Registering the domain name. 8. Wait a day or two. Your new domain name won’t be available immediately. It takes a couple of days for the name to be registered everywhere. Book VIII Chapter 1 9.
892 Managing Data Remotely how this process works because it’s often slightly different from working with the database on your local machine. Creating your database Often, a tool like the one shown in Figure 1-17 allows you to pick a defined database or create a new one. Figure 1-17: You often have to create a database outside of phpMy Admin. This database creation step happens because you don’t have root access to MySQL. (If everybody had root access, chaos would ensue.
Managing Data Remotely 893 Figure 1-18: phpMy Admin is just like the one on your home machine! If you look carefully, you see that Freehostia is still using MySQL 4. Therefore, not all SQL scripts in this book work correctly. The only significant problem is views because this feature wasn’t included in MySQL 4. I include a version of the buildHero4.sql script on the CD-ROM that eliminates all references to views. Otherwise, the script is the same.
894 Managing Data Remotely By far the biggest problem when moving your programs to a remote server is figuring out the new connection. Make sure that you know the right combination of server name, username, and password. Test on a simple PHP application before working on a complex one.