Home > Tags > MySQL
Page 1

Optimize Your WordPress Site to Load Faster

Compared to other platforms, WordPress is pretty fast. However, we can still make it run even faster. A fast loading WordPress site not only gets love from people, but also from Google. Here we look at 4 useful optimization tips that you can implement right now and get your site running faster than ever before.

1. Optimize Your Database

Your MySQL database tables should be cleaned regularly. These tables are sure to have some clutter in time and this has a direct impact on the load times of your WP site. Rather than use plugins to do this, getting a hands-on idea of what is going on with your database is most recommended.

Using the phpMyAdmin panel, choose the “Check All Tables Having Overhead” to get an overview of all the tables that need to be optimized. From the drop down menu, select “optimize table” which when completed, should display a success message. In case of errors in your DB tables, select the “Repair Table” option. Always remember to backup your database before making any major optimization efforts or repairing your database tables.

If you are running WordPress 2.9 and below, which do not support automatic database optimization, add the line below to your wp-config.php file:

define (‘WP_ALLOW_REPAIR’, TRUE);

2. Cache Your Posts

Caching your WordPress posts creates .html files that are served to visitors instead of having to query the database every time, effectively speeding up your website. To do this, you can use popular WP plugins like WP Super Cache, Hyper Cache, W3 Total Cache or the DB Cache. Some plugins like the W3 Total Cache improve your server performance, caching every aspect of your site and reducing download times of site elements.

If you are caching a high traffic website, you might want to consider adding an opcode cache like Alternative PHP Cache (APC) to your server to enhance PHP’s performance. Using a CDN (content delivery network) helps to server your content via a number of servers. This is an expensive option as most CDNs are quite expensive. I would recommend a CDN like CloudFare – it is free but with features that come close to paid services.

3. Compress and Combine Your JS and CSS Files

Compressing and combining JS and CSS files has been shown to improve site loading times. Compressing reduces the overall page size while combining multiple files reduces the number of HTTP requests to the web server required to retrieve the files. There are many JS and CSS compressors out there available for free.

Again, you can do this manually by rewriting the URLs that point to the respective CSS and javascript libraries to point to one destination and then using a small script, concatenate the requested files, compress and send to the browser.

A much easier way would be to use the WP Minify plug-in that combines your various JS can CSS files into one file. And of course compressing images further using a plugin like WP Smush.it does not hurt.

4. Use CSS Sprites

This is a fantastic technique of combining multiple images into a single file with all the information about the graphical elements in it. Sprites can, for example, be used to on a blog’s sidebar where there are 5 buttons each requiring 5 images. These 5 different images can be combined into one file requiring only that single file to be loaded thereby speeding up the site and saving bandwidth.

I recommend a tool like “Sprite Me” to make your sprite coding job easier.

5. Clean Your House

Of course, there are other obvious ways to speed up a WP site like upgrading your WordPress installation, upgrading plugins and deleting unused plugins.  These should be on your regular site maintenance list.

...
more →

Getting Started with Python Programming: Creating a Blog

How do you create a simple, dynamic website using the Python programming language? In this tutorial we are going to learn how to do exactly that. First, lets get some basics about Python.

Classes and Methods in Python

Python is primarily object-oriented. Class instances (objects) in Python are defined as shown below:

class coder: coding_languages = 10 david = coder() david.coding_languages = 5 print “David knows s languages.” % david.coding_languages

Running the above script from the terminal gives the results below:

“David knows 5 languages.”

Methods in Python are functions contained within a class. Methods are written in Classes and referenced using objects. Methods are defined as shown below:

class coder: coding_languages = 10 def learn(self): print “I know s languages.” % self.coding_languages

Consider another method below:

class google(coder): def chrome(self): print “Ow snap!” david = coder() david.chrome()

Variables get inherited the same way as Classes.

In languages like PHP, you only need to code the functions specific to your website. When using Python you can use frameworks like Django, Web.py, Grok and TurboGears. When using Django, install it both locally and on your server when deploying. Django is an MVC framework which is feature-rich and its tutorials are easily available online and this is what we are going to be using in this tutorial.

Creating a Simple Blog

Start your first Django project using the command below:

Django-admin.py startproject SimpleBlog

When you list the files inside the above folder, SimpleBlog, you will see three files have been created: manage.py, settings.py and urls.py

We will start by creating our first app as follows:

Python manage.py startapp blog

This creates a directory called “blog” which is our app. We need to define our models using the models.py file. For a blog we will need a table. We create a table as shown below:

class posts(models.Model): author = models.CharField(max_length = 30) title = models.CharField(max_length =100) bodytext = models.TextField() timestamp = models.DateTimeField()

After installing mySQL as your database, install the Python library for interfacing with the DB (I use Easy Install) and then create the database. Set your Django project to work with your mySQL database.

Add all the models we created into the database using the command below:

manage.py syncdb

This command simply adds new fields and does not alter existing ones in the database.

Set up the urls pattern (urls.py) to the appropriate module as shown:

Urlpatterns = patterns(), url(r’^$’, ‘SimpleBlog.blog.views.home’, name= ‘home’),

Under views.py, add the code below:

from django.shortcuts import render_to_response from blog.models import posts def home(request);...
more →
Karl says: your templating system for the code has completely destroyed the right python syntax. You might have to fix a few things such as...

Enhancing WordPress Functionality with BuddyPress

A few weeks ago, I was working with a fellow developer and trying to figure out how we could enhance the functionality of a WordPress website that required managing visitor logins. The site, which was for poets and writers, would allow visitors to set up accounts, submit content, interact with others on the website and share content to outside circles on Facebook and Twitter. After scratching our heads for a number of days, we came to the conclusion that BuddyPress would provide the needed solution. A couple of weeks later, we can see our decision was not misguided.

In our case, BuddyPress worked because it accomplished what it was created to do: enable people with similar interests to connect and communicate. The BuddyPress package however is more than a social networking tool. Companies can use it as an internal communication tool and some universities and colleges have used it to deploy a wide social network on their website. While most institutions are powerless to control and monitor Facebook interactions, BuddyPress provides a safe and secure environment with similar functionality but with the ability to monitor student activity.

BuddyPress is open source and makes available its core code online. In addition, users are free to use its themes, plug-in extensions and contribute their time and knowledge to the project.

The BuddyPress Core

Since BuddyPress is essentially an enhanced WordPress plug-in, it is written with the same primary technologies that power its parent base i.e. PHP and MySQL. Most users will therefore find it real easy if they have previously been working on WordPress. The package extends the integral functions of the WordPress engine to include themes, plugins and widgets effectively inheriting what has been there all along.

BuddyPress Features

In order to allow the creation of social networking applications, BuddyPress comes installed with some basic functionality that includes Activity Streams, User Profiles, Group Creation, Friend System, Bespoke themes and Blogs per user. Even with its own login functionality, BuddyPress integrates with the underlying WordPress platform in such a way that only a single sign-on is required to the system for users thereby providing seamless experiences across the board.

With most users already on social networks, BuddyPress offers a solid strategy of helping you attract new members by allowing you to link user profiles to their other social networks like Facebook and Twitter. Using a code snippet or a plug-in, users can easily share their activity on social networks as well as allow others to check out their other profiles on these outside platforms. Members can even share their profiles on social networks if they want others to join them in their new ‘social network’.

Group Forums

Groups and group forums are popular on the Web and within communities, and BuddyPress offers communities an easy way to post and reply to forum posts. Members have the freedom to search all public forum topics from the Forums Directory and even post a reply or start a forum topic in a public group even when they are not group members. Any time a member adds a post or replies to a forum post, he or she auto joins that group. Group forums in BuddyPress are made up of Forum Topics and Discussion Threads. Forum topics are proposed discussion subjects while discussion threads are the conversations and replies that result from a particular topic.

Users can easily search and filter forum topics and groups using various parameters as well as create new Forum Directory topics in the same way.

BuddyPress also offers other enhancements that include site-wide forums, avatar uploads, a friend messaging system and a bunch of interesting plugins and themes.

BuddyPress can be installed directly through the WordPress dashboard plugins page or downloaded manually from the plugins repository and uploaded to your website. The latest BuddyPress build can also be downloaded from the SVN repository for developers who want to get their hands dirty.

...
more →
David Gitonga says: Great News, BuddyPress users. Version 1.6 is out. This is a major BuddyPress feature release. BuddyPress 1.6 introduces many...

Create your own CRUD app with PHP & MySQL (Part 2)

Picking up from where we left off, we need to start by creating some HTML to display the data we’ve stored in the $results variable. You can always modify this to suite your project. I’ll be using a table structure.

<!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <link href="styles/theme.css" rel="stylesheet"/> <title>PHP & MySQL</title>\ </head> <body> <div id="wrapper"> <table> <thead> <th>Title</th> <th>Release Date</th> <th>Publisher</th> <th>System</th> <th>Rating</th> <th>Number Of Players</th> <th>Tools</th> </thead> <tbody> <?php foreach($results as $entry): ?> <tr> <td><?php echo $entry->title; ?></td> <td><?php echo $entry->release_date; ?></td> <td><?php echo $entry->publisher; ?></td> <td><?php...
more →
Marty Lavender says: Your code had a lot of errors. All of which I have been able to fix on my own. I cannot however figure out how to resolve this...

Free, expert website monitoring!

Knowing if your website is working properly is the first step in catching potential problems before they blow up. But unless you have time to check your site every five minutes or you want to wait for your visitors to tell you there’s a problem, you need some kind of monitoring service.

Monitor Scout provides web-based monitoring that lets you know when your site is having problems, twenty four hours a day and seven days a week. You’ll know about issues before your visitors notice, and in time to fix them before they cause real problems.

Whether you run a blog, e-commerce site, or something else entirely, uptime is crucial. The last thing you want is for a visitor trying to use your site to encounter problems that prevent them from making a purchase, finding the information they need, or contacting you. If that happens, there’s a good chance they’ll take their business elsewhere — straight to one of your competitors.

Monitor Scout gives you expert monitoring that includes more than fifty different checks, server health monitoring, technical support, SMS and email notifications (including 5 free SMSs), and 1 minute check intervals. And while Monitor Scout is in beta, you can use their service for free!

It only takes minutes to get up and running with Monitor Scout. There’s no software to install and in addition to simple uptime monitoring, it also does internal server monitoring with threshold notifications for RAM, HDD, NIC, CPU, and processes. Your site will be monitored from more than fifteen different locations worldwide. Monitor Scout also supports a wide array of applications and protocols.

Monitor Scout includes a ton of different reporting and analysis tools, including uptime graphs, latency graphs for all monitors and locations, and usage and performance graphs for memory, CPU, network interfaces, hard disks, and processes. Alerts give you detailed information about the problem your site is experiencing, including location, monitor, and device. That information can then be used to diagnose problems and prevent them from recurring in the future!

But you get more than just server monitoring. Crucial business applications will also be monitored, including email, CMS, MySQL, and PostreSQL, among others. A script repository offers functions and scripts that will help you enhance your monitoring experience.

Whatever type of website you run, a monitoring service like Monitor Scout is a must-have to stay on top of potential issues and downtime, and improve user experience!

...
more →
Think360 Studio - Web Design says: Hello everyone. I really enjoyed this article. It would be really helpful. Thanks for sharing this article.

Develop, Deploy and Maintain in Coda

Coda by Panic bills itself to be “one-window web development.”

I have been a web developer (or at least playing with code) for the past six or seven years, and purchased Coda about a year ago. It took me almost this long to realize the beauty that lies within the code editor when you truly use it as a one-window web development system.

Today, I’m going to walk you through setting up your next WordPress site so you can develop locally, deploy to your live server, and maintain the code base and providing site maintenance. All in Coda. So let’s get started.

Developing a WordPress Website Locally

If you’re new to developing WordPress websites, you’ll definitely want to get up to date on WAMP or MAMP, which stands for Windows/Mac, Apache, MySQL and PHP. Basically, it is everything you need to develop a dynamic website, such as WordPress (or Joomla!, Drupal, etc) on your machine.

The advantages to this are incredible. First off, you’re recreating a server on your machine, which means as long as you’re running MAMP, you don’t need to be connected to the internet. So, if you find yourself 30,000 feet in the air on a Boeing 737-400, you can still work on that WordPress website you promised your client. [Note: if you use CDN content such as jQuery or other JavaScript libraries, those still need an internet connection. I found that out the hard way a few days ago. When developing, always have a copy of the most up-to-date script on your machine.]

To get MAMP or WAMP, visit their respective sites and download the application. Installation is fairly self-explanatory, and there are dozens of tutorials on how to set up local development for WordPress.

Getting Set Up With Coda

The first step to creating a great development process with Coda is to plan it out a little. Think of where your files are going, locally and on your server. A little planning here makes the development process a lot easier when setting up your site on Coda.

Let’s take a visual look at the set up for a sample project.

So, as you can see, you’ll have two sets of code bases, one locally on your computer and one live on your server. Obviously, the local code base can be previewed with the magic of MAMP or WAMP, while the live code base is viewable by your customers or clients.

With the layout of the development and deployment system framed out, let’s jump into Coda.

Setting Up A Coda Site

The first tab you want to utilize in Coda is the ‘Sites’ tab.

Next, you’ll want to look in the bottom corner and click “Add Site”. This will bring up the Site creation menu, where you can set up your local code base, FTP to your server, your local preview site, and your live preview domain.

Starting from the top, the Nickname is obviously the name of the site or project. The Root URL is the domain for the server that this site will live on. As the tool tip suggests, Coda will take a quick screen grab of this domain and use it as the preview in the Site menu.

Moving down the list, the Local URL is the domain that your MAMP or WAMP uses. This enables the “Preview” tab in Coda when using a database driven solution. For my setups, my Local URL is always http://localhost:8888. Check your MAMP or WAMP set up and check what your local server is.

The Remote Root is the location on the server where your files will be placed. This could be the root of the server, or could be a subdirectory. Finally, the last key is the Local Root, to which you can browse, select your local code base, and get to work.

The next major section is your FTP information to connect to your server.

Once you’ve got all that set up, click Save and let’s get to work.

Developing Locally

Once you’ve got your site set up, simply double click on it to open up a code editor with your theme file folder on the left and any open files that you were working on. The beauty of the Site is that you can save all of your work, close Coda, come back hours later, click your Site and everything opens up just where you left off.

If you’ve created a WordPress theme before, you know what you’re doing at this point. The connections we created when we set up the site will now allow you to edit PHP and preview the WordPress website in the “Preview” tab. Be sure that this isn’t your exclusive testing, though, as you should always check your website in every browser that you possibly can.

Publishing to Remote Server

So you’ve been hard at work creating your theme locally and you’re ready to publish to the remote server. All it takes is the click of a button.

Once you hit “Publish All”, every file that you have saved will be pushed via FTP to your web server – all from the same Coda window. Sorry if you were hoping the publishing section of this article was going to be longer… but it’s really quite simple.

Maintaining Your Site, Locally and Remotely

Whether you’re working for a client or a personal project or your brand new portfolio website, you will definitely have to maintain the code, add or delete features, and change up the CSS. With your set up in Coda, you’ll never have to dive into the clunky WordPress editor or deal with downloading and uploading FTP files for hours on end.

Within your site, you can quickly select whether you want to work on the Local code base or Remote code base. My recommendation is to always work on the local code first, then Publish All to the web server. Since you have MAMP or WAMP set up, you can preview exactly what your site will look like on the live server without committing the changes. Once you’re satisfied with the changes, publish all and go to bed happy.

Further Extension

While this article touched on a few of Coda’s positives in the Site, Editor and Preview windows, they also have full Terminal support, a dedicated CSS editor (although I prefer to write the CSS by hand), and a Books section, with several free handbooks and the ability to add more. Those items are outside of the scope of this article, but if you’re looking for more information on them, visit the Coda website to read more.

Conclusion

The set up I’ve described above is my go to set up for web projects at the moment. Do you use Coda (or another one-window editor like Espresso)? How do you develop, publish and maintain your websites? Join in on the discussion in the comments below.

...
more →
Bob Rockefeller says: I'm reading this kind of late, but I've come upon a recent interest in doing this, or something close to it. But it leads to a...

Building a PHP Ad Tracker: Creating the Database Tables

For the vast majority of modern websites, advertising is a major source of revenue.

Banner ads for services related to the web site owner’s industry allow customers to view products that tie into the site owner’s core business. In exchange, the web site owner can charge the banner ad owner for every impression (banner ad appearance) or click-through (when a user clicks the banner ad).

In order to build a banner ad management system, we must first create the database tables that will hold the ad information, the client data and the activity schedule for each ad.

Step 1: Create MySQL Advertisement Table

First, we must build a table to hold the data on each particular banner ad. The table will contain: ·    a primary key ID number for each ad ·    a foreign key ID number (tied to the client ID) ·    the title of the ad ·    the URL.that the page will redirect to when the ad is clicked ·    the file path of the ad banner ·    the ad’s “active” status (active/inactive) ·    the ad’s “deleted” status ·    the date the ad was created ·    the last date the ad was modified ·    the date the ad was deleted

The MySQL script below will create the devdrive_ads table:

CREATE TABLE devdrive_ads ( ad_id int(10) NOT NULL auto_increment, ad_client_id int(10) NOT NULL default '0', ad_title varchar(200) NOT NULL default '', ad_url varchar(255) NOT NULL default '', ad_path varchar(255) NOT NULL default '', status int(1) NOT NULL default '1', deleted int(1) NOT NULL default '0', deleted_dt datetime default NULL, created_dt datetime NOT NULL default '0000-00-00 00:00:00', modified_dt datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (ad_id) ) TYPE=MyISAM;

Step 2: Create the MySQL Clients table

Each banner ad must have a client. Since some clients may have multiple banners, we need a separate table for the client data, rather than including it in each line of the devdrive_ads table.

The clients table will contain: ·    a primary key ID number ·    the client’s business name ·    the name of the primary contact at the client’s office ·    the client’s email address ·    the client’s phone number ·    the client’s “active” status ·    the client’s “deleted” status ·    the date the client record was created ·    the last date the client record was modified ·    the date the client record was deleted.

The MySQL script below will create the devdrive_ads_clients table:

CREATE TABLE devdrive_ads_clients ( ad_client_id int(10) NOT NULL auto_increment, ad_client_name varchar(100) NOT NULL default '', ad_client_contact varchar(100) NOT NULL default '', ad_client_email varchar(100) NOT NULL default '', ad_client_phone varchar(20) NULL default NULL, status int(1) NOT NULL default...
more →
JD says: a couple things i would change (just from personal experience/preference). in devdrive_ads: add start_date & end_date so i...