How to setup a local web server on your computer using XAMPP
Web development work should always be done locally. When developing a website, all the development work should be done on a local LAMP Stack environment installed on your computer. That way, the production time is greatly reduced and you can fully test your work before launching.
When you are completely done developing your project, the migration to the live server is seamless. Here are the simple steps to install a local server on your PC to easily develop websites.
This article applies to the installation on Windows 98, NT, 2000, 2003, XP and Vista, of Apache, MySQL, PHP + PEAR, Perl, mod_php, mod_perl, mod_ssl, OpenSSL, phpMyAdmin, Webalizer, Mercury Mail Transport System for Win32 and NetWare Systems v3.32, Ming, JpGraph, FileZilla FTP Server, mcrypt, eAccelerator, SQLite, and WEB-DAV + mod_auth_mysql.
Installing XAMPP on your computer
- First, download XAMPP for Windows Installer
- Then run the installer on your computer and make sure that your Windows firewall unblocks Apache.
- Run the Apache administrator.
- Open your browser and go to http://127.0.0.1 – If all went well, a screen will appear where you can choose your language.
- Go to http://127.0.0.1/security/xamppsecurity.php and setup a password (it ill be used for your databases), and click on “Password Changing”.
Congratulations! You’re done! Now put your website’s files in a new directory under C:\xampp\htdocs\ (if you installed xampp in C:\xampp). For example: C:\xampp\htdocs\myproject\; and setup your databases using PHPMyAdmin located here http://127.0.0.1/phpmyadmin/.
Configuring Mod Rewrite
To finalize your installation, and make your development work much easier, go through the following steps to enable Mod Rewrite. This enables you to use fancy permalinks without the index.php appendage.
- Navigate to C:\xampp\apache\conf\httpd.conf
-
Open up httpd.conf in notepad and look for this line:
#LoadModule rewrite_module modules/mod_rewrite.so
-
Uncomment it so that it reads:
LoadModule rewrite_module modules/mod_rewrite.so
- Next, search for AllowOverride None and change it to AllowOverride All.
- Restart Apache by typing services.msc in either the command prompt or Start Search prompt in Vista.
Personalized Domain for your Local Environment
I’ve set my local environment to mimic my live environment as much as possible. For example, to access the local environment for my blog, I type this in my browser (http://richardcastera.dev). Here is how to set that up for each project:
- Navigate to C:\Windows\System32\drivers\etc\ and open the host file in a notepad editor. Make sure the following lines are written in the file:
127.0.0.1 localhost ::1 localhost
- Now add the following line to access your website locally via the URL myproject.dev (or any other URL you’d like):
127.0.0.1 myproject.dev
- Finally, open the file C:\xampp\apache\conf\extra\httpd-vhosts.conf in a notepad editor, and add the following lines:
NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot “C:/xampp/htdocs” ServerName localhost </VirtualHost> <VirtualHost *:80> ServerName myproject.dev ServerAdmin webmaster@localhost DocumentRoot “C:\xampp\htdocs\myproject” </VirtualHost>
That’s it! Hope you enjoyed the post!
Drupal – Check if a User has a specific role
Here is a quick way to determine if a user has a specific role
<?php
// Bring the user object into scope.
global $user;
// Check to see if $user has the administrator user role.
if (in_array('administrator', array_values($user->roles))) {
// Do something.
}
?>
Drupal – Adding Javascript to your module
When creating your own Drupal module, you may need to add some styling or Javascript to improve the usability of your module. Here is how to do it.
drupal_add_js(drupal_get_path('module', 'MODULE_NAME') . '/common.js');
Similarly you can add CSS to your module as well
drupal_add_css(drupal_get_path('module', 'MODULE_NAME') . '/styles.css');
Drupal – Use hook_form_alter() to set redirect path on the form
One popular use of this hook is to change the destination of a form submission. Here is how it is accomplished:
<?php
function YOURMODULE_form_alter($form_id, &$form) {
switch ($form['#id']) {
case 'node-form':
if ($form['type']['#value'] == 'story') {
$form['#redirect'] = 'new/url';
}
break;
}
}
?>
Excellent Analytics – Import Google Analytics into Excel
I ran into this nice Excel Plugin that lets you import web analytics data from Google Analytics into a spreadsheet. It’s an open source project and 100% free to download and use for individuals and businesses.
WordPress – List Scheduled Posts
If you ever wanted to show you readers posts that are scheduled to be published, here’s how to do it.
<?php
$result = new WP_Query('post_status=future&order=DESC&showposts=5');
if ($result->have_posts()) {
while ($result->have_posts()) : $result->the_post(); ?>
<?php the_title(); ?>
<?php endwhile;
}
?>
CSS – Cross Browser Opacity
A little hack to set Cross-Browser opacity.
.setOpacity {
opacity: .75; /* Standard: FF gt 1.5, Opera, Safari */
filter: alpha(opacity=75); /* IE lt 8 */
-ms-filter: "alpha(opacity=75)"; /* IE 8 */
-khtml-opacity: .75; /* Safari 1.x */
-moz-opacity: .75; /* FF lt 1.5, Netscape */
}
-
J. K. Rowling donates $15 million for MS clinic http://om.ly/tkkw
- Follow me
Last Tweet
-
Archives
Categories
My Favorites
- 37 Signals
- Andrew Warner
- Chris Coyier
- Chris Shiflett
- Collis Ta'eed
- Development Seed
- Drupal
- HubSpot
- James Padolsey
- Joel On Software
- John Resig
- jQuery
- Kevin Rose
- Life Hacker
- Magento
- Mashable
- Matt Cutts
- Matt Ryan
- MySQL
- NetTuts
- Noupe
- Photoshop Tutorials
- PHP
- Smashing Magazine
- Tech Crunch
- WoorkUp
- Wordpress
