There are many ways to install the WordPress content management system. This tutorial introduces two methods for installing WordPress from a public repository: SVN or Git.
While you can install WordPress in a few different ways, e.g. using a one-click image, downloading a zip file, or using the built-in FTP service – using a repository has some unique benefits.
- Quick upgrades and downgrades to different versions of WordPress
- More secure protocols for transferring the files
- Faster updates since only the changed files are transferred
What happens if you update WordPress to the latest version and your site goes down? With SVN or Git, you can easily roll back the file changes with one command. This is impossible with the FTP updater.
Follow this tutorial to install Apache, MySQL, and PHP on your server:
You can stop after Step Three — Install PHP.
Install Git with the following command:
You’ll need to answer yes to accept the download. Now let’s test it. Enter the following command:
You should see the following message:
First, figure out which version of WordPress you want to install. The best place for this is to visit the official WordPress website.
At the time of writing, this is WordPress 4.0, so that’s what we’ll use in the examples.
Decide where you want to install WordPress. In this example we’ll use the default Apache document root, /var/www/html. If you want to set up a virtual host, you can do that instead.
Clone the latest version of WordPress from the GitHub repository:
The general form of the command is as follows:
You’ll see some messages such as Cloning in… along with, but not limited to, Receiving objects: and Receiving deltas: with some information. You now have a complete working development copy of WordPress, including past production runs.
However, we want the latest production (stable) version. First move to the WordPress directory on your server:
Check out WordPress 4.0, or the latest stable version, with the following command:
The general form of the command is as follows:
Git will display some information along with something like
HEAD is now at 8422210... Tag 4.0, which indicates the file versions were successfully changed; in this case to 4.0.
Congratulations! You’ve just installed WordPress using Git.
Now we need to set up the database and configure WordPress.
Follow the instructions in this WordPress installation tutorial, but without the wget, tar, and rsync commands.
You do need to set up the database, change the wp-config.php details, and run the chown command:
At this point WordPress is ready to use! Visit your IP address or domain in your browser, and set your website and login details as prompted. You can add themes, plugins, and content as you like.
Git uses a special directory called
.git that contain important information. You should block web access to this directory for security’s sake.
If you want to see what it looks like now, visit http://example.com/.git/ in your browser, using your own domain name. It should list the files in the directory, which is a security issue.
First, open your Apache configuration file for editing:
Locate the AllowOverride line in the
Now create a new .htaccess file in the /var/www/html/.git/.htaccess directory:
Add the following contents to the file:
Now you, or anyone trying to snoop on your server, will get an Internal Server Error if they visit http://example.com/.git/.
Now it’s time to upgrade WordPress. You’ll want to keep up with security patches, bug fixes, and new features. So let’s discuss how to upgrade with Git.
It’s always a good idea to make a backup.
Connect to your server with SSH, and move to your WordPress installation directory:
Fetch the latest files from the third-party WordPress repository:
The -p switch tells Git to remove any old versions that are no longer in the repository. This helps keep your files in sync with the remote server.
Execute this command to check out a new version:
[VERSION] is a placeholder for the actual number of the release. If the new version to be installed was 4.0.1, the command would be:
This is also the method for downgrading, too. If you want to return to version 3.9.2; you would do that with this command:
To see all the available options, check the branch dropdown and the Tags tab on the repository page.
That’s it! With Git, your custom settings, like your wp-config.php file and your themes and plugins, should stay the same. However, if you’ve modified any of the core files, you may run into problems; hence the need for a backup.
Once you have the files, you need to let WordPress make the changes it needs in the database.
Click the Update WordPress Database button.
That’s it! You should now be on your desired version of WordPress. If your site isn’t working after the change, simply check out the version you had before.
If you made it to the end of this tutorial you should have a basic understanding of setting up WordPress using the SVN and/or Git system(s). It is important to note that this method will back up the core WordPress system, but your custom themes and plugins will require a different approach.
Now that you have learned how to manage WordPress with version control, you’ll probably never want to go back. This is so much faster, easier, and safer. You don’t need to store any FTP information in your WordPress installation. Also, you can easily and quickly revert back to previous versions if the need arises, something that the FTP method makes more difficult.
This guide is not a replacement for a good backup system, so make sure you have good backups, too.