Monthly Archives: October 2013

Buy Scripts, Applications and Web Tools at Jafty.com/products

Yes, I finally am starting to sell some of my products that I have been developing for over 12 years now. I am only putting together the best tools I have made and remaking certain ones I find the most useful for sale on my website, Jafty.com/products

Types of Products for sale on Jafty.com/products

  • Email Marketing tools
  • Domain name tools
  • DNS tools
  • Server administration tools
  • webmaster tools
  • PHP tools
  • Customized tools for business
  • Have me build one custom for you if you don't see what you need

CLICK HERE TO VISIT Jafty.com/products/ and see what's listed for sale now. However, I do not have them all listed yet, so drop me an email or give me a phone call at 330-903-6074 or 330-417-3617 to find out how I can help you.

jafty0

Want to learn more about SEO? Check out these relative books from Amazon:

Install WordPress from the Command Prompt

Today I was thinking to myself, "Why do I have to upload all these files via FTP each time I install WordPress?". I think this because I install WordPress probably close to a hundred times a year being a web developer who specializes in WordPress. Therefore, I decided to provide this tutorial on how to install WordPress from the Linux command line for those of you with Linux servers. Windows servers will have a very similar method, so this mostly applies there as well. I did this on an Amazon Linux AMI in an EC2 instance, but the instructions are almost the same for any Linux web server. Let's get started!

Installing WordPress from the command line is a lot faster than downloading it, unzipping it and then uploading it using an FTP client such as FileZilla. Here is how to install WordPress on an Amazon Linux web server using an EC2 instance as I am in this example. You can make minor adjustments to the process for other servers. Here are the steps:

  1. Open up a command prompt - I use Putty for this. In putty, you enter the IP address or domain name of the server first. If you are using Amazon EC2, you will also have to point it to the public key file by clicking on SSH/Auth/browse and then selecting the location of your .ppk key file. After entering the IP or domain and providing a key file location if needed, click on "open" to open a command prompt and enter a username and password if required to get to a command prompt.
  2. Once you have your command prompt,  go to your web root directory which should be something like var/www/html and you can then type:    wget http://wordpress.org/latest.tar.gz from the command prompt to download WordPress from thier main repository.
  3. To untar, type:   tar xvzf latest.tar.gz -C /var/www/html   where /var/www/html should be replaced with your web root or where you want WordPress to reside in your file system. Or if you are in the correct directory where you want it you can simply use: tar xfz latest.tar.gz 
  4. WordPress will now be in /var/www/html/wordpress. If you don't want to access http://yourdomain.com/wordpress and want WordPress at http://yourdomain.com instead, move it there by typing the following at the command line:
    mv /var/www/html/wordpress/* /var/www/html

Now you will have WordPress where you want it. You may have to play with permissions on some servers to get it to work right but this tutorial should have gotten you far enough to finish the job now. Good luck.

php composer dump-autoload returns error

When you open a route after doing work on your Laravel 4 application, you have to clear the autoload. If when you run:

php composer dump-autoload

...it returns error:

could not open input file: composer.

Then this is what I did to get around it:

  1. I was using xampp and localhost on Windows 7 so I opened a command prompt in Windows, not Xampp and went to the Laravel application directory with cd desktop/xampp/appname, then I found that php composer dump-autoload returns an error still, but the following command without php in front of it works: composer dump-autoload returns error
  2. Try opening your route again now and it should work.

I think the reason for this is the location of the php installation that composer uses, so that's your tip if you want to investigate further. For example instead of php, you may need  a complete path. Just guessing from something I remember reading folks, so don't hold me to this. If anyone wants to comment on it that would be helpful.

 

 

Cloning a Laravel Project

Today, I am making a copy of a Laravel project. I a doing it to have a testing and development environment that is separate from my main Laravel application so I can tinker with it without messing up the main project. Anyway, its a good idea, so here is how I did it on my localhost server. The process will be nearly the same on any server though.

  1. copy your main project folder and give it a new name so you can keep it in the same directory as your original project. By "project folder", I am referring to your entire Laravel project, so your project folder could be named anything (whatever you decided to call it), so it will be different for everyone. The main project folder should contain a "vendor" directory, an "app" directory, a "public" directory(unless you took it out and placed pubic files in the main project folder as I have done before) and there will be some files also, but I am just telling you basically what folders should be in a project to be clear on what I mean when I say we are cloning a project. For example, if you project directory was named "Project"  make copy that folder and place the copy in the same directory as Project and name it "Project2" or anything other than it's original name. I will refer to the original project folder as "Project" and the copy as "Project2" in this tutorial. If you are on the local server as I am, just right click on the Project folder and copy and paste it then rename it to "Project2". If you are on a live web server you will probably be using a command prompt and would do something like "cp Project Project2" from the command line while in the working directory that contains the project folder.
  2. Now add a new database for your cloned project. If the project you are cloning already has data in the database, then you will want to dump it to a sql dump file, otherwise just create a new empty database and give it a new name. I named mine. if you have a localhost set up like mine, you'd go to http://localhost/phpmyadmin/ and clone the database which I shouldn't have to explain here as it is something you should know if you are using Laravel. If you need help, Google Mysql/phpmyadmin tutorials along with the server type and you'll find what you need.

So far that did it. Just one main step? Yea, it looks like it(but then I quickly realized I would prefer to run the clone off of it's own database, so I added step 2 above), I tested it by going to http://localhost/Project2/ and it works, but if I run into problems later on, I will add notes to this tutorial on any further actions that may be required as I come across any. I may not because everything seems to work already!

Installing Twitter Bootstrap in Laravel 4

Installing Twitter's Bootstrap with Laravel 4 using composer is as easy as changing the require line in composer.json to look like the following by adding the bootstrap declaration to it:

"require": {
        "laravel/framework": "4.0.*",
        "twbs/bootstrap": "3.0"
    },

Summary

That's all there is to it. Read my OTHER LARAVEL TUTORIALS BY CLICKING HERE.

Laravel Views Tutorial

This is a brief tutorial on how to create Views with Laravel 4. Views make up the "V" in the MVC or Model View Controller.

View File Formats

View files will have a .php file extension or a .blade.php file extension if you use the Blade templating engine which I'll explain later in this tutorial. All views live in app/views and sub-directories you can create in app/views.

A Basic View Example

A very basic view could consist of some HTML and a variable such as in the following example file we will name welcome.php and it goes in app/views/. Here is the syntax:

<html>
    <body>
        <h1>Welcome <?php echo $name; ?></h1>
    </body>
</html>

Passing Data to a View

You should notice the PHP echo statement in the view code. We can now display the view in a browser and  pass a name to the view's $name variable like this:

Route::get('welcome', function()
{
    return View::make('welcome', array('name' => 'Ian'));
});

Now when you visit example.com/yourapp/welcome, you will see a welcome message with the name you passed to your view in the route. That's a very basic view implementation. Next we will get a little more complicated.

Share Data with all Views

If you want a piece of data to be available to all views in your application, simply declare it in routes.php like this:

View::share('name', 'Adam');

Then anytime the name variable is called in a view with $name, the name you set, Adam in this case, will be displayed. This could be handy for a logged in user for example.

Views and Templates

Very often, you will want to use a template with a View and Laravel has incorporated the Blade Templating Engine just for that purpose.

BLADE Templates

The Blade Templating engine is driven by sections and template inheritance. All view files that use Blade will have the .blade.php file extension telling Laravel that the file is using the Blade template engine. Blade Views are also held in the app/views folder of your application and sub-directories of app/views.

Three Steps to Developing a Blade Template View

Step 1:

To help you understand both Sections and Inheritance, we will look at a Blade template view as an example. First, let's add a directory to app/views and call it layouts. So we now have app/views/layouts as a folder to keep our Blade layout templates. Next, create a new file called app/views/layouts/master.blade.php. This will be our master layout we may use for several pages, so it will be flexible. Copy the following lines of code into your master.blade.php file:

<html>
<body>
<nav>
@section('topnav')
<a href="/">Home</a>
<a href="/about">About</a>
<a href="/contact">Contact</a>
@show
</nav>

<div>
@yield('content')
</div>

<div>
@section('sidebar')
Master sidebar content in all sidebars....<br />
@show
</div>

<div>
@section('footer')
Master footer content that gets overwritten so you won't see this in this example when viewing the "aview" page in a browser....<br />
@show
</div>

</body>
</html>

Step 2:

Now make another file and put this on directly in app/views and call it app/views/anypage.blade.php and add this:

@extends('layouts.master')
 
@section('content')
  <p>This will be overwrite</p>
@stop
 
@section('sidebar')
  @parent
   
  <a href="#">Section specific links will get appended...</a>
@stop

 

Step 3:

Now step 3 is to add our route to routes.php. Copy the following to the end of your routes.php file:

Route::get('aview', function()
{
    return View::make('anypage');
});

3 Steps Explained

  1. In step one we made our master.blade.php template file which is our master layout for several pages in our application. We used nav and div containers. nav could be a div, they act the same. You will want to add CSS style classes to these in your actual application. We left CSS out for simplicity of learning just what you need to know. It is assumed you know basic HTML, PHP and CSS if you are learning a template engine and a PHP framework. In master.blade.php we used a few different methods of displaying content for learning purposes. First we created a section with: @section('topnav') then we added some content that will show on all pages in the top nav. We closed the section with @show. @show is the common method for closing a section in a layout file. We will use something else for closing sections in views as you'll see below. Next we showed how to use yield to "yield" the content directly from the view, so a yield statement in a layout file is simply a placeholder for content which may be defined in our view as you'll see in step 2. After the yield example is another section example. This section, for the sidebar in our example, is designed to be static content that won't change in most pages, but could be overridden if necessary. FInally in our footer section we demonstrate content that is intended to be overwritten, but if it wasn't, you would see the default content that is there. You'll see how overwriting is done in the next step.
  2. Step 2 is where we define the view which extends the master template from step 1. Here you can see that first we tell Laravel that we are extending the master layout with extends('layouts.master'). Then we skip the nav because we are not changing anything there. That's why the first thing you see after extending the master layout is the content section that is declared with section('content') then followed by some HTML and ends with @stop. Notice the use of @stop in our view instead of @show like we used in our layout file to end a section. The main difference between @stop and @show is that @show yields the content immediately. They both end the session, but @show ends and shows the content at the same time. Next, you should notice the sidebar section has @parent in it. @parent indicates to Laravel's Blade that we intend to append to the content in the sidebar. Therefore whatever HTML is after @parent and before @stop will show up after the default content in the layout file from step 1. After that, I go on to demonstrate what happens by defualt in a section declared in a view without using @parent. WIthout using @parent, the default behavior of a section in a view when extending a layout is to overwrite the existing layout's content as you will see happen if you run the route in the next step, step 3.
  3. Finally in step 3, we declare our route in routes.php. This is simple and you've probably done it a hundred times by now if you are this far along in learning Laravel already, but just to be sure, all you do is include the file name of the file in our app/views folder from step 2 above without the .blade.php file extension in your make declaration when coding the route. In this case, we named our route "aview", so we get to the page by visiting example.com/appname/aview in a browser. Then the file name we put in the app/views folder was anypage.blade.php, so we used return View::make('anypage'); in our route next.

Summary

That's basically all there is to it. If you can practice and master those three steps you are well on your way to creating pages with Laravel and Blade templates. Good luck.

You can see all of my Laravel tutorials by CLICKING HERE.

 

Laravel Quickies

Laravel Quickies is a quick tutorial I developed to help you remember how to do the major coding steps for the Laravel MVC PHP framework. If you don't have an idea of how to do the things in this tutorial yet, you should probably read the more detailed tutorials I've written on each of the subjects below. This is meant just as a quick reference guide for those that already know the basics but need a quick refresher course in the high level steps to do things such as create a route, model, view or migration for example.

Laravel Quick Start Examples

Routes:

Enter the following code into routes.php to create a simple route:

Route::get('test', function(){

return('<h1>Laravel Route Example</h1>Ian L. of Jafty.com created this simple Laravel route test.');

});

visit the full Laravel routes tutorial here: http://jafty.com/blog/laravel-routes/

Controllers:

Add the following in a new file within the app/controllers directory to create a new controller:

class yourClass extends BaseController {

public function yourFunction() {

return "<h1>This is what gets output to the web page when the test route is visited by a user in this basic Controller Example</>";

}

The above controller would need the following route set up in routes.php to make it work:

Route::get('test', 'yourClass@yourFunction');

Finally, after you create a new controller, you always need to flush the autoload contents before the new controller will work, so do so by opening your command prompt that you use composer from and type:

composer dump-autoload

More Laravel quickies coming soon! For now, you can view all of my Laravel tutorials and posts by visiting the Laravel Category of my blog HERE!

Laravel Validation with Ardent Tutorial

If you are already looking into Laravel Validating, you should already know a bit about Laravel. So, you should be aware that Laravel is a MVC or Model View Controller PHP framework. Validation should occur in the Model part of the Model, View, Controller trio because the Model is where the business or database logic is kept. In this Laravel validation tutorial, we are going to discover how to do basic validation using the Ardent package.

Installing Ardent

The first thing we can do is install Ardent. To do this, we ned to open up the json file named composer.json which should be in your application root folder. We need to add the following code to the end of this file:
  "require": {
    "laravelbook/ardent": "dev-master"
  }
You wll want to add this near the bottom, but before the last closing bracket(}) so the last several lines of composer.json should look like this after adding the above code:

    "minimum-stability": "dev",

  "require": {
    "laravelbook/ardent": "dev-master"
  }

}

Save the composer.json file then open up a terminal window to your server and run the following command prompt command:

composer update

That will cause your application to update and upload the dependencies for Ardent since you required it in the composer.json file. The command may take a while to finish from the command line, so wait until you get your command prompt back so you know it is finished. You will see several removing, installing and downloading lines in the terminal window while it is working.

After the composer update command is finished, you may notice that several folders and files were updated in your application. Also it should have added a folder named laravelbook if you didn't already have it and inside that folder you will find the ardent directory. I mention this just so you can confirm it worked if you want to.

Validating with Ardent

Validating with Ardent is done in the Model as I mentioned above. Let's look at a very basic User.php model file as an example of how to use Ardent to validate input from the user.

Here's the default users.php file minus comments:

use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface {

    protected $table = 'users';
    protected $hidden = array('password');
    public function getAuthIdentifier()  {
        return $this->getKey();
    }

    public function getAuthPassword() {
        return $this->password;
    }

    public function getReminderEmail() {
        return $this->email;
    }

}

You may have noticed, no validation occurs in the default file, but with Ardent, we can add some. Here is how to transform your users.php file to validate with Ardent:

  1. Add the following line of code towards the top of the file where you see the other two "use" declarations, so you can add the following just under where it says "use Illumincate....":
    use LaravelBook\Ardent\Ardent;
  2. Change the extends line just under the line we added in step 1 from:  class User extends Eloquent implements UserInterface, RemindableInterface {             to:
    class User extends Ardent implements UserInterface, RemindableInterface {
  3. Just before the } bracket that closes the User class at the bottom of the file add in the following  Ardent validation rules to make your model self-validating, meaning that you won't have to do anything, the model will simply reject invalid input and accept valid imput. So if a user trys to save something that doesn't pass validation, the save method will return false and nothing will be saved, otherwise if it validates, it will save the data and create the user in this case. Here is a validation rule set example to add to the end of your User class before the closing bracket:
     // Ardent validation rules:
    public static $rules = array(
      'email' => 'required|email',
      'password' => 'required|alpha_num|min:6|confirmed',
      'password_confirmation' => 'required|alpha_num|min:6',
    );
  4. Not all data needs to be saved, so we need to tell Laravel to purge the redundant data. In this case redundant data would be the password confirmation. Add the following line of code just below your validation rules to purge that data:
    public $autoPurgeRedundantAttributes = true;
  5. Save the User.php file then open your applications routes.php file in the main folder. Add the following route to test the validation changes you made to your User model:                                                     //test Ardent validation process:
    Route::get('/user_test', function() {
      $user = new User;
      $user->email = 'linian11@yahoo.com';
      $user->password = 'mypassword';
      $user->password_confirmation = 'mypassword';
      var_dump($user->save());
    });

That's all the steps, now go to the route you created in the final step above and if the user validates and is saved, you will see this in your browswer window only:

bool(true)

Then you know it worked. if you don't see that or see a false instead, go back and check your code.

Summary

I hope this Laravel Validation tutorial has helped you understand how to install and user Ardent so that you can make self-validating models from now on. You may want to expand on this validation technique to make it more user friendly, but this should at least get you pointed in the correct direction and get you started.

Starting with Laravel

Learning a new framework can be frustrating. Laravel is probably one of the more pleasant frameworks to learn, but if you are anything like me, you still dread taking on a new framework and you may be thinking, "Why can't I just use plain PHP?", well, you can! That's true. There is nothing stopping you, but PHP frameworks were designed to be time-savers and to make coding in PHP easier. Now, that said, there are exceptions to the rule as always. The main and most important exception being this:  You don't need a framework if you do not use PHP often enough. So ask yourself, "Do I use PHP daily or at least more than once a week?" if you answered yourself "yes" you may have some psychological issues, but none-the-less, by all means, pick and learn a good PHP framework and stick with it. No need to learn multiple PHP frameworks unless you are a real nerd, but one good PHP framework should suffice the average coder like myself. I have learned a  few out of necessity because certain clients want to use certain frameworks, so there are always reasons why you would learn more than one obviously. That brings us to exactly why I learned the Laravel framework. I did it because a client wanted me to use it, but I got to admit, it is probably the first PHP framework, I have tried out that I think I may actually keep on using during my career as a PHP developer. Okay, enough chit chat! Let's get started.

Makeing Laravel work in Root

Okay, I wasn't sure what to call this tutorial, I could of called it Laravel Pretty URLs or Getting Rid Of Public, but I didn't, so Making Laravel Work in Root will have to do and for SEO purposes, I already mentioned the other titles, ha ha. The gist of this tutorial is that it will teach you how to change ugly stock Laravel URLs that look like:

http://kingadvrt.com/laravel/public/test

TO look like this:

http://kingadvrt.com/test

The first example URL is what my first public Laravel installation produced. I had to navigate to the project name, laravel, then to the public folder and finally to the route I named in routes.php. Not very nice at all if you ask me or my client, in this case, kingadvrt.com. So, how do II make the king of advertising happy? Yes! Pretty URLs of course! Here is how it's done with Laravel:

Method 1:

you will have to edit your virtual host declaration in your server's config file. This is often in either httpd.conf or a file included in the httpd.conf file such as vhosts.conf or something similar. If you are not sure, search the include files and directories from your httpd.conf file which is normally in etc/httpd/conf/ directory or as in my case, I had a client with a public server that didn't allow access so I had to use a different solution. But if you are lucky enough to have a VPS or other server with httpd.conf access, simply edit the document root to that of your new public directory.

Method 2:

This may not be the preferred method, but it works if you would like to have a directory structure like:

http://kingadvrt.com/app/test

where everything is inside the app directory or whaever you want to call it. I am not referring to thte existing app directory in laravel, but a new one you can create to hold app, vendor, bootstrap, etc. So, what you do is upload all your Laravel files to a folder named app or whatever you want to call it that is inside of your web root directory so you have something like example.com/yourfolder to hold Laravel files. Then you move all the files from public down one level to yourfolder in this example. Then you have to edit the index.php file paths. Open index.php and replace any occurences of ../ with just / and you are done.

 

Be sure to visit Jafty.com to view my portfolio and see the web development services I offer! You an also email me at linian11@yahoo.com if you need anything.

Installing Laravel Without Composer

Some people don't realize that Composer isn't required to use Laravel. It is nice to have however and should be used when ever possible. If you have no reason for excluding Composer, see my original tutorial on Installing Laravel with Composer HERE. For those of you that cannot use composer because your hosting provider doesn't allow it or because you want only use composer on your primary developing environment, this article is for you. In this article, I am using Xampp, but the basics will apply to any basic web server.

Setting Up a Basic Working Environment For Laravel

If you are just experimenting or need a secondary development environment, then I suggest cloning your original Xampp server and installing Laravel there. Follow my tutorial on Cloning Xampp by CLICKING HERE to learn how to clone Xampp to have two working copies of your development environment for testing and developing more applications. If you already have a copy of Xampp or another web server working where you want to install Laravel, then don't worry about this part of the tutorial. It is over now anyway. Ha ha.

Download Laravel

If you have downloaded Laravel before, you can use those files, otherwise download a fresh copy BY CLICKING HERE to get it from github.com or just go to http://laravel.com/. If you go to Laravel.com, click on the five minute quick start button and you will see that they instruct you to use composer, but under that they provide a link to download from github which is what you want to do in this case. I provided both links because Laravel.com has general information that is useful for beginners, but you could just download from github if you are in a hurry and just want to follow this tutorial to get up and running.

Here's the Gotcha!

You have to run composer once! I know, I said we were installing Laravel without composer, but what I meant was for cases where you cannot install composer like production shared server environments. This is basically a work-around for those that can not install Composer on a client's server or on their own. You can however almost always install Composer on your Local Machine. I see no reason why anyone couldn't! So go ahead and run composer. After you do so on your local machine, you will have all the dependencies necessary downloaded into your Laravel installation and you can now move it to a server that can not or does not, for whatever reason, use Composer. Now, if you have already installed Laravel on your original Xampp server and are working on a clone now, you can move a project over without composer just by moving the Laravel directories over to the htdocs folder of your new server, so see, we are installing Laravel without Composer after all! I told you so!. The "Gotcha" is that you do have to run Composer somewhere at least one time to get all the dependencies required to run Laravel. So, if you can't do it on the production server, do it on your localhost and upload the entire working Laravel installation to your production machine when it's ready. I'll explain just how to do this later, so keep reading!

Running Composer from Localhost

So, as I mentioned, you all should be able to run Composer from your localhost, so go ahead and do that using your Xampp installation by opening up a terminal window from your Xampp control panel. Just go to the file, xampp-comtrol in your main Xampp folder and fire up your server if you have not already, then click on the "Shell" button to get a shell prompt.

Okay, before we install our Laravel dependencies, make sure you have yourself in order...or at least have your Laravel directory in order. I can't help you with you ha ha. So, if you installed Laravel from github.com as I suggested above, unzip the laravel-master.zip folder into your htdocs directory of xampp. Sadly it will be in a sub-folder like laravel-master/laravel-master and we probably don't want that, so just make a new folder in htdocs called "laravel" or whatever you want to call your project and open up the final laravel-master folder, the one with all the files and cut all the contents and paste them into your final project directory.

Now go back to your shell and type:

composer install

Type the above from the shell prompt to have Composer download the necessary dependencies and add them to your Laravel project. You will notice a new folder in your Laravel directory called "vendor" that is the results of running the composer install command, but be patient, depending on your internet service provider, it could take several minutes to complete. Watch your shell prompt, when it is done, it will let you know by returning your command prompt to you.

Test Laravel

To see if it worked, go to:

http://localhost/laravel/public/

If you named your project "laravel" as I suggested above, then that URL should now work, but if you named it something else, replace laravel with whatever you named your Laravel folder. If your efforts were a success, you should see a page like in the following screenshot I took while making this tutorial:

Snap 2013-10-08 at 16.07.01All is god if you see the above on your screen navigating to your Laravel public folder. If you see anything else, you have issues I suspect. Read on for help! There is a troubleshooting section below, trust me. It may be a ways down the page, but it is there, I promise.

 

Moving Laravel from localhost to a Live Web Server

Here comes the fun part! This is where you folks that don't want to or can't use Composer on your production server will thank me. This part was tricky for me the first time because I couldn't find a tutorial on it anywhere, which also in part inspired me to write out, so hopefully if you are reading this, you won't have the difficult time I did. Well, if you are the thanking type anyway. If not, don't worry about it, my feelings won't be hurt. I don't know you anyway. So, go to your nasty old public shared host and make a FTP connection to it. I like to use Filezilla for this. If you don't know how to connect to your web server with FTP, contact your host or Google it and get instructions. Most hosting support departments are prepared to answer such elementary questions as how to access your account using FTP, so don't be afraid to ask! Once you have established an FTP connection, make a new directory for your Laravel Project or upload the existing project from your local machine and use that. Here is all you are going to need to do to move your Laravel project from localhost to another web server:

  1. Go to your project on your local machine. If you don't have one and need one just for testing, create a simple route at least so you have something in your project to migrate to a new server for learning purposes. CLICK HERE to see my simple Laravel route tutorial to create a route if you don't already know how.

 

Troubleshooting, Help Me!

Here are some possible issues you may have when following this tutorial if you didn't follow every small detail to the letter:

  • Laravel may be configured wrong for your environment. When I wrote this tutorial, I assumed you were working on your localhost and that you used xampp installed on your local machine. That also assumes that your working directory is going to have http://localhost/ as it's root. If that isn't the case, you will need to set some configuration settings in your Laravel installation. Look in your app/config directory for clues as to how to resolve such issues. Also your database may need configured. Laravel, conveniently for some of us, comes set up for a local host install with default settings for Mysql which uses root user and no password by default out of the box, but if you have changed this, you will have to go into your database..php file and make changes. It is located in app/config/database.php, so go there and make the appropriate changes if necessary and try to start your project again. It should work now.
  • Apparently my directory paths are different and are causing issues when I moved my installation to a live web server! You can configure Laravel directory paths in  bootstrap/paths.php.
  • Where can I find more help, your tutorial sucks and I can't get my Laravel app working! Okay okay, jeez! give me a break here... go to laravel.com/docs and happy hunting. No need to be rude.

 

 

 

Cloning Xampp

Okay, today, I found a need for cloning my local Xampp web server. I simply wanted a second installation for testing certain applications separate from my main local development environment which has a lot of important material on it. So, how do I clone Xampp? I started by just trying to copy the entire directory, but when it told me it would take 14 minutes just to copy, a red flag went up. Then I realized, most of my files were in the htdocs directory because I have been putting websites there for development. Therefore, I decided to copy everything but htdocs and filezilla because I didn't want filezilla, you can copy it if you need it yourself. Here is how I cloned Xampp on my local Windows 7 desktop.

 

  1. Make a new folder on your desktop or wherever your original Xampp installation is and name it something else other than what your original Xampp installation is called. I named my folder xampp2.
  2. Open your original Xampp installation folder and copy all of the files and directories except the "htdocs" directory. If you want to clone all of the websites in your xampp server also, then of course you should copy htdocs as well, but some of the websites may not function properly on the cloned server if they were configured to run with the original installation of Xampp.
  3. When your files are finished copying to the xampp2 folder, open it and make a new htdocs directory if you didn't copy the old one over.
  4. Make a test index.php file with a simple php script to test your cloned server with something like <?php echo "if you see this, PHP works on your server..."; ?> in it.
  5. Open up the file xampp2/properties.ini in a text editor such as notepad or notepad++ for editing and do a case sensitive search and replace for xampp and replace every instance with xampp2 or whatever you named your clone's main folder.
  6. Open apache/httpd.conf and replace all occurrences of xampp with xampp2(or whatever you named your cloned xampp directory) except for the one in the line that reads: Include "conf/extra/httpd-xampp.conf", leave that one alone.
  7. Open up apache/extra/httpd-xampp.conf and change all but a couple instances of xampp with xampp2. Leave the secone xampp in the line" <Directory "C:/Users/ian/Desktop/xampp2/htdocs/xampp">" alone and leave th one that has "xamppsecurity" in it alone and also the one that has a pipe after it like: "xampp |", but change the rest to xampp2.
  8. Then open apache/extra/httpd-vhosts.conf and change the two xampp occurrences with xampp2 and save the file.
  9. Open apache/extra/httpd-autoindex.conf and replace both times you see xampp with xampp2 and save.
  10. Also, open apache/extra/httpd-dav.conf and replace all occurrences of lowercase xampp with xampp2.
  11. To be safe, also replace xampp with xampp2 in apache/extra/httpd-ssl.conf. If you are using HTTPS or SSL support for anything, then there is a little more you need to do which is beyond the scope of this tutorial, but suffice it to say that you will be replacing a lot more xampp occurrences because you will need to go in the ssl directories and do the same thing there. Most of you will not be using SSL especially on a local test or development server and if you are, you can probably figure out the changes on your own just from what you have read so far anyway.
  12. Now this step I had to learn the HARD WAY, so this will save you a huge headache if you do it now instead of after it is too late like I did the first time doing a clone of Xampp. You have to change all the occurrences of xampp with xampp2 inside the my.ini file located inside the xampp2/mysql/bin directory. Open xampp2mysql/bin/my.ini in notepad and search and replace lower case xampp with lower case xampp2 or you will have major issues. If you read this to late, and mess up the database on your original Xampp server, remember, you made a copy, so you may have a way out. Go get your copy in xampp2 before you mess it up and replace the entire data directory with the copy if you have to only.
  13. Now once you are sure both Xampp servers have their databases set up properly you can move on. Make sure by going into each, starting it and checking PHPMyAdmin to be sure. Then you can go into your xampp2/mysql folder and make a backup of the entire data directory just to be safe as it is always good to do when working with database tables. Copying the xampp2/mysql/data directory, will give you a backup of all your original Xampp tables before you go and mess anything up by accident or by misconfiguration as I did once(and it was a nite mare!). After you make a backup of the data directory, you can go into the xampp2/mysql/data folder and delete all your tables from the original xampp install except the following ones:  mysql, performance_schema, test, webauth and phpmyadmin. Those tables you should keep, the rest you can delete as long as you are not cloning all of the website in your Xampp server also.
  14. Navigate to the file xampp2/xampp-control.exe and start the Xampp control panel.
  15. Click on the start buttons for both Apache and Mysql in the Xampp control panel to fire up your cloned server. You will probably have to click a couple pop ups to allow the services through your firewall the first time you start each service.
  16. Once both Apache and Mysql are running, open your favorite web browser and type "localhost/" and see if it takes you to your test index.php page you created above in step 4. You should see the test text from your .php script if everything is working. If you have issues read below for troubleshooting. Remember, you should see just "This is output by PHP, so if you are seeing this, PHP is working on your server..." if you made your test php script as I suggested above.

Troubleshooting

Here are a few possible problems and fixes if you are having issues:

  • If your page didn't resolve at all, you may have tried to install your clone in the wrong directory. This tutorial assumes that you are installing your clone in the same directory that your original Xampp installation is in under a new name, so for example, if your original Xampp directory is yourname/Desktop/xampp, then your clone should be in yourname/Desktop/xampp2 or it is likely not to work.
  • If you go to localhost in your browser and get the Xampp slash page instead of your test script, then you missed one of the replacement xampp2 cases, so search through all the files and make sure you changed all the xampp directories to xampp2 and try again.
  • My xampp2 install won't open because of a blocked port! If this happens, sometimes Skype is the culprit. If you have skype open, close it and try to open Xampp again. If it works that was the problem and you can then start Skype after and Skype will open on a different port. If that wasn't the problem then you may have your original xampp install running at the same time, shut it down and try to open the clone again and it should work. Unfortunately you cannot run both at the same time.

 

Twitter Bootstrap Tutorial

This is a beginner's Bootstrap tutorial for those of you who are just starting out using Twitter Bootstrap.

What is Twitter Bootstrap?

Twitter Bootstrap, which I will refer to simply as Bootstrap from here on out, is a collection of JavaScript, CSS and images set up in an organized manner for web developers to enrich their programming interfaces with such as websites, online applications and user interfaces.

Things you  can do with Bootstrap include but are not limited to the following:

  • Forms
  • Navigation
  • Bread Crumbs
  • Tables
  • Responsive Designs
  • Icons
  • Tabs
  • Thumbnails
  • Progress Bars
  • Error Alerts
  • Modal Windows
  • Dropdowns
  • Pop Overs

Bootstrap Plugins

Bootstrap has a plethora of plugins that can be used to enhance your applications. Some of the plugins include:

  • Scrollspy - allows you to automatically update nav targets based on scroll position.
  • Carousel - creates content or image sliders.
  • Buttons - a plugin to help you easily create styled buttons.

 

Why Use Boostrap

Hopefully just from reading this far in this Bootstrap tutorial, you should already have reasons to use Bootstrap, but if you haven't ready enough to convince you yet, read on and also look at these before and after screenshots of the exact same HTML code with and without Boostrap:

Before:

b4

After:

aft

The before image above is without the Bootstrap CSS file linked to the HTML document and the after image is with the Boostrap CSS fle linked. See the difference Bootstrap makes to the look of a form? Pretty nice and easy if you ask me since all you have to do to make it work is link to the style sheet and include the proper class names in the form elements as in the following example code which produce the above images:

<!DOCTYPE html>  
<html lang="en">  
<head>  
<meta charset="utf-8">  
<title>Twitter Bootstrap Version2.0 horizontal form layout example</title>  
<meta name="description" content="Twitter Bootstrap Version2.0 horizontal form layout example from w3resource.com.">  
<link href="bootstrap/css/bootstrap.css" rel="stylesheet"> 
</head> 
<body> 
<form class="form-horizontal"> 
        <fieldset> 
          <legend>Controls Bootstrap supports</legend> 
          <div class="control-group"> 
            <label class="control-label" for="input01">Text input</label> 
            <div class="controls"> 
              <input type="text" class="input-xlarge" id="input01"> 
              <p class="help-block">In addition to freeform text, any HTML5 text-based input appears like so.</p> 
            </div> 
          </div> 
          <div class="control-group"> 
            <label class="control-label" for="optionsCheckbox">Checkbox</label> 
            <div class="controls"> 
              <label class="checkbox"> 
                <input type="checkbox" id="optionsCheckbox" value="option1"> 
                Option one is this and that—be sure to include why it's great 
              </label> 
            </div> 
          </div> 
          <div class="control-group"> 
            <label class="control-label" for="select01">Select list</label> 
            <div class="controls"> 
              <select id="select01"> 
                <option>something</option> 
                <option>2</option> 
                <option>3</option> 
                <option>4</option> 
                <option>5</option> 
              </select> 
            </div> 
          </div> 
          <div class="control-group"> 
            <label class="control-label" for="multiSelect">Multicon-select</label> 
            <div class="controls"> 
              <select multiple="multiple" id="multiSelect"> 
                <option>1</option> 
                <option>2</option> 
                <option>3</option> 
                <option>4</option> 
                <option>5</option> 
              </select> 
            </div> 
          </div> 
          <div class="control-group"> 
            <label class="control-label" for="fileInput">File input</label> 
            <div class="controls"> 
              <input class="input-file" id="fileInput" type="file"> 
            </div> 
          </div> 
          <div class="control-group"> 
            <label class="control-label" for="textarea">Textarea</label> 
            <div class="controls"> 
              <textarea class="input-xlarge" id="textarea" rows="3"></textarea> 
            </div> 
          </div> 
          <div class="form-actions"> 
            <button type="submit" class="btn btn-primary">Save changes</button> 
            <button class="btn">Cancel</button> 
          </div> 
        </fieldset> 
</form> 
</body> 
</html> 

 

 

  • <!DOCTYPE html>   
  • <html lang="en">   
  • <head>   
  • <meta charset="utf-8">   
  • <title>Twitter Bootstrap Version2.0 horizontal form layout example</title>   
  • <meta name="description" content="Twitter Bootstrap Version2.0 horizontal form layout example from w3resource.com.">   
  • <link href="twitter-bootstrap-v2/docs/assets/css/bootstrap.css" rel="stylesheet">  
  • </head>  
  • <body>  
  • <form class="form-horizontal">  
  •         <fieldset>  
  •           <legend>Controls Bootstrap supports</legend>  
  •           <div class="control-group">  
  •             <label class="control-label" for="input01">Text input</label>  
  •             <div class="controls">  
  •               <input type="text" class="input-xlarge" id="input01">  
  •               <p class="help-block">In addition to freeform text, any HTML5 text-based input appears like so.</p>  
  •             </div>  
  •           </div>  
  •           <div class="control-group">  
  •             <label class="control-label" for="optionsCheckbox">Checkbox</label>  
  •             <div class="controls">  
  •               <label class="checkbox">  
  •                 <input type="checkbox" id="optionsCheckbox" value="option1">  
  •                 Option one is this and that—be sure to include why it's great  
  •               </label>  
  •             </div>  
  •           </div>  
  •           <div class="control-group">  
  •             <label class="control-label" for="select01">Select list</label>  
  •             <div class="controls">  
  •               <select id="select01">  
  •                 <option>something</option>  
  •                 <option>2</option>  
  •                 <option>3</option>  
  •                 <option>4</option>  
  •                 <option>5</option>  
  •               </select>  
  •             </div>  
  •           </div>  
  •           <div class="control-group">  
  •             <label class="control-label" for="multiSelect">Multicon-select</label>  
  •             <div class="controls">  
  •               <select multiple="multiple" id="multiSelect">  
  •                 <option>1</option>  
  •                 <option>2</option>  
  •                 <option>3</option>  
  •                 <option>4</option>  
  •                 <option>5</option>  
  •               </select>  
  •             </div>  
  •           </div>  
  •           <div class="control-group">  
  •             <label class="control-label" for="fileInput">File input</label>  
  •             <div class="controls">  
  •               <input class="input-file" id="fileInput" type="file">  
  •             </div>  
  •           </div>  
  •           <div class="control-group">  
  •             <label class="control-label" for="textarea">Textarea</label>  
  •             <div class="controls">  
  •               <textarea class="input-xlarge" id="textarea" rows="3"></textarea>  
  •             </div>  
  •           </div>  
  •           <div class="form-actions">  
  •             <button type="submit" class="btn btn-primary">Save changes</button>  
  •             <button class="btn">Cancel</button>  
  •           </div>  
  •         </fieldset>  
  • </form>  
  • </body>  
  • </html>  

- See more at: http://www.w3resource.com/twitter-bootstrap/forms-tutorial.php#sthash.kgyHadcw.dpuf

Installing Godaddy SSL Certificate on Amazon EC2

I have installed Godaddy SSL HTTPS certificates on many Amazon EC2 instances and I always end up having to look stuff up every time I do it, so I am creating this tutorial for future reference and to help others who have issues installing SSL certificates. The definitely are not the easiest things to install in the world by far! Godaddy certificates are a lot easier to install than Semantic or VeriSign certificates however. They are a lot cheaper too, but do not have the good reputation for security that VeriSign/Semantic has.

First Steps for Installing SSL Certificates:

  1. Log in to your Godaddy.com account and click in the drop down under your name in the top left green nav bar, click on "My Account".
  2. Then click on the plus sign next to  "SSL Certificates" and select the certificate you most recently purchased and click on the orange "Set Up" button on the right. Then select your service in the drop-down that appears and click on the green "Set Up" button.
  3. Next, Click on the "Launch" Button to open your certificate control panel. Since you are installing the certificate on a third party server, Amazon, select the third party server option in the "Hosting Options" dialog and enter your CSR by following the instructions for CSR in the next section.

 

Generating a Certificate Signing Request (CSR) - Apache 2.x

  1. Log in to a secure shell. I uses Putty for this.
  2. Enter the following at the command prompt:openssl req -new -newkey rsa:2048 -nodes -keyout yourdomain.key -out yourdomain.csr                                  Replace yourdomain with the domain name you're securing. For example, if your domain name is coolexample.com, you would type coolexample.key and coolexample.csr.
  3. Provide the information asked for when doing the above command. You do not have to enter a password if you want to make the process simple and you don't have to enter any of the data that is specified as optional.
  4. After answering the questions, type "ls" at the command prompt to list the content of your directory and you should see the two files you just generated with the CSR signing request. Open the .csr file by typing "sudo vi yourdomain.csr" and highlight the entire file and copy it to your clipboard with cntrl+c.
  5. Paste the text into your Godaddy account  below where it says "Enter your Certificate Signing Request (CSR) below:".
  6. Check the box to agree to terms of service and click the continue button leaving the other options set to default. Your certificate should be emailed to you.
  7. Next login back into your Godaddy account and click on "request certificat" next to the certificate you just did the CSR for.
  8. You do not have to wait for the email though, to get your certificate, go back to your account main page by clicking on "My Account" from the main nav on Godaddy.com. Scroll down to "SSL Certificates" again and click "Launch by your new certificate. If it is not ready yet, wait for your email and try again.
  9. wait on email....

Server  Configuration for SSL Certificates

The next thing you will have to do, after you have received your certificate files from Godaddy, is to configure your web server to deal with SSL and HTTPS. To do so, first check that you have open ssl and mod_ssl installed by creating an info.php file with the following contents:

<?php

phpinfo();

?>

Upload info.php to your server's web root directory which will be /var/www/html on an Amazon Linux AMI. Then go to your info.php file in a web browser by navigating to yourDomain.com/info.php. You can verify that you have Open SSL by using the find feature of your browser and searching for "openssl" and check to make sure that it says enabled after the second instance of openssl you find on that page.

You can verify the existence of mod_ssl by searching info.php for "mod_ssl" if it is there, it is activated most likely. Just make certain it is listed under the loaded modules in your php info file.

Installing mod_ssl

If in the previous step, you could not find mod_ssl, it probably isn't installed. To install mod_ssl, open up a shell command prompt and type the following command at the command prompt:

sudo yum install mod_ssl

Type "y" for yes to give permission to install the module.

Now you can see mod_ssl in loaded by confirming it's presence in your info.php file from before.

Configure httpd.conf and ssl.conf

Before you start the following steps, go to your command prompt for your web server and make backup copies of your httpd.conf and ssl.conf files using the following commands:

cd /etc/httpd/conf

sudo cp httpd.conf httpd.conf.bkup

cd /etc/httpd/conf.d

sudo cp ssl.conf ssl.conf.bkup

  1. Next, download your files from Godaddy as described above. Unzip them onto your desktop and upload them to your ec2-user folder on the web server. Your key files should already be there from when you generated a CSR earlier
  2. If you're using an amazon Linux basic AMI, you will have a separate ssl.conf file at etc/httpd/conf.d/ssl.conf and your httpd.con file will be in the etc/httpd/conf/ folder. Open up /etc/httpd/conf.d/ssl.conf in vi using the command: sudo vi /etc/httpd/conf.d/ssl.conf
  3. Find the following lines and edit them according to the file names you just uploaded and your key file name:     SSLCertificateFile /home/ec2-user/site.com.crt
    SSLCertificateKeyFile /home/ec2-user/site.key SSLCACertificateFile /home/ec2-user/gd_bundle.crt
  4. Replace "site" with the actual file name above, then save the ssl.conf file in vi editor by typing :wq and if you didn't know how to edit in vi editor, u have to type "i" to insert or delete text then hit the esc key to get out of insert mode.
  5. Restart Apache by typing "sudo service httpd restart" at the command prompt and pressing return. If no errors occurred, you did everything correctly and your ssl certificate will work now. If Apache didn't restart, you have a problem in your config file most likely so check your error logs or read the output error and fix the problem and restart until it works. If all fails revert back to the original backed up config files and restart the process until it works.

Updates when I did this again in December of 2016

When I installed an SSL certifiate in December of 2016, the process was close to the one described above, so I'll leave it there for reference and note any differences here. One obvious difference is that the Godaddy site has changed, but not so much as to make the above instructions not work. You will just have to be aware that some of the buttons and links are a little different than I have described above. Also, I noticed that almost none of the Godaddy links to support and information worked, so it was difficult and nearly impossible to find any help from Godaddy's website. That is why I decided to update my guide here.

Info Needed for a CSR

Here is a list of the basic information you will be asked for when doing a Certificate Signing Request or CSR:

1- Country Name(2 letter code):
2- State or Province Name(full name):
3- Locality Name(eg, city):
4- Organization Name(eg, company):
5- Organiztion Unit Name(eg, section):
6- Common Name(eg, your name or your server's hostname):
7- Email Address:
8- Company name:

In December, 2016, I was able to use the command described above to get the CSR files from the Amazon server. So I got the CSR and received the email from Godaddy several minutes later. Here is the relavent portion of the email they sent me after I filled out the Godaddy CSR form on their site:

----------------------------Begin email from Godaddy:--------------------------

Dear Secure Certificate Customer,

Congratulations on becoming an SSL certificate owner for the domain: MySite.com! We're delighted to have you on board.

What's Next?

Step 1

  • Download your certificate, by logging in to your account at https://certs.godaddy.com/home.pki?AccountUid=REMOVED FOR SECURITY REASONS.

Step 2

  • Click here to follow our easy instructions to install your certificate.

Step 3

  • We've partnered with McAfee SECURE to deliver more value with your SSL Certificate. By installing the McAfee SECURE trustmark on your website, your site will be monitored by McAfee 24/7. McAfee SECURE trustmark will display on every page of your site and right in the search results of Google, Yahoo!, Bing and Ask.To add the seal to your site, log in to your SSL account at (Link Removed), select your certificate, then choose your seal from the “Seal” options.

 

If you have any trouble or questions, contact us and let us know. We are available to help around-the-clock, seven days a week.

Customer Support:
E-Mail: ra@godaddy.com
Phone: 480.463.8887
Fax: 480.393.5009

For further information, log in to your account at https://certs.godaddy.com.

----------------------------End email from Godaddy--------------------------

Naturally, I attempted to follow the instructions emailed me in the above email message. I completed step one by clicking on the link they provided(or you can navigate to the SSL cert yourself from your Godaddy account). You simply click the link in step one from the email, click on the domain name that represents the current SSL certificate you wish to install, and click on the "Download" icon in the resulting web page.  That will open a page that asks you the server type you wish to install the SSL certificate on. The options are:

  • Apache
  • Echange
  • IIS
  • Mac OSX
  • Tomcat
  • Other

How to Find Your Server Type

In order to to figure out what type of web server you're running, from Linux you can issue the following command from a shell prompt(command prompt):

curl -I www.jafty.com

Type the curl command replacing jafty.com with a domain name that points to your server and press enter. When entering the above command you should see results similar to this:

servertype

Notice the text that I circled in red. It says I'm on a cloudflare-nginx server. So for server type, I would choose "other". Then I clicked the download button.

So far, so good, but when I went on to step two after successfully downloading the SSL certificate files, the link that Godaddy provided in step two for instructions fails to open a web page, so you are on your own for instructions. Again, that is why I have provided the information here. I hope it helps people.

Installing SSL Certificate on Bitnami ec2 with WordPress

If your webroot directory is /opt/bitnami/apps/wordpress/htdocs then you are surely usig a Bitnami ec2 with WordPress stack. In that case, here are the modified instructions for installing your SSL certificate:

Open your bitnami.conf file at /opt/bitnami/apache2/conf/bitnami/bitnami.conf by navigating to the directory and executing this command:

sudo vi bitnami.conf

scroll down to the virtual host settings for port 80 and port 443 and change this: DocumentRoot /opt/bitnami/apache2/htdocs

to this:

DocumentRoot /opt/bitnami/apps/wordpress/htdocs

in each virtual host(ports 80 and 443).

Find the lines in the virtual host declaration for port 443 that look similar to:

SSLEngine on
SSLCertificateFile "/opt/bitnami/apache2/conf/uniquecertname.crt"
SSLCertificateKeyFile "/opt/bitnami/apache2/conf/uniquegenerated.key"

Delete the above lines and replace them with the following lines:

SSLEngine on
SSLCertificateFile "/opt/bitnami/apache2/conf/YourOWN.crt"
SSLCertificateKeyFile "/opt/bitnami/apache2/conf/YourOWN.key"
SSLCertificateChainFile "/opt/bitnami/apache2/conf/gd_bundle-g2-g1.crt"

Make sure you change the above files names with your own however and make sure you've placed the files named in the proper locations. THe first one, YourOwn.crt, will be replaced with the file you downloaded from Godaddy when you purchased your SSL certificate. The second file will have  been created when you created your certificate signing request from the command line before you obtained your files from Godaddy and can normally be found in /home/bitnami. The last line is for your bundle certificate which should also have been in the files you downloaded from Godaddy. Place all three files in the /opt/bitnami/apache2/conf/ directory by opening each(before they exist) in vi editor then copy and pasting their content and saving them. I use that method because filezilla FTP clients will not allow you to modify files in this directory.

 

Summary

That's all there is to it. It's difficult if you don't have precise instructions to follow for your particular web server, so if you have an Apache server on an amazon ec2 instance, following these instructions in this tutorial should have you up and running with HTTPS in no time at all. If you are using a different type of server or hosting provider, the instructions will be similar but will differ in some spots, so be careful as this tutorial was written for Amazon, Linux users in mind.

 

 

 

 

 

How to Remove an Entire Directory in Linux

To remove a directory in Linux, you use the rm command line command from a shell prompt with the -r argument to let Linux know to do a recursive delete where it delete all files including sub-directories and files in sub folders. Here is what you would enter into the command prompt to delete a directory named MyDirectory:

rm -r MyDirectory

You can also use the -f argument with the -r argument if Linux bothers you with a bunch of queries as to whether you want to delete certain files, but I found that it was not always necessary. When you find yourself having to type "yes" a thousand times however, use this command instead to stop it from asking you to confirm deletion:

rm -rf mydirectory

 Don't Delete via FTP!

I found that when you need to clean up a server or delete hundreds, thousands or more files, using an FTP program like Filezilla becomes very inefficient. I found that logging into shell with Putty and using the above command, rm -rf mydirctory, works much faster and has way less problems. Definitely worth the extra time to log into a shell account!