{"id":18,"date":"2013-10-11T17:02:57","date_gmt":"2013-10-11T16:02:57","guid":{"rendered":"http:\/\/david.lidstone.me\/blog\/?p=18"},"modified":"2022-05-31T22:05:26","modified_gmt":"2022-05-31T21:05:26","slug":"setting-up-php-development-environment-p1","status":"publish","type":"post","link":"https:\/\/david.lidstone.me\/blog\/?p=18","title":{"rendered":"Setting up a PHP Development Environment &#8211; Part 1"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#ffe2c7\" class=\"has-inline-color\">\u00a0Note that this was published back in 2013 and is obsolete. I plan on doing a more modern development environment tutorial at a later date. Images are missing from this entry.<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I&#8217;m going to show you how to set up a fully featured development environment for PHP5 on Windows (I&#8217;m using 7) It will use <a title=\"Eclipse IDE\" href=\"http:\/\/www.eclipse.org\/\" target=\"_blank\" rel=\"noopener\">Eclipse<\/a> Juno, with <a title=\"The Uniform Server\" href=\"http:\/\/www.uniformserver.com\/\" target=\"_blank\" rel=\"noopener\">The Uniform Server<\/a> as your WAMP stack. I&#8217;m going to break this into a few parts, but you will end up with a full working local development environment with PEAR, XDEBUG, PHPUnit2, Git, <a title=\"phpDocumentor2\" href=\"http:\/\/www.phpdoc.org\/\" target=\"_blank\" rel=\"noopener\">phpDocumentor2<\/a> and <a title=\"DStruct Framework\" href=\"http:\/\/www.dstruct.org\/\" target=\"_blank\" rel=\"noopener\">DStruct Framework<\/a>. What bits you&nbsp;set up or use is obviously your choice.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<!--more-->\n\n\n\n<p class=\"wp-block-paragraph\">I want to start with quickly discussing the whats and whys. I&#8217;ve been developing for a long time and for many years used the excellent <a title=\"Notepad++\" href=\"http:\/\/notepad-plus-plus.org\/\" target=\"_blank\" rel=\"noopener\">Notepad++<\/a> with <a title=\"XAMPP\" href=\"http:\/\/www.apachefriends.org\/en\/xampp.html\" target=\"_blank\" rel=\"noopener\">XAMPP<\/a> and our company&#8217;s internal SVN \/ Track server with <a title=\"TortoiseSVN\" href=\"http:\/\/tortoisesvn.net\/\" target=\"_blank\" rel=\"noopener\">TortoiseSVN<\/a>. It all worked well, but the opportunity to change came up, and I thought I&#8217;d try something different. It was a bit of work getting everything up and running, but I think it is worth it &#8211; I now have code-completion, easy debugging, unit testing, easy documentation and more. I used to use XAMPP, but prefer The Uniform Server. I&#8217;ve just had less trouble with it and I like the GUI included, especially for PEAR modules. All the other tutorials I&#8217;ve come across are incomplete &#8211; only covering one part of setting up your environment, but I want to cover it all. That means an environment which is for multiple projects, uses UTF-8 from the browser to the database and back again, includes all the tools developers use on a daily basis etc. Also, there are so many old projects out there which have been superseded or abandoned that I had problems finding out which tutorials I should actually follow.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I should also add that much of this was learnt from elsewhere. I&#8217;ll try to reference the original sources where I used them, but I apologise if I&#8217;ve missed any out \/ forgotten where I found stuff.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ok&#8230; on with the show. I&#8217;m going to run through this quite quickly, rather than going through every mouse click, but if it&#8217;s not clear and you have any questions, leave me a message and I&#8217;ll look at updating things.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Install Eclipse and start a new Project<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a title=\"Download Eclipse IDE\" href=\"http:\/\/eclipse.org\/downloads\/\" target=\"_blank\" rel=\"noopener\">Download<\/a> and install Eclipse. The Standard version should be fine. You&#8217;ll need <a title=\"Java\" href=\"https:\/\/www.java.com\" target=\"_blank\" rel=\"noopener\">Java<\/a> installed and will get an error message if you try to start Eclipse without it. You don&#8217;t need to separately install Git in Eclipse as everything you need is included (eGit).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a folder where you will start your projects. This will not be where our projects end up, as we will move them when we add them to source control.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Start Eclipse and use the folder you just created as your Workspace when prompted.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Go to <em>File &#8211;&gt; Install New Software&#8230;<\/em> and click <em>Add<\/em>. Call it PDT (short for PHP Development Tools) and use the URL: <em>http:\/\/download.eclipse.org\/tools\/pdt\/updates\/release<\/em> Install PDT.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"http:\/\/david.lidstone.me\/blog\/wp-content\/uploads\/2013\/10\/add_pdt_repository.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-23 alignnone\" src=\"http:\/\/david.lidstone.me\/blog\/wp-content\/uploads\/2013\/10\/add_pdt_repository.png\" alt=\"Add PDT Repository\" width=\"489\" height=\"188\"><\/a><br>Create a new PHP Project in Eclipse. Make sure<br>you click &#8216;Create new project in workspace&#8217;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Click <em>Project &#8211;&gt; Properties<\/em> and change the text file encoding to UTF-8. If you want, also change the new text file line delimiter setting.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Add your Project to Git<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">I&#8217;ll be going through the absolute basics to set up a project on Git, but I highly recommend you familiarise yourself with this tutorial <a title=\"eGit Tutorial\" href=\"http:\/\/www.vogella.com\/articles\/EGit\/article.html\" target=\"_blank\" rel=\"noopener\">http:\/\/www.vogella.com\/articles\/EGit\/article.html<\/a> which covers most eGit functionality.<br>Right click on your project and choose <em>Team &#8211;&gt; Share Project<\/em>.<br>Select &#8216;Git&#8217;.<br>Untick &#8216;Use or create repository in parent folder of project&#8217;.<br>Click the &#8216;Create&#8230;&#8217; button and choose a folder to contain your repo (don&#8217;t use a space in the folder name if possible).<br><a href=\"http:\/\/david.lidstone.me\/blog\/wp-content\/uploads\/2013\/10\/create_git.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-24\" src=\"http:\/\/david.lidstone.me\/blog\/wp-content\/uploads\/2013\/10\/create_git.png\" alt=\"Create Git Repo\" width=\"525\" height=\"433\"><\/a><br>Back on the &#8216;Configure Git Repository&#8217; page, leave the &#8216;Path within repository&#8217; blank.<br><a href=\"http:\/\/david.lidstone.me\/blog\/wp-content\/uploads\/2013\/10\/configure_git.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-25\" src=\"http:\/\/david.lidstone.me\/blog\/wp-content\/uploads\/2013\/10\/configure_git.png\" alt=\"Configuring new Git repo\" width=\"848\" height=\"497\"><\/a><br>Finish, and in the Project Explorer your project should now have the name you gave it in square parenthesis and something like &#8216;NO-HEAD&#8217;.<br>Add some files to your project if you wish (empty folders can not be added to Git), and when you&#8217;re ready, submit your first commit to the repo&#8230; I&#8217;ve opened the &#8216;Git Staging&#8217; tab in the &#8216;View&#8217; pane at the bottom of Eclipse. Drag the unstaged files into the staged area, add a message and commit.<\/p>\n\n\n\n<figure class=\"wp-block-image alignnone\"><a href=\"http:\/\/david.lidstone.me\/blog\/wp-content\/uploads\/2013\/10\/initial_commit.png\"><img decoding=\"async\" src=\"http:\/\/david.lidstone.me\/blog\/wp-content\/uploads\/2013\/10\/initial_commit.png\" alt=\"Making initial Git commit\" class=\"wp-image-26\"\/><\/a><figcaption>Initial Git commit<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">3. Install and set up The Uniform Server<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Download <a title=\"The Uniform Server\" href=\"http:\/\/www.uniformserver.com\/\" target=\"_blank\" rel=\"noopener\">The Uniform Server<\/a> and install it in <code>c:\\<\/code>. Do not use any spaces in the installation folder name. If you do so, it will lead to permissions issues and other problems.<br>Start the Uniform Server Service GUI and use the Server Configuration to set up Apache vhosts. Instead of your domain name &#8220;www.example.com&#8221;, use something like &#8220;www.example.local&#8221;. We&#8217;ll use the local hosts file later on to point the<br>DNS. On the version I have installed, the DocumentRoot does not get wrapped in double quotes. This can mean the server won&#8217;t start if there are spaces in the path, so you may need to manually edit the file. On my installatin, Apache vhosts is here:<br><code>C:\\UniServer\\usr\\local\\apache2\\conf\\extra\\httpd-vhosts.conf<\/code><br>Install and start the Apache and MySQL services. Remember to set a root password on MySQL.<\/p>\n\n\n\n<figure class=\"wp-block-image alignnone\"><a href=\"http:\/\/david.lidstone.me\/blog\/wp-content\/uploads\/2013\/10\/uniform_service_interface.png\"><img decoding=\"async\" src=\"http:\/\/david.lidstone.me\/blog\/wp-content\/uploads\/2013\/10\/uniform_service_interface.png\" alt=\"The Uniform Server Interface\" class=\"wp-image-27\"\/><\/a><figcaption>The services have been installed and started.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><br>Go to <em>Server Configuration &#8211;&gt; PHP<\/em> and choose &#8216;Install PEAR&#8217;. You can go ahead and add any PEAR modules you want, but <strong>don&#8217;t<\/strong> install PHPUnit &#8211; it&#8217;s an old version. I&#8217;ll go through adding PHPUnit2 in a later tutorial.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. Set up DNS in hosts file<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The local computer needs to know where to find &#8220;www.example.com&#8221; and so we need to set up the local hosts file which is your PC&#8217;s first port of call when resolving an address. I recommend using Notepad++ to edit this file. Although<br>To open the hosts file, run your text editor of choice as Administrator and use&nbsp;<em>File &#8211;&gt; Open<\/em> and paste in:<br>%Windir%\\System32\\drivers\\etc\\hosts<br>All the text in the hosts file will probably be commented out. Append the domain name you set up in Apache vhosts to a new line at the bottom of the file:<br><code>127.0.0.1 &nbsp;&nbsp; www.example.local<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. Add PEAR to your project<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Next, we need to link PEAR into Eclipse.<br>Right click on your project in the Eclipse PHP Explorer. Click &#8216;Properties&#8217; and then select &#8216;PHP Include Path&#8217;, then the &#8216;Libraries&#8217; tab.<br>Click the &#8216;Add Library&#8230;&#8217; button, then &#8216;Next &gt;&#8217; to select &#8216;User Library&#8217;.<br>On the next page, click &#8216;Configure&#8230;&#8217; and then &#8216;New&#8230;&#8217;.<br>Call the new library &#8216;PEAR&#8217; and tick the &#8216;Add to environment&#8217; box, then &#8216;OK&#8217;.<br>Select the library you just created and click &#8216;Add External folder&#8230;&#8217;, then select the folder which contains PEAR. On my installation, it is:<br><code>C:\/UniServer\/home\/us_pear\/pear<\/code><br>It should end up as shown below. In future, you don&#8217;t need to create the library, just select the &#8216;Libraries&#8217; tab when setting up a new project and tick the PEAR library.<\/p>\n\n\n\n<figure class=\"wp-block-image alignnone\"><a href=\"http:\/\/david.lidstone.me\/blog\/wp-content\/uploads\/2013\/10\/add_pear_lib1.png\"><img decoding=\"async\" src=\"http:\/\/david.lidstone.me\/blog\/wp-content\/uploads\/2013\/10\/add_pear_lib1.png\" alt=\"Adding PEAR to Eclipse\" class=\"wp-image-29\"\/><\/a><figcaption>Your set up should look similar. Note the stack of windows leading to the PHP Libraries one.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">5. Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You should now be able to open your &#8216;local&#8217; domain in a web browser. Any changes you make in Eclipse should be visible by just refreshing the page.<br><a title=\"Setting up a PHP Development Environment \u2013 Part 2\" href=\"http:\/\/david.lidstone.me\/blog\/setting-up-a-php-development-environment-part-2\/\">Part 2<\/a> covers adding PHPUnit2.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction \u00a0Note that this was published back in 2013 and is obsolete. I plan on doing a more modern development environment tutorial at a later date. Images are missing from this entry. I&#8217;m going to show you how to set up a fully featured development environment for PHP5 on Windows (I&#8217;m using 7) It will [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[5,6,7,8,10,12,13,16,17,18,19,20],"class_list":["post-18","post","type-post","status-publish","format-standard","hentry","category-programming","tag-eclipse","tag-egit","tag-git","tag-juno","tag-pear","tag-php5","tag-phpunit2","tag-svn","tag-the-uniform-server","tag-wamp","tag-xampp","tag-xdebug"],"_links":{"self":[{"href":"https:\/\/david.lidstone.me\/blog\/index.php?rest_route=\/wp\/v2\/posts\/18","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/david.lidstone.me\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/david.lidstone.me\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/david.lidstone.me\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/david.lidstone.me\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=18"}],"version-history":[{"count":1,"href":"https:\/\/david.lidstone.me\/blog\/index.php?rest_route=\/wp\/v2\/posts\/18\/revisions"}],"predecessor-version":[{"id":69,"href":"https:\/\/david.lidstone.me\/blog\/index.php?rest_route=\/wp\/v2\/posts\/18\/revisions\/69"}],"wp:attachment":[{"href":"https:\/\/david.lidstone.me\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=18"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/david.lidstone.me\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=18"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/david.lidstone.me\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=18"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}