Why I went to the cloud…

I was asked to write a blogpost about my server setup. Specifically, about “the best fixes for wrangling all of those crazy cables.” To which I responded: “Oh, I just use the cloud. Never used anything else.”

Why don’t I host my own physical server? Cold hard cash. For the level of scale I need, a few hundred hits a day, it would be overkill to buy my own.

That question got me thinking about why I do wrangle my own server, albeit in the cloud, instead of relying on hosted solutions. So here goes…

I’ve used many of the popular shared, and not shared, hosting solutions. But I’ve always come across the same issues. As my development skills improve, I find that I can only do less and less with what I have, when I rely on others for the environment in which I run my site.

Let’s say I need to increase the upload limit in your php.ini? NOPE!

Do I want to install git? Wait, I can just install that from the command line?! What else does my unix user have permissions to do? …or other users for that matter…

Wait, you aren’t running PHP 5? Ok, I get that it’s complicated to upgrade PHP for existing users because you don’t want to break their sites, but, c’mon! I’m a new user!!!

Through a mixture of horror and frustration I decided to look into alternatives. But, to be honest, I was afraid of running and configuring a server of my very own.

For my first attempt I tried SUSE linux; because that’s what was being used at the office at time. But I really couldn’t keep it running. It just kept restarting. I didn’t know enough then to be able to say even now why that happened.

But I persisted experimenting, and with some shameless begging, we switched to CentOS in the office. I took that opportunity to build my own development environment locally. Around the time I started feeling comfortable with playing around with server configuration I discovered DigitalOcean.

After playing with AWS for a bit, moving to DO felt like moving to Apple from Windows XP. I had to give up a few controls that I didn’t feel too strong about, in exchange I didn’t have to think too much about settings I don’t care about. The server just worked. No extra services were needed and I knew the cost.

So to answer the question of why I wrangle my own server?

First, I like understanding the technologies upon which I am relying. The more you understand, the better performance you can pull out of something — “full-stack development” should include the Linux/Apache (or Nginx) part of the stack.

Second, I you’re building an plugin or theme for distribution you need to make sure it will be compatible, and you can’t really rely on the masses to be running any advanced server setups. So don’t bother with anonymous PHP functions. But if you’re building something for yourself, you should be able to enjoy the benefits of PHP 5.5 and more.

I’m currently working on version 3 of my server. I just moved from CentOS with a traditional Apache, PHP setup to Ubuntu with Nginx and PHP-FPM.

Why?

Well, first of all, all the cool kids are doing it.

More importantly, Apache slows down under heavy load, because of the need to spawn new processes, while Nginx was designed specifically to handle high traffic sites. In addition, PHP-FPM runs along side the webserver, instead of on top — like a traditional setup with apache — which reduces the recourses available.

This is a great example of the first reason I stated above. I saw a relatively easy way to improve my site’s performance. Since I’m in control, I can do it.


    Setting up an Ubuntu Desktop LAMP development server

    So you’ve inherited a WordPress site and you want to start developing for it. But you don’t want to go commando on the production site. Smart.

    How do you set up a local development environment?

    In this tutorial I’ll walk you through setting up a simple dev environment on Ubuntu desktop.

    WordPress typically runs off a LAMP stack. Not always, but most sites do. So that’s what we’ll set up.

    LAMP stands for:
    L inux – the operating system. In this case Ubuntu.
    A pache – the web server. Sometimes Nginx is used.
    M ySQL – the database.
    P HP – the server-side scripting language.

    The first step is to make sure you’re completely up to date.

    So let’s open up the terminal and run:

    sudo apt-get update

    Now we install the lamp server, run:

    sudo apt-get install lamp-server^

    Since Ubuntu 10 there’s this. Pretty easy, right?

    Type your password. Agree to the packages it’ll install. This will install ALL of the modules and packages you’ll need to run a web server locally.

    You’ll get a prompt to set a password for the root user for MySQL. Even though this is local, it’s best to keep to best practices, so don’t just press enter.

    That was ridiculously easy. Let’s test that by going to http://localhost/ in the browser. You should get a success apache screen.

    Let’s test PHP:

    sudo touch /var/www/html/info.php

    sudo nano /var/www/html/info.php

    type:

    <?php phpinfo();

    Ctrl C to exit.

    Then navigate to: http://localhost/info.php

    You should see the phpinfo screen.

    Also to keep with best practices, once that’s done run:

    sudo /usr/bin/mysql_secure_installation

    Remember that password we just set? You’ll need it now.
    No, you don’t need to change the password you just set.
    Say yes to the rest.

    Next we’ll need a database for WordPress to use. So type:

    mysql -u root -p

    Enter the password you set for root.

    Then create the database:

    create database wordpress;

    Then: exit

    Now we’re almost ready to install WordPress, we just have to deal with some permissions, so we can code comfortably.

    First, we’ll need to grant apache access to the html directory:

    sudo chown -R www-data:www-data /var/www/.

    Then we need to add ourselves to apache’s group:

    sudo usermod -a -G www-data YOURUSERNAME

    In order for that to take effect, you’ll have to log out and log back in.

    Now, we still can’t do anything in the html directory. That’s because we need to grant read/write/execute permissions for the apache group.

    sudo chmod -R 775 /var/www/.

    And Viola! WordPress time!

    Download: http://wordpress.org/latest.zip

    Let’s extract that to: /var/www/html/

    If you go to http://localhost/wordpress in your browser you should see the installation wizard.

    Click “Create a Configuration File” then “Let’s go!”

    The “Database Name” keep as ‘wordpress’, we just created that.
    “User Name” is ‘root’.
    “Password” is whatever you set for that.
    “Database Host” keep as ‘localhost’.

    Usually it’s not a good practice to keep the root user for running your applications, but for expediency we’ll keep it for now.

    “Submit”

    Aaannnd this: “Sorry, but I can’t write the wp-config.php file.”

    No problem. Click back in your browser, and go back to the terminal. Run:

    sudo chown -R www-data:www-data /var/www/.

    Again, and we’ll resubmit. Because we copied the WordPress files apache didn’t own that directory. You should be good to go now.

    “Run the Install”

    Fill out the form. And we can log in now!

    Congratulations! You now have your own development server running off your Ubuntu desktop.

    Let’s test that out… Yup, all seems to be working just fine.

    This site you can now develop for and break with impunity.


      Announcing IlanaCMyer.com

      ilanacmyer.com

      I’m proud to announce the launch of the author site of my talented wife: Ilana C. Myer.

      The art is by the very talented Galen Dara; the site design and development is my own. I wanted to take a few words and go a bit into my thoughts behind that design.

      The design: The primary purpose of the site is for Ilana to share updates and insights about her upcoming book.

      Towards that goal, it was important for me was to have a beautiful readable type. I used Calluna. It has an elegant feel. What struck me about it was the elegance of the serifs, and how it balanced that detail with a clean reading experience. 

      To balance out the serif body type I used Lato I believe that it was intended to be used as a thinner sans-serif. However, for contrast I used it’s thickest weight. I think it still works nicely.

      For Ilana’s name, at the top, we used Neue Hammer Unziale. It’s Celtic look was apropos due to the influences of the book. (You’ll just have to read it to find out more.)

      Having commissioned the art, we wanted to put it front-and-center. I felt it would immediately place the visitor into the world of the book. Thankfully, the visual trend now is leaning towards full screen hero images.

      The transparent heading before the posts on the homepage is to keep the visitor inside that world, always reminding them of the art. The art can be seen in full by scrolling all the way to the bottom.

      The page heading recluses itself as the visitor scrolls down to bring the visitor into the text, reducing the distraction of the art.

      The tech: I used underscores as a base theme and set up a grunt watch to compile my LESS and JS files. Nothing too fancy; not much needed for a blog.


        We Choose

        Today 45 years ago one of our species landing on another world. For a moment all mankind were bound together by accomplishment and ingenuity. We looked up at the heavens and for the first time, we knew one of us was looking back. Oh the force of the human spirit.

        “There is no strife, no prejudice, no national conflict in outer space as yet. Its hazards are hostile to us all. Its conquest deserves the best of all mankind, and its opportunity for peaceful cooperation may never come again. But why, some say, the moon? Why choose this as our goal? And they may well ask why climb the highest mountain? Why, 35 years ago, fly the Atlantic? Why does Rice play Texas?

        We choose to go to the moon. We choose to go to the moon… we choose to go to the moon in this decade and do the other things, not because they are easy, but because they are hard, because that goal will serve to organize and measure the best of our energies and skills, because that challenge is one that we are willing to accept, one we are unwilling to postpone, and one which we intend to win, and the others, too.”

        When something seems too hard, I look up at the sky and think of these words. We have so many challenges ahead of us, but the force of that idea.

        This is who we are.

        We set foot on the Moon.

        Goddammit. We can find a way to live with respect for one another and stop killing each other. Goddammit. We can find a way to conquer poverty and plague. Goddammit. We can find a way to live with all the comforts of modern society without burning away our future and our fellow inhabitants of this beautiful planet that gave birth to us.

        We set foot on the Moon.


          Demystifying the WordPress Plugin

          I asked one of the guys on my team to build a WordPress plugin, he balked. I realized that he just didn’t get how easy it is. So I thought I’d dedicate some time to dispelling the myth that plugins are complicated to write. “Plugin” sounds formidable. But really, a plugin is a file in the plugins directory with a comment. That’s it. To build your first plugin create a file, name it whatever you like, and place the following code at the top:

          <?php
          /**
          * Plugin Name: Name Of The Plugin
          * Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
          * Description: A brief description of the Plugin.
          * Version: The Plugin's Version Number, e.g.: 1.0
          * Author: Name Of The Plugin Author
          * Author URI: http://URI_Of_The_Plugin_Author
          * License: A "Slug" license name e.g. GPL2
          */
          

          Upload that file to "YOUR-SITE-ROOT/wp-content/plugins/" and voilà!

          Screenshot 2014-06-29 15.55.47

          Go to your plugins menu and you’ll see your shiny new plugin there.

          What do you put in there besides the comment? Typically, anything you’d put in your theme’s functions.php file. Unlike with the functions.php file which runs everything you put in it, where plugins are concerned you can decide whether to “activate” the code or not.

          Here’s a great post with 25+ potential plugins. Let’s try #3 (Don’t forget to change the plugin’s name):

          <?php
          /**
          * Plugin Name: Remove WordPress Version Number
          * Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
          * Description: A brief description of the Plugin.
          * Version: The Plugin&#8217;s Version Number, e.g.: 1.0
          * Author: Name Of The Plugin Author
          * Author URI: http://URI_Of_The_Plugin_Author
          * License: A &#8220;Slug&#8221; license name e.g. GPL2
          */
          function wpbeginner_remove_version() {
            return &#8221;;
          }
          add_filter(&#8216;the_generator&#8217;, &#8216;wpbeginner_remove_version&#8217;);
          

          See! Wasn’t that easy?

          Typically, you’ll want to add to your functions.php file code that is necessary for your theme to run, and make plugins for all functionality that is separate from the theme.

          There’s a lot more to say about plugins, the example above is rather simple, but it should get you on your way.

           


            Labor Surplus is a Resource to be Tapped, Not a Liability to Mitigate

            “While those ancestral Maori who first colonized the Chathams may have been farmers, Maori tropical crops could not grow in the Chathams’ cold climate, and the colonists had no alternative except to revert to being hunter-gatherers. Since as hunter-gatherers they did not produce crop surpluses available for redistribution or storage, they could not support and feed nonhunting craft specialists, armies, bureaucrats, and chiefs.”

            - Diamond, Jared. “Guns Germs And Steel

            Technology is such a blessing. As production becomes more efficient, fewer people need to work in order feed the rest.

            While in the past, technology has created more jobs because of the efficiency it created, given Moore’s law, as the efficiency of our systems grow exponentially, I believe that it may threaten jobs, if we aren’t able to keep up with the progress.

            But what this really is, is the opposite of the Chathams’ experience. There are “crop surpluses” which means that more people are available to discover, build, learn and develop.

            All we need to do is invest in empowering people to profit from their creativity. If we invest intelligently in our future, we’re in for quite an exciting ride of creative invention and innovation beyond our wildest dreams.


              SharePulse Relaunched

              I am happy to announce the relaunch of SharePulse. (From the site)

              Relying on hit counts simply does not reflect the impact of your posts. SharePulse finds and ranks your site’s posts that have the greatest social impact. The stats are gathered from Twitter, LinkedIn, Facebook as well as your own site’s most commented posts measuring actual engagement. SharePulse lets you display these posts in your site’s sidebar showing off your posts which have had the greatest social impact over the past day, week, month year or for all time. Each post is displayed with the total number of tweets, shares and comments.

              This version was rebuilt from the ground up. It now uses more reliable stat counters and was built lean and with stability in mind. While it’s version 3, it is in alpha. It’s stable enough for a production server, but I decided to tag it as “incomplete” because of all the features I have planned.

              So please, use it on your site, enjoy it! And I’d love your feedback.


                Database Indices

                I recently had the pleasure of indexing our company’s sites’ tables. The  custom CMS I inherited has some really brilliant code, but it also has quite a large amount of idiotic code blocks as well. In this case, the database was not thought out as best it could have.

                I was able to reduce some ridiculously long queries from 10 seconds down to 2 seconds with a few well placed indices. While 2 seconds isn’t anything to brag about. It’s quite an improvement. A database index is a lookup table that is created to help query information more quickly.

                Before jumping in. One thing to note about indices is that there is an expense. If you go ahead and index your entire table it will likely take longer to run that query than a non-indexed table. So you have to be discerning about what you index.

                The rule of thumb is, anything that alters the query, typically a WHERE clause or ORDER or GROUP, is a potential candidate for an index. For me, the rest of the process was trial and error, I went through all the potential candidates in my longest queries and tried various combinations until I came up with the quickest time for each query. There may be an algorithm for calculating the best columns to index. But this worked.

                phpMyAdmin doesn’t make it easy to find your indices.

                ( Don’t get any funny ideas, this is just a typical WordPress install. )

                1) Open a table, click “Structure” at the top.

                where are you?

                2) At the bottom of the page is a tiny link that says “Indexes”. You can manage existing indices from here.

                oh there you are

                3) To add an index check to see if there’s a “More” menu on the column you’d like to index…

                and how do I do that?

                Enjoy!


                  Why I use Bootstrap, and what I get from it

                  I previously wrote about the the Bootstrap front-end framework. In a nutshell my thoughts then were, it’s a useful tool but if something goes wrong, it’ll be a pain to troubleshoot.

                  What I thought then still remains true, if you need to work outside their box, you’ll have a tough time. However, since I first wrote about it, it’s gotten quite a bit more polished.

                  My gripes

                  When they made the jump from version 2.3 to 3 I was not happy. It’s quite a bit more polished now and naming conventions make more sense, but one really can’t upgrade a bootstrap 2.x based site to 3 with ease.

                  Note to all framework developers: if you’re planning on doing such a drastic change, please, please, please document your changes carefully so that you’re not wasting the time of the people for whom you are building your code for? Even better? Write a conversion script.

                  Also, I was not happy that they dropped IE7 support. It would be nice to have some graceful degradation in place, especially since it is a framework. I work with the banking industry, who notoriously refuse to upgrade their systems. Which is plain dumb and I have a lot to say about that; but, that’s for another post.

                  What I Love

                  Pain aside, it’s sweet to work with.

                  It is now flat, which is really nice for a framework. It’s not a good idea to include tons of extra code to add shading and depth to an element that you will go ahead and overwrite. Start slim, build from there.

                  The grid system is fully responsive, which was nicely executed. I’m also please that they moved away from the 8 column grid, 12 is much more flexible.

                  Version 3 moved from sprites to glyphs in font format, it’s time for sprites to die.

                  ~=~=~=~=~=~=~=~=~=~

                  In today’s world it’s a no-brainer to use a framework, at least for prototyping. Whether, the framework is really just your own snippets you’ve collected, or it’s a framework that has a team dedicated to developing and improving it. Front-end frameworks really cut down the development time, and Bootstrap is solid.

                  To resolve my initial reservations with using a framework, when I’m assigning projects to my team I make sure to pepper the tasks with some vanilla CSS and JS. It’s good to keep on one’s toes.


                    To the FCC: Thoughts on Net Neutrality

                    The internet is a great equalizer. It is the foundation upon which we share all our communication and knowledge, like the printing press. Giving priority access to some over others is the equivalent of constraining access to the alphabet or language. You’re damning the less fortunate to remain illiterate.

                    Are you upset as well? Here’s something you can do. 

                    Here’s something else you can do.