This post is written to help out beginners that are planning to or have just started their web development adventure. It is not the only way of managing your local environment, but it is one of the better ones.
After working on Magento projects for a longer period of time on a local Windows development machine, you can notice mild to heavy performance drop. This is because Magento is a huge system that has a lot of small files and a lot of database tables/entries. The latest Magento CE, for example, contains 11,900+ files and 4,435+ folders by default (not to mention SVN’s files, if you have to work with it or haven’t yet realised the advantages of git). Multiply that by a dozen of projects (active ones and in support phase) and you’ll have some serious fragmentation issues. SSD disks are good, but personally, I don’t yet see them as a reliable solution.
Create Windows virtual host
… and create it on a separate partition. One partition for each project you are working on. You will achieve another thing with using partitions – higher possibility of data recovery in case of system failure (Murphy’s law: Very important files that are not tracked with version control system will die first). Here’s step-by-step guide:
- Create a new partition by using your favourite partitioning tool. Let it be 2 times bigger than what you estimate your project’s size would be (3 times if you are using SVN). Create a new folder that will hold your Magento project (for example X:\yourmagentoproject\)
- Stop your Apache server and enable showing hidden files in Windows.
- Open your favourite text editing tool as an Administrator. Good old Notepad can do the job just fine. If you already don’t know, even if your Windows user has privileges of an Administrator, you don’t have all the file editing rights automatically. Use Windows search bar to find Notepad, right click the result and pick “Run as Administrator”.
- Open hosts file (default location is “Windows\System32\drivers\etc\“) in your text editor and add your new domain name for your Magento project in a new line at the end of the file1
- Open Apache’s main configuration file httpd.conf. Default location is in conf folder of your Apache installation. Find the following line:1
# This should be changed to whatever you set DocumentRoot to.
There is a block that defines your default document root. Add the following block after that Directory block:123456
Options Indexes FollowSymLinks
Allow from all
- Open Apache’s virtual hosts configuration file, typically found in your Apache folder at \extra\httpd-vhosts.conf. Add the following to the end of the file:123456
DirectoryIndex index.php index.html index.htm not-a-file
In case you are wondering, yes… directory index is defined in vhosts file.
- Start Apache.
Moving MySQL data files to a separate partition
Magento has a lot of tables in its database. Each table is saved in its own .frm file inside a folder named after the database name. Every piece of information you add, edit or delete inside Magento admin is saved in the database along with the frontend visiting logs and statistics. You will also often have to work with client’s databases from existing sites that will be deleted when they are no longer needed and replaced with your freshly built ones. That’s a lot of file management tasks that your disk needs to handle. That means a lot of fragmented files that represent database tables and it’s only piling up over time.
Step-by-step guide how to transfer your MySQL data files to a separate partition:
- Create a new partition that will hold your MySQL data files. Don’t forget to make it big enough to hold all the databases you’ll need.
- Stop the MySQL server.
- Locate your MySQL data files folder. By default, it’s in the data folder of your MySQL installation directory. Copy the entire folder (not just the content of it) to the new partition. Your new folder’s location should be something like Y:\data\
- Open my.ini and add/edit the following lines:12
#Path to the database root
#*** INNODB Specific options ***
- Start the MySQL server
I really hope that this post will be obsolete in a year. That’s a reasonable timespan for SSD manufacturers to resolve the reliability issues of their drives. In the mean time, with this method you can more easily backup and defragment only projects that you are working on, you can even zip the whole project, quickly re-format the partition and unzip the project to get the fresh start. And it’s a neat way of organising your projects.