Skip to main content

Posts

Debugging a DOS

I'm not a sysadmin, but I end up doing my best now and then when one of my sites gets into trouble. This is a sort of "after action report" of an incident that I just resolved (hopefully). I woke up and happened to check email on my phone (don't always do this, will now) and was greeted with a uptime robot email that one of my sites was down, and had been for about 4 hours. I quickly checked the site on my phone and yup, it wasn't loading. Ran to the office and hopped on my laptop. SSH to the server, and everything seems fine. Very little load on the server (AWS instance). Did a restart of apache/php/mysql and the site is still down. Weird. Running the site's index.php file on the command line works as expected and fast. Ask a few other people to check, and it's down for them. Then I logged into the AWS console and checked on status there - everything is up and running.... WTF? This is a lightsail instance, and then I noticed the outgoing network traffic h...

WSL - great tool for LAMP webdev!

 So I've been using WSL (Windows System Linux) for well over a year ago. I started with WSL 1 and then moved WSL 2 recently. All in all it's been a pretty smooth ride. I decided to ditch my mac after well over a decade of using macs and move to Windows. I wasn't happy with the price of the hardware I was getting for that price. Windows is better than it used to be... but that's not really saying much. And I've always been firmly in the Linux world when it comes to web development and hosting. So what to do? WSL fills the bill perfectly. Right now I have Ubuntu installed - all I have to do is open a Windows terminal window and type 'wsl' and I'm in a nice comfy linux world. Start up apache and MySQL, open localhost in my browser and I'm working off my local environment, almost like I was using MAMP. I did consider setting up dual-boot Windows and Linux - but my laptop just doesn't have the disk space for that. Upgrade the disk is an option, but tr...

Uhh.... wtf?

 Randomly checked the views in blogger for the post I published yesterday on cleaning up a hacked Wordpress site.  Hey, there's one view! I guess that's good... wait, it says that the view occurred on Sept 30, 2020... more than three weeks before I actually published the post. Someone has a bug!

Cleaning up a hacked wordpress site

A long-time client contacted me with a question about their SSL certificate, and said they thought the site "might be hacked." Well, boy was it hacked. Shell scripts everywhere, and core Wordpress files as well as plugins heavily modified. I think it's all cleaned up now, so I thought put up a quick post about the process while it's still fresh in my mind. How to know it's hacked? In this case, it was easy. The site looked fine in the browser, but when I logged in and looked at the files on the server there were quite a few shell scripts which are little php files (in this case) that give the attacked a 'back door' to continue to upload files/etc even if their WordPress access was closed off. Additionally, there were many core files (wp-config.php for example) that had huge chunks of encoded text inserted at the top of the file. Additionally, looking at the transfer logs revealed traffic to weird looking URLs that were definitely not legitimate pages/post...

Multiple domain SSL certificates on AWS lightsail...

This one caused some confusion today! I have an AWS lightsail server set up. It handles multiple different domains - essentially the same codebase, but does different things depending on the hostname (domain) being used to access it. I needed to add a new letsencrypt certificate to the system. This would be the second one I've added. After generating the certificate, I found that the new site (called it domain2) was trying to use the certificat of the first site (domain1) ... I thought I'd generated a certificate that supported both domains, but apparently not. After some poking around (lightsail has its own way of setting up the apache configuration files) I finally figured it out. To fix it, I needed to have two different virtual host (port 443) directives. They were essentially alike, except that that I had to add ServerName and ServerAlias settings appropriate for domain1 and domain2, and set the SSLCertificateFile and SSLCertificateKeyFile settings appropriately. Now I j...

Using a vim macro to fix 'mysql_' calls with regex

 I'm working on a largish project, converting it to work from early PHP 5 to PHP 7.3 and I found myself spending a lot of time converting all those various mysql_* to their equivalent procedural mysqli_* function calls. Mostly pretty tedious. Anytime you encounter something tedious that you'll have to do on a ton of files, it's a chance for automation. In this case, I decided come up with a vim macro that would automagically convert the most commonly occurring function calls. Here's the macro, which uses 4 regular expressions to search and replace the four most common ones - then followed by a search for "mysql_" to catch any outliers. :% s/mysql_query(\(.\{-}\),\(.\{-}\))/mysqli_query(\1 , \2)/eg :% s/mysql_fetch/mysqli_fetch/eg :% s/mysql_num/mysqli_num/eg :% s/mysql_close/mysqli_close/ge :/mysql_ The easiest way to use this is to paste into a new document, then select it all and yank it into a buffer. Then just run the buffer as macro. So, I used 'm...

Quickly create a gallery of images from a list in vim

This is something I run into pretty often, so I thought I'd share how I handle it, in case it's helpful. Sometimes you have a list of image files, and you need to create the html formatting to make them into a gallery of some sort. Imagine each file has two versions, a full size and a thumbnail image. Pretty common scenario. The URL for the files will look like /images/gallery/full/[filename] and /images/gallery/thumb/[filename] There's lots of ways to do this, here's what works well for me. First I grab a list of the files from the command line, ending up with something like this ls -l -rwxrwxrwx 1 user group 388044 May 25 11:16 IMG_20161205_120541.jpg -rwxrwxrwx 1 user group 451788 May 25 11:16 IMG_20161215_114201.jpg -rwxrwxrwx 1 user group 298125 May 25 11:16 IMG_20161216_121618.jpg -rwxrwxrwx 1 user group 369981 May 25 11:16 IMG_20161216_125940.jpg -rwxrwxrwx 1 user group 479464 May 25 11:16 IMG_20161216_131010.jpg -rwxrwxrwx 1 user group 664528 May 25 11:16 IMG_20...

Setting up a simple LAMP stack in WSL/Ubuntu

As I've mentioned before, I've been running WSL (Windows Subsystem for Linux) for roughly a year now. It's still a little mind-blowing to me - when I got started Microsoft was about as anti-linux as can be. Weird times! Anyways, I have a fairly simple setup right now that's been working well for me. I'm using an older version of WSL right now, and apparently the newer version is much faster - but this works well enough for my needs right now. This guide assumes you already have WSL set up and working, and can get a bash command line... Install Apache and MySQL This is easy, just run: sudo apt install apache2 and sudo apt install mysql-server and while you're at it, you can start them up: sudo service apache2 start sudo service mysql start You may run into some weird issues - I used this guide if you need any other info. Now you have the most basic bits set up, it's time to get your actual sites up and running locally! Setting up your projec...

WSL and Windows Terminal

I've been back on Windows now for awhile, and WSL has made it quite an easy adjustment. You still get the occasional "WTF Windows" moment, especially after a big update - but I'm pretty happy with it. At the time I just couldn't justify splashing out for a pricy macbook with no escape key and a stupid "hotbar" thing... Anyways, if you're used to working in the LAMP stack and haven't tried out the combo of WSL and windows terminal, give it a try! Or at least try WSL if you don't use command line much. WSL (Windows Subsystem for Linux) basically lets you run linux inside windows. I use it to then run MySQL and Apache/PHP - and I'm good to go. Most of my work happens inside a Windows Terminal window, which has become a pretty slick, configurable terminal. I have a 'projects' directory set up, in which each of my various projects reside. When I want to work on one, all I have to do is edit the apache config to use that particular ...

Security Tips - Passwords and Logins

Passwords are something we all have to live with. There are other authentication methods slowly coming into use (i.e. two-factor) but it's hard to see passwords going away anytime soon. I assume everyone knows the basics - use "good" passwords, don't share them between sites, don't write them on a sticky note on your desk, don't save them in a file named "passwords.txt" on your computer, etc etc. That's all well and good, but there's so much more you can do! Good Passwords A "good" password is hard to guess, is what we're told. I think most people are unclear about what exactly "guess" means. These days, it means that it needs to be resistant to password cracking attacks that are getting ever more fast and sophisticated. Just making sure that you have numbers, characters, upper/lower case, etc isn't enough. The gold standard most important thing about a password is that it is long . The longer the better....

Security Tips - Incognito Window

A lot of people know what incognito mode (or private mode) is at some basic level. They should use it when they want to do something "private" on the web. But I think most people don't actually understand what it means and how/why to use it. Perhaps this will help. Before we start - cookies are little bits of data used to track you between page loads. Think of it like a fingerprint. They're extremely important for session handling, so that a site can remember who you are from one page to the next. But they're also really handy for things like advertising services to track your activity on the web. When you open a new incognito window (and don't have one open already) - you're starting a new session in your web browser that doesn't have any of the cookies or caching that your "normal" browser window has. In practical terms, this means that when you visit a site, they won't have any history of you (mostly) and you may need to relogin, ...

Setting up SEO-friendly URLs in htaccess/PHP

This is something I feel like I've done dozens of times over the years, and always have to waste some time googling before I figure it out. Maybe next time I'll remember to look here? So, you're writing a custom site, and you need to be able to handle SEO-friendly URLs. You know, the kind where instead of something like "category=my_category&page=233" you the URLs to look more like "/my_category/my_page" Those are called SEO Friendly URLs and really they're also just plain friendlier for people too. They're really kind of a leftover from when a lot static HTML sites were really organized with subdirectories full of HTML files - and Apache will still work like that "out of the box" My usual approach to this has two parts. First, there's a custom .htaccess file in the main site directory, that redirects all requests (that are not for actual files/directories) to index.php Then, in the index.php there's a bit of code ...

Playing with Pico CMS

I recently started working on reanimating an ancient site I had just sitting around as a backup. It was built on a very old version of Joomla, and while some of the content is still relevant - much of it is not... So, rather than trying to figure out how to import all this content into some more modern CMS and then delete the old stuff, I decided to use this as an opportunity to play around with Pico - a PHP-based flat-file CMS. The idea is that you can easily create content by just creating markdown files in the 'content' directory, and they magically show up on the site. Organization is as simple as subdirectories inside content. Themes are just twig template files. I'm not a huge fan of twig (remember, PHP was originally a templating language... so why do we need something else for templates?) but I'll give it another try - I haven't used twig in at least six years, so maybe it's better. So far things have been going pretty smoothly - I can just copy...

Project/Issue Tracking and Organization for the freelancer

I'm currently working on a pretty large, long-running project as the primary developer and systems administrator. I primarily work with one other person who acts as designer and the main interface with clients and others. Everyone works remote. We quickly realized we needed some way to keep track of ongoing issues/ideas/features - and our initial response was a simple google sheet. I'm a big fan of starting with the simplest possible system first and adding complexity as needed. This worked pretty well, although prioritizing/sorting and remove completed "issues" became clunky over time. In the past I've experienced quite a variety of systems for handling/tracking work. Jira is probably the most popular in larger organizations, but to my mind it was like using a sledgehammer when a pocket knife was needed... plus it was not free and we had no budget. Trello and things like it are pretty nice, but I wanted something with a little more capability to track all t...

using vim and command line to backup and remove a lot of directories

Was just working on some server cleanup for a client and thought that this might be a handy tip for anyone out there in a similar situation... Here's the problem, I have a directory on a server that has lots (i.e. thousands) of subdirectories. I need to copy those up to an S3 backup bucket - organized by year and month - and then delete them. The tricky bit is they're not organized by month/year right now. It's just a giant mess of subdirectories without much of a coherent naming strategy. So, here's what I've come up with so far. First, I generate a text file listing all the directories, filtering through grep for the year I'm interested in, i.e. ls -ltr | grep 2019 > list.txt This gives me a list of all directory entries that have '2019' in them, which should get them all since we're using 'ls -l' Next, I open that file in vim, and copy all the files for the month I'm backing up, and use a regex to remove the leading bi...

My Setup - updated

Reading through my old posts, I found it ironic that one of them was about how I was back to using Macs again for work. Ironic because after eight years of using a mac, I switched back to Windows about a year ago. The reason was that my old mac laptop was getting long in the tooth, and I absolutely hated the new macbooks with their janky keyboard and stupid touchbar. Apparently the keyboard has gotten better since then... but I still feel that the macs are just too expensive for what you get. So I switched to Windows, thinking I'd dual-boot with Linux to give me an appropriate development environment. I still spend most of my time at the command line or in vim anyways. But I decided to try out WSL in Windows just to see what it was all about. What a pleasant surprise! I ended up getting a nice 13" gaming laptop that packs quite a punch in a lightweight package. Windows 10 is decent enough. It still has a lot of those annoying Windows quirks, but I can live with that. ...

A blast from that past...

I noticed the other day while checking out Google Analytics that this site was still alive and getting the occasional visit! That's great, but I think it deserves some freshening up. So stay tuned for some content that is a bit ... fresher!

Mobile posting

I'm writing this post on my phone using the official Blogger android app... seems pretty basic, but handy nevertheless! More posts coming this week, if my workload cooperates.

Life as a Mac web developer

I have a terrible secret. For the last few months, I've been using a... Mac (gasp). Now I may be the only mac-user on this blue ball that isn't some sort of die-hard apple cultist. I think they're great (if over-priced) hardware, and I dig OSX. I don't think Steve Jobs is the second coming. I hate iTunes and iPods. I don't have an iPhone. I don't like black turtlenecks. But this does make a nice little web development machine. I have a command line (that's not DOS...) and a unixish OS. It has apache set up right away. It has a very nice UI, and there is some amount of "it just works" - although I'm not sure that's more true with WIndows. But it is more true than of even the best linux distros, at least in my experience. So, stay tuned and I'll point out some handy apps for any other web devs who've made the switch.

Empty $_POST array in MAMP

OK, so just spent 30 minutes debugging this. I'm now using a mac as my development platform for one of the sites I support. It's worked pretty well until today when I started adding a new feature. I ran into a weird problem where POST arguments were not being made available, either in $_REQUEST or $_POST - while GET arguments were. Thanks to this page , I was pointed in a useful directions. Turns out for some reason my version of MAMP had a max_post_size of "3200M" set in its php.ini file. That was not working too well - when I changed it to 32M, everything went back to working normally. So, perhaps that will help someone else who's driving themselves crazy!