Often we want to install WordPress manually on our own instead of going through the cPanel administration interface. WordPress is an incredibly easy application to set up. All you require is FTP access and the appropriate versions of PHP and MySQL. Unfortunately, the WordPress download file is a “zip” archive and we need the extracted files in our directory or subdirectory in order to work with them. The FTP protocol doesn’t allow the zip file extraction so we need to do it ourselves. One way of course is to manually unzip the archive on our local computer and upload the extracted folder via FTP. But this can be a long and laborious process. A typical fresh WordPress installation has lots of files and folders and since FTP transfers one file at a time, it can get pretty tiresome especially if you have several installations to take care of. To unzip WordPress package files on the server efficiently, we need to use another technique.
One way is to get shell access and extract the files directly on the server itself. But that’s a different ballgame altogether. Many people are familiar with FTP but don’t want to bother with shell access. Fortunately, the PHP environment itself provides us with an easy way to unzip files. And since PHP is a file-based framework, all we need to do is write a line of code to get the job done. Here’s how we go about it.
Upload the PHP Script
The first step is to download the fresh WordPress installation from the official website. Head to http://wordpress.org/download/ and obtain the zip archive on your desktop. Once the download is complete, make a note of the filename. It’ll typically be “wordpress” followed by the version number. We’re going to use this filename to create a simple PHP file. Open up notepad or a plain text editor and type in the following lines:
<?php $unzip = shell_exec("unzip wordpress-3.8.1.zip"); echo 'Unzip command executed'; ?>
In the second line, replace the file name ending with the “zip” extension with whatever name you obtained in the first step. In this example, I’m simply using the latest WordPress version number. Save this file with a .php extension. I’m calling it “unzip.php”. Using FTP, upload this file onto your Web server.
It’s important to keep in mind that by default, the WordPress archive will extract into a directory – usually called “wordpress”. So if you place unzip.php (and the zip archive) into your root location, the WordPress files will be extracted into root/wordpress. If this is not the behavior you want, you may consider extracting the files onto your desktop and then rezipping them so that they extract into the original location instead of a sub directory.
Uploading WordPress and Extracting
Next, simply upload the WordPress archive file into the same location that you placed unzip.php. Now you just need to visit the PHP file using a web browser by typing in the location you uploaded it to. If all goes well, the extraction should proceed smoothly and you should see a confirmation message as shown below:
And here you can see that the extraction has indeed progressed smoothly. The process has created its own directory into which the WordPress files have been extracted.
From here, you can set the blog address either to a renamed sub directory or even the root – but that is a discussion for another day. You can use this technique to unzip any archive of course, not just WordPress. If you find yourself doing this regularly, you save yourself a lot of time and effort!