Centos 6.5 Virtual Hosts Not Working? Try this

As I was working on creating virtual hosts I noticed that no matter how correct I wrote the code in the http.conf file, the VH’s still wouldn’t work. I found that in CentOS 6.5 , unlike CentOS the NameVirtualHost *:80 tag is commented out. Fix this from

#NameVirtualHost *:80

 

to

 

NameVirtualHost *:80

 

Save your file and the restart apache

sudo service httpd restart

 

Your Virtual Hosts should be working now.

Enabling .htaccess use in CentOS7

1. Go to your /etc/httpd/conf directory.

 

/etc/httpd/conf

 

2. Then use your text editor to modify it. I used Vim on this example:

 

sudo vi http.conf

 

Look for the code that looks like this :

 

 <Directory /var/www/>
 Options Indexes FollowSymLinks MultiViews
 AllowOverride None
 Order allow,deny
 allow from all
 </Directory>

 

3. Change AllowOverride None  to AllowOverride All  (Press i to insert the text you want to modify in Vim in the correct place, when finished press the ESC key to exit out of insert mode)

4. use :wq to write and quit Vim

5. Restart Apache

sudo apachectl restart

 

Now go and create your .htaccess file in the directory you want, for example:

 

/var/www/example.com/public_html/.htaccess

 

It worked for me, so it should work for you.

 

Good luck!

 

Creating Virtual Hosts on CentOS 7

So this is my first attempt at creating Virtual Hosts on CentOS7. I followed a tutorial found on → https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-centos-7

 

However, as soon as I ran:

sudo apachectl restart

 

I got the error stating:

Job for httpd.service failed. See 'systemctl status httpd.service' and 'journalctl -xn' for details.

So I typed:

 

systemctl status httpd.service

 

and I found more information:

 

 httpd: Syntax error on line 354 of /etc/httpd/conf/httpd.conf: Could not open configuration file /etc/httpd/sites-enabled/example.com.conf: Too many levels of symbolic link

So for some reason the IncludeOptional line wasn’t working.

Then I found a blog post about virtual hosts on → http://blog.miteshganatra.com/how-to-set-up-apache-virtual-hosts-on-centos/

 

And it told me to put the <VirtualHost> tags directly into the httpd.conf file.

 

This lead to this error :

 CustomLog takes two or three arguments, a file name, a custom log format string or format name, and an optional "env=" or "expr=" clause (see docs)

You can fix this error by including the parameter combined at the end of the custom log line.

 

So your <VirtualHost> block should look like this:

<VirtualHost *:80>
 ServerName www.example.com
 ServerAlias example.com
 DocumentRoot /var/www/example.com/public_html
 ErrorLog /var/www/example.com/error.log
 CustomLog /var/www/example.com/custom.log combined
</VirtualHost>

Then I restarted apache:

 

sudo apachectl restart

 

and everything seems to be working!

I hope this help you out avoiding the pitfalls I faced today :)

 

Happy Thanksgiving!

 

Concrete 5.6 Block won’t show up in install list

Capture

 

As I am learning how to write blocks for Concrete 5 aka Laravel that mated with a goat behind a 7-11. I tried to install it via FTP and the new block wasn’t appearing in the list. This was due to my folder name not matching the controller name. I found the answer to this issue here → http://www.concrete5.org/community/forums/customizing_c5/new-block-isnt-recognized/#309922 . So make sure to name your folder the same name as your controller and you should be golden. Below is how a new block, loaded via FTP should look:

 

Capture

Naming your routes in Laravel

So if you are like me, you whip out code faster than a swinging nudist at Woodstock. However before you know it you’re routes are a mess, there’s money missing off the dresser and your daughter is knocked up…..I’ve seen it a hundred times…….

 

Anyway instead of doing your routes like this :

Route::get('/','FooController@method');

 

You should name your routes like this :

 

Route::get('/',array('as'=>'home','uses'=>'FooController@method'));

 

 

This makes it so that when you need to start doing redirects or simple navigation tasks you can do:

 

$url = URL::route('home');

OR…

$redirect = Redirect::route('home');

With ease. Good luck!

Laravel DB::Table()->get() returns an array of objects

Take this code for example:

DB::table('user_charges')->where('uID',$user_id)->get();

 

This will return an array of result objects from your database table ‘user_charges’. This is good to know if you are trying to access the information within the objects in a foreach loop

 

Instead of using:

 

foreach($user_charges as $key=>$value){
  echo $value;
}

Use :

foreach($user_charges as $key=>$value){

echo $value->object_name;

}

Using ‘keyup’ vs ‘keydown’ on jQuery .val() for HTML elements

So I had a code that looked like this

 

$('#invoice_details').on('keydown','#item_amount',function(){

 var qty = $(this).parent().prev().children('#item_qty').val();
 var amt = $(this).val();
 console.log(qty);

 //Do the Math
 var total = (qty * amt);

 $('#item_total').val(total);

})

 

Because of using keydown, jQuery doesn’t have time to tell what the input is until after you essentially “enter” the command from the keyboard aka “pulling your finger up off the key”. Once the keyboard sends the data, then jQuery can see the value. This is why you need to use ‘keyup’. Jquery waits for the keyup event to happen on your keyboard and then sends the results to the .val() function. Good thing to know :)

 

It should look like this:

 

$('#invoice_details').on('keyup','#item_amount',function(){

 var qty = $(this).parent().prev().children('#item_qty').val();
 var amt = $(this).val();
 console.log(qty);

 //Do the Math
 var total = (qty * amt);

 $('#item_total').val(total);

})