How to repair permissions on Linux Apache /var/www/html folder

I recently ran into an issue where I could no longer FTP files to my Linux droplet when multiple users were uploading to the server. The server kept the user as the owner despite me adding them to the www-data group. This fix comes from my ex-boss, James Tomasino who was kind enough to provide some help since I was stumped. I’m sharing in case anyone else runs into the same issue and finds it useful.

You’ll need to fire up terminal, ssh to the server, and then execute these commands:

+s makes permissions sticky so that all files will inherit from the parent directory. This was the setting I was missing.

Open up /etc/ssh/sshd_config. I use nano so:

Hit CTRL+W and look for “subsystem” which is typically located near the bottom of the file. Change

to

If you already have files in the HTML folder, you’ll want to run these commands to reset the permissions:

 

How to stop CouchDB on Mac OS

I have been working on a proof of concept using CouchDB. After getting the proof of concept working, I spun up a digital ocean droplet and proceeded to setup CouchDB on the server. I went to enable the SSH tunnel so I could access the CouchDB Futon instance and promptly ran into an error because my local instance of CouchDB was using the same port, 5984. I had a lot of trouble finding out an easy way to stop CouchDB because the documentation in the Wiki wasn’t accurate:

As a workaround, in Terminal, run

This will output something like:

99093 0 org.apache.couchdb.288008

Grab the highlighted portion and run

Substitute the process name accordingly and you should be able to run the ‘launchctl list’ command again and see the process is no longer present.

Regex to parse date formats when unknown

I’m working on an app that will parse different file sources and aggregate it for a report. Of course, each format has a different date format and trying to parse it all has proved to be a pain. I wrote a regex that’ll parse out just about every datetime format I’ve run into that I am sharing in case someone else finds it useful. I’ve put it on a Github gist along with a sample of the various dates I’ve tested it against and confirmed to work. If you find a format not covered by the regex, post a comment and I’ll update the gist.

Just a note that I haven’t finished parsing the timestamp (e.g. 1997-07-16T19:20:30+01:00) format. The date portion does get extracted correctly so I left it in.

(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80 – error

I recently got handed a new Ubuntu droplet at work to setup and work on. I was going through the typical configuration to lock down the server and go to installing Apache when I suddenly ran into the error

(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80 – error

I was a little surprised considering I had only run 4 commands total on a brand new installation. If you’re getting this error like me, you’ll need to find out what’s being bound to port 80 and then stop it. Use this command to get a list of anything that’s running on port 80.

For me, it turned out nginx was running and bound to port 80. If you have the same problem, run this command to stop it:

Now you should be able to start apache.

Copy File Context to Clipboard via Command Line, Git Bash (Mingw64), or Terminal

I’ve been spending more time switching from SVN to Git and learning the command line options. I’m finding a lot of the Mac Git terminal commands I run aren’t the same in Git Bash (Mingw64). One of the commands I use is the pbcopy command to copy the ssh key to the clipboard to paste into Github and Bitbucket accounts. I’m starting to use it more as I am learning managing Linux servers and adding my key to login. I’m adding it here as a cheatsheet for myself but I thought others may find it useful.

On Windows, you can run this command to copy your ssh key to the clipboard:

On Mac:

or if you want to view it in the terminal window:

How to Copy and Paste into the Digital Ocean VNC Console

I recently signed up for Digital Ocean to test droplets for my development and linux management testing. I was securing the server and setup fail2ban, disabled the root login, and created a user account but forgot to change the user name from root to the user name I selected in my SSH client profile. I ended up locking myself out of the server and had to resort to logging into the admin panel on Digital Ocean’s website and use their browser embedded VNC client to restore my access. I quickly discovered that one of the downsides of using this panel is that you can’t copy and paste commands. Luckily there’s a workaround and you can use the browser console to do sendkeys through Javascript.

Bring up the console in the browser developer tools. Here’s a cheat sheet for keyboard shortcuts:

BrowserDescriptionWindowsMac
ChromeOpen Developer Tools and bring focus to the consoleCtrl + Shift + JCmd + Opt + J
FirefoxOpen ConsoleCtrl + Shift + KCmd + Opt + K
Internet ExplorerAfter hitting F12, you have to click the console tab.
There’s no direct shortcut to the console tab.
F12N/A

Paste this snippet into the textbox in the console window:

Chrome console

 

Update 9-21-16

Ruden and Sebastiaan’s pointed out there was a bug in the code above. This updated snippet has support for characters when using shift characters like !@#$%^&*()_+

You’ll receive a dialog prompt to enter the copy to paste in. Please note that you need to click on the VNC console and hit enter to execute the command.

Javascript Prompt

 

 

 

 

 

If you need to enter more than one command, just hit the up arrow on your keyboard in the console to get the script again for easy reuse.

Sitecore 8 Install Error: “The name you entered is not unique.”

Stecore Installer Error - The name you entered is not unique.I was working on my business partner’s computer to help him fix errors with his Sitecore instance for his certification class. He experienced multiple issues with the Sitecore 8 installer on Windows 8 and we went the manual route of deleting Sitecore to install clean and start from scratch. In the process, we:

  • Deleted the IIS website instance in the IIS Manager
  • Deleted the databases used by the instance
  • Deleted the root folder in the filesystem

After launching the installer again, it kept returning the error “The name you entered is not unique.” when naming the Sitecore instance to one previously used. After checking the IIS metabase and a few other typical locations, couldn’t figure out where the Sitecore installer was finding the name since we deleted everything manually. It turns out that the Sitecore executable installer creates a registry entry under HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Sitecore CMS which is used to display information in Windows Programs and Features. This registry key is also checked during the installation process and if a child key with the same name as the one being installed is found, the above error message is shown.

To fix this:

  1. Start -> Run (or Windows Key + R)
  2. Type regedit
  3. Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Sitecore CMS.
  4. Delete the registry keys containing the information about the previously installed instance.

NOTE: You’ll need to relaunch the installer as it apparently caches the key information.

 

How to fix “hacked by Moroccanwolf” WordPress site

A client of mine had their wordpress hacked and when you would load the site, it would simply display a message that said “hacked by Moroccanwolf”. I did some digging and luckily it wasn’t a major hack and they didn’t mess with the posts or other settings as a lot of the hacks do.

Quick Fix

  1. To fix it, you’ll need to connect to your database using an editor of some sort, such as PHPmyadmin.
  2. Once logged in, expand your database on the left.
  3. Click on ‘wp_options’.
  4. On the top right, click the ‘Browse’ tab.
  5. Look for ‘widget_text’ in the option_name field. (For my client, it was at row 90). You should see something similar to this:

Delete the entire tag and this  should restore your website. Now remember to change your logins and update wordpress.

How I Figured it Out

Most of the hacks I’ve seen are done through injecting javascript into the database somewhere which either force a redirect or something along those lines. Here’s the steps I followed to find it:

  1. To fix it, you’ll need to connect to your database using an editor of some sort, such as PHPmyadmin.
  2. Once logged in, click on your database on the left. Ensure you’re on the database and not a table.
  3. Click Export.
  4. Leave it to quick and click go.
  5. You should now see a textbox with a mess of SQL commands.
  6. Copy and paste into your favorite editor,
  7. Search for <script> and you should find something that doesn’t belong.  In this instance, that was the only thing I found of note.
  8. You’ll want to scan the rest of the database for things that don’t belong. Additionally, you’ll want to replace all the wordpress files and confirm no .htaccess files were created that give hackers write access.

 

When updating Office 2011 for Mac, you are prompted that you must close “Microsoft Database Daemon” and “SyncServicesAgent”

If you’re trying to update your install of Microsoft Office 2011 for Mac, you may get the following message:

“These applications must be closed before the software can be installed:

Microsoft Database Daemon
SyncServicesAgent

Close these applications and try again”

If you try to kill the apps using activity monitor, you’ll find they keep getting restarted. The only way I found that worked to stop them is by following the instructions below.

  1. Open a terminal window and enter the following command:
    launchctl unload ~/Library/LaunchAgents/com.microsoft.LaunchAgent.SyncServicesAgent.plist

This will unload the SyncServicesAgent. Unfortunately the Daemon kept running for me after the latest update. To stop that, do the following:

  1. Open activity monitor
  2. Scroll down until you find Microsoft Database Daemon in the list of active applications.
  3. Click on Microsoft Database Daemon and click on the Quit Process button in the toolbar

Go back to the install utility and you should now be able to proceed with the install. Once the install is finished, you’ll want to restart the Sync Services Agent, so do the following:

  1. Go back to the terminal window and enter this command:
    launchctl load ~/Library/LaunchAgents/com.microsoft.LaunchAgent.SyncServicesAgent.plist

Now you should be all set with updates and can close terminal.

 

Windows Server 2008/2012 Blue Screen after Login – No Desktop

One of my teammates was working on a Windows server and needed to access IIS to complete a Sitecore upgrade on the machine. After logging in, he was reporting that he only saw a blue screen with no user interface. I logged in under the administrator account and ran into the same thing. Here’s how I was able to reset:

  1. CTRL + ALT + END
  2. Start Task Manager
  3. Click processes tab and find all instances of “explorer.exe”
  4. Right click each process and selected “End process tree”
  5. Once all instances are gone, select the Applications tab
  6. Click new task button
  7. Type “explorer.exe” without the quotation marks
  8. Click OK.

If it’s a user account and you can login to the administrator account and see the UI, you can load remote desktop as admin.

  1. Start -> Run
  2. Type “mstsc /v:servername /console /admin” in order to access the server.
  3. In “Windows Taks Manager”, go to the Users tab and proceed to do a right click over the account that you want to “Log Off”, select log off.

This should free the locked session used by that account and bring the UI back.