Friday 19 July 2013

Exploring PHP Basics

WordPress requires PHP in order to work; therefore, your Web hosting

provider must have PHP enabled on your Web server. If you already have
WordPress up and running on your Web site, you know PHP is running and
working just fine. Currently, the PHP version required for WordPress is ver-
sion 4.3 or later.

In the very near future, WordPress will drop support for PHP version 4.
When this happens, version 5 will be the only version supported by the
WordPress platform. Ask your Web host to upgrade you to PHP version 5
sooner rather than later because most WordPress developers (for plugins,
themes, and so on) base their development practices on PHP version 5.

Exploring PHP Basics

Here content refers to the data stored in the MySQL database; that is, your
blog posts, pages, comments, links, and options that you set up in the
WordPress Dashboard. However, the theme (or design) you choose to use
for your blog — whether it’s the default theme, one you create, or one you
have custom designed — isn’t part of the content in this case. Theme files
are part of the file system and aren’t stored in the database. Therefore, it’s
a good idea to create and keep a backup of any theme files that you’re cur-
rently using. See Book VI for further information on WordPress theme
management.

When you look for a hosting service, keep an eye out for the hosts that pro-
vide daily backups of your site so that your content (data) won’t be lost in
case something happens. Web hosting providers who offer daily backups as
part of their services can save the day by restoring your site to its original
form. Additionally, Book II, Chapter 5 covers important information about
backing up your Web site.

 

Exploring PHP Basics

PHP is a server-side scripting language for creating dynamic Web pages.

When a visitor opens a page built in PHP, the server processes the PHP com-
mands and then sends the results to the visitor’s browser. MySQL is an open
source relational database management system (RDBMS) that uses
Structured Query Language (SQL), the most popular language for adding,
accessing, and processing data in a database. If that all sounds like Greek to
you, just think of MySQL as a big file cabinet where all the content on your
blog is stored.

Every time a visitor goes to your blog to read your content, he makes

a request that’s sent to a host server. The PHP programming language

receives that request, makes a call to the MySQL database, obtains the

requested information from the database, and then presents the requested information to your visitor through his Web browser.

Understanding How PHP and MySQL Work Together

 

WordPress uses a PHP/MySQL platform, which provides everything you need to create your own blog and publish your own content dynamically, without knowing how to program those pages. In short, all your content is stored in a MySQL database in your hosting account.

Introducing PHP and MySQL



 

In Book VI, you dig into the code necessary to create functions and
features on your Web site. Many, if not all, of these functions and fea-


 

tures use Hypertext Preprocessor (PHP) tags. When combined with the

WordPress code, these tags make things happen (such as displaying post content, categories, archives, links, and more) on your Web site.

One of the reasons WordPress is the most popular content management
system (CMS) is that you don’t need to know PHP code to use it. That’s to
say, you can use WordPress easily without ever looking at any of the code
or template files contained within it. However, if you want to tweak the set-
tings of your WordPress theme (flip to Book VI) or the code of a particular
plugin (see Book VII), you need to understand some basics of how PHP

works. But don’t worry; you don’t need to be a PHP programmer.

 

This chapter introduces you to the very basics of PHP and MySQL, which is
the database system that stores your WordPress data. After you read this
chapter, you’ll understand how PHP and MySQL work together with the
WordPress platform to serve up your Web site in visitors’ browsers.

 

This book doesn’t turn you into a PHP programmer or MySQL database

administrator, but it gives you a glimpse of how PHP and MySQL work

together to help WordPress build your Web site. If you’re interested in finding out how to program PHP or become a MySQL database administrator, check out PHP and MySQL For Dummies by Janet Valade (Wiley).

Finding and Using Free and Easy FTP Programs

Here are some quick and easy steps for using your FTP program to CHMOD a file, or edit its permissions on your Web server:

1. Connect the FTP client to your Web server.

2. Locate the file you want to CHMOD.

3. Open the file attributes for the file.

Right-click the file on your Web server and choose File Permissions. (Your FTP client, if not FileZilla, may use different terminology.)

4. The Change File Attributes window appears, as shown in Figure 2-6.

5. Type the correct file permissions number in the Numeric Value field.

This is the number assigned to the permissions you want to give the file.
Most often, the plugin or theme developer provides you which permis-
sions number to assign to the file or folder; typically, it will be either 644
or 755. (The permissions in Figure 2-6 are assigned the value of 755.)

6. Click OK to save the file.

Finding and Using Free and Easy FTP Programs



Typically, folders and files within your Web server are assigned permissions




of either 644 or 755. Usually, you’ll see PHP files, or files that end with the
.php extension, with permissions set to 644 if the Web server is configured
to use PHP Safe Mode.

This is a very basic look at file permissions because, usually, you will not
need to mess with file permissions on your Web server. In case you do
need to dig further, you can find a great reference on file permissions from
Elated.com at http://www.elated.com/articles/understanding-
permissions.


You may run across a situation where you’re asked to edit and change the

file permissions on a particular file on your Web server. With WordPress

sites, this usually happens when dealing with plugins or theme files that
require files or folders to be writable by the Web server. This practice is
referred to as CHMOD, an acronym for Change Mode. When someone says,
“You need to CHMOD that file to 755,” you’ll know what they are talking
about.

Changing File Permissions

Each set of permissions has a numeric code assigned to it, identifying what
type of permissions are assigned to that file or folder. There are a lot of
them, so here are the most common ones that you run into when running a
WordPress Web site:

✦ 644: Files with permissions set to 644 are readable by everyone and
writable only by the file/folder owner.

✦ 755: Files with permissions set to 755 are readable and executable by
everyone, but only writable by the file/folder owner.

✦ 777: Files with permissions set to 777 are readable, writable, and execut-
able by everyone. For security reasons, you should not use this set of
permissions on your Web server unless absolutely necessary.

Changing file permissions

 

Every file and folder on your Web server has a set of assigned attributions, called permissions, that tells the Web server three things about the folder or file. On a very simplistic level, these permissions include:

✦ Read: This setting determines whether the file/folder is readable by the
Web server.

✦ Write: This setting determines whether the file/folder is writable by the
Web server.

✦ Execute: This setting determines whether the file/folder is executable by
the Web server.

Save the changes you made to the file

Click the Save icon or choose File➪Save.

Upload the file to your Web server.

After you save the file, FileZilla alerts you that the file has changed and asks whether you want to upload the file to the server. Click the Yes button; the newly edited file will replace the old one.

That’s all there is to it. Use the FTP edit feature to edit, save, and upload files as you need to.


When you edit files by using the FTP edit feature, you are editing files in a

“live” environment; meaning that when you save the changes and upload the
file, the changes take effect immediately and affect your live Web site. For
this reason, we strongly recommend downloading a copy of the original file
to your local computer before making changes. That way, if you happen to
make a typo on the saved file and your Web site goes haywire, you have a
copy of the original to upload to restore it to its original state

Editing files by using FTP

You will run into situations where you need to edit certain files that live on

your Web server. You can use the methods described in the preceding sec-
tion to download a file, open it, edit it, save it, and then upload it back to
your Web server. That is one way to do it. Another way is to use the built-in
edit feature that exists in most FTP client software, by following these steps:

 

1. Connect the FTP client to your Web server.

2. Locate the file you want to edit.

3. Open the file by using the internal FTP editor.

Right-click the file with your mouse and choose View/Edit. (Remember I’m using FileZilla; your FTP client may name it differently, such as Open or Edit.) Usually, the FTP client will use a program that already exists on your computer — such as Notepad for a PC or TextMate for Mac — to edit the files. In some rare cases, your FTP client software may have its own internal text editor. FileZilla uses a program designated for text editing that already exists on your computer

Tuesday 16 July 2013

10. Click the Connect button.



This connects your computer to your Web server. The directory of folders and files from your local computer display on the left side of the

FileZilla FTP client window, and the directory of folders and files on your Web server display on the right side, as shown in Figure 2-5.

Now you can take advantage of all the tools and features FTP has to offer you!

Finding and Using Free and Easy FTP Programs. Transferring files from point A to point B


Now that your local computer is connected to your Web server, transferring
files between the two couldn’t be easier. Within the FTP client software, you
can browse the directories and folders on your local computer on the left
side and browse the directories and folders on your Web server on the right
side.

FTP clients make it easy to transfer files from your computer to your hosting
account by using a drag-and-drop method. Two methods of transferring
files are

✦ Uploading: Generally, transferring files from your local computer to

your Web server. To upload a file from your computer to your Web

server, click the file you want to transfer from your local computer and drag and drop it onto the right side (the Web server side).

✦ Downloading: Transferring files from your Web server to your local

computer. To download a file from your Web server to your local computer, click the file you want to transfer from your Web server and drag and drop it onto to the left side (the local computer side).

Downloading files from your Web server is a very efficient, easy, and smart way of backing up files to your local computer. It’s always a good idea to keep your files safe, especially things like theme files and plugins

4. Enter the FTP server in the Host field.

Host is the same as the FTP server information provided to you when you set up the FTP account on your Web server. In the example, the FTP server is ftp.yourdomain.com, so that’s entered in the Host field, as shown in Figure 2-4.

5. Enter the FTP port in the Port field.

In the previous example, the FTP port is 21. Typically, in most host-
ing environments, FTP uses port 21 and this never changes. However,

double-check your port number and enter it in the Port field, as shown in Figure 2-4.

6. Select the server type.

FileZilla asks you to select a server type (as do most FTP clients). Select FTP - File Transfer Protocol from the Server Type drop-down menu, as shown in Figure 2-4.

7. Select the logon type.

FileZilla gives you several different logon types to choose from (as do
most FTP clients). Select Normal from the Logon Type drop-down menu.

8. Enter your username in the Username field.

This is the username given to you in the FTP settings. In the example, the username is lisa@yourdomain.com

9. Type your password in the Password field.

This is the password given to you in the FTP settings. In the example, the password is {W?$s((7Tqi.

Finding and Using Free and Easy FTP Programs

FTP Username: username@yourdomain.com Password: yourpassword

FTP Server: ftp.yourdomain.com FTP Server Port: 21

Quota: Unlimited MB

Figure 2-2:

Mozilla

FileZilla
FTP client
software.

This is where you need that information. To connect to your Web server via the FileZilla FTP client, follow these few steps:

1. Open the FTP client software on your local computer.

Locate the program on your computer and click (or double-click) the program icon to launch the program.

2. Choose File➪Site Manager to open the Site Manager utility.
The Site Manger utility appears, as shown in Figure 2-3.

3. Click the New Site button.

You can give the new site a name, so type a name that helps you identify the site. This site name can be anything you want it to be because it isn’t part of the connection data you add in the next steps. (In Figure 2-4, you see My Site — original, we know.)

Connecting to the Web Server via FTP

 

For the purposes of this chapter, we use the FileZilla FTP client (http://
sourceforge.net/projects/filezilla) because it’s very easy to use,
and the cost is free ninety-nine (that’s open source geek-speak for free!).

Figure 2-2 shows a FileZilla client that’s not connected to a server. By default, the left side of the window displays a directory of files and folders on the local computer.

The right side of the window displays content when the FileZilla client is
connected to a Web server, specifically, directories of the Web server’s fold-
ers and files.

If you use a different FTP client software than FileZilla, the steps and look of the software will differ, and you will need to adapt your steps and practice for the specific FTP client software you are using.

Connecting to a Web server is an easy process. Remember the FTP settings you saved from Step 7 in the previous section?