Categories
Programming Server Ubuntu

Getting PHP 7.2 to work with NGINX (UBUNTU)

This took a while. I’m much, much more familiar with running apache. I really like how fast and light nginx is, though, and was going to start using it, no matter what.

In the end, it was a combination of all of these things:

  • When I upgrade to nginx 1.17, there is a new “include” line in the nginx.conf file, and suddenly nginx was looking for site config files in this directory (/etc/nginx/conf.d/) instead of the usual one (/etc/nginx/sites-enabled). Had to change that first thing.
  • The nginx process was trying to run under the “nginx” user, instead of “www-data”. Basically, the “user” config in both your php conf files and your nginx conf files must match, or the php-fpm process ignores the requests from nginx.
  • Most tutorials I’ve found on the internet want you to insert specific php-related config into your nginx site config that points php to a certain port, like this:
    • "fastcgi_pass 127.0.0.1:9000;:".
  • However, my php-fpm was configured to run under a unix socket only (you find this via the “listen” param in your php config). So, I had to add the following line to my nginx site config instead in the php section:
    • "fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;"
  • I had to include the following line in my php-specific config in my site conf file for nginx. Even the nginx example conf file is not explicit about this:
    • include snippets/fastcgi-php.conf;
Categories
Programming Science and Technology

Converting ghost cms output to csv for wordpress import

If you’re just coming here for the solution, and don’t want to read the backstory about how I came up with the solution, I understand. :)

Click here to skip to the solution.

The Problem

Recently I helped convert someone’s main blog from Ghost, back to WordPress.

While WordPress makes it easy to export in any format (so that you can easily import your entries into another blog engine), Ghost… does not.

While Ghost certainly does have an “export” tool, it exports in JSON format. JSON format is definitely preferable to XML, but no matter what, I could not find a way to import these entries into WordPress.

I searched through the plugin library–nothing was devoted to allowing an import through Ghost.

I furiously Googled–weirdly enough, any entries I could find about converting Ghost’s output to something that WordPress could import were all years old (and thus none of the solutions presented worked anymore, because I imagine Ghost’s export format had slightly changed.)

So, I decided to make my own.

The Solution

The solution is on Gitlab — just download the Powershell script (the .ps1 file) and run it on the command-line, passing one parameter of “jsonFile”, which is the path to the Ghost export.

Then, you’ll need a plugin to import the new CSV file to WordPress — I used the “WP All-Import” plugin. It seemed to be well maintained, and unlike many other plugins, it didn’t require you to pay for it.

That’s it! I built it in Powershell, because A) I can make quick scripts very quickly in Powershell, and I was frustrated by this point, B) Powershell has very good native CSV and file format conversion abilities, and C) Powershell can now run on any platform (Linux and MacOS included).

If you’re running this script on Windows, you already have Powershell installed, but if you’re running it on any other system, the link to install Powershell will also be below.

Future Enhancements

I only had posts with single tags to test against, so my script is only designed to get one tag for each post for the new CSV-formatted entries.

Ghost’s JSON format for tags was… bad. I don’t know why it was the way that it was. With every other type of metadata you’d need associated with a post, their JSON has that data in the “post” object, but with tags, they’re in a completely different other place, and only associated to posts through a series of IDs. It’s weird.

Either way, if you come up with a solution to that, feel free to fork the project! (Or just suggest a pull request.)

Also, I’d like to eventually re-code this into Python, just because more computers probably use it by now!

Sources

Categories
Computing Hacking Internet Linux Programming Science and Technology Ubuntu

OpenVPN One-Command Server Install Script

I have been looking for a script like this for about a year now:

https://github.com/Nyr/openvpn-install

For some reason that I never understood, installing and setting up an OpenVPN has always been a pain in the ass.  I’ve had one I’ve been using for about a year, but it’s on Amazon’s AWS as was installed through an appliance install, and I really wanted to learn how it worked myself.

Every tutorial I saw either didn’t make sense, or the steps didn’t work.  I set about to try and create a one-script install myself, and then thought, “No — somebody has to have done this before.”

And lo and behold — that’s where I found the above github repo.  It’s amazing, and it works.  I’m going to donate to this person, because they saved me a good bit of work.

 

Categories
Internet Linux Programming Science and Technology Ubuntu

mysql_connect() breaking with an upgrade to PHP7?

mysql_connect() has been finally removed from PHP7 (it was deprecated for some time), and now you have to use mysqli_connect();   The same goes for any other mysql_ commmand.  (I simply did a find/replace for “mysql_” and changed it to “mysqli_” in my php code.

Also, if you’re running your own server, you probably need to install the “php-mysql” after upgrading to PHP7 — it doesn’t seem to be installed along by default anymore.

Categories
Hacking Linux Programming Science and Technology Ubuntu

Using Dreamhost’s VPS as a MySQL Server

[Editor’s Note: Dreamhost no longer allows sudo access on their VPS servers, so the below is no longer possible. If you’re reading this, you might want to check out Amazon’s AWS. Nowhere near as user friendly as Dreamhost, but MUCH more powerful.]

I’ve been a happy customer of DreamHost for many years now — for $9.95 a month, I was able to get loads of diskspace and unlimited bandwidth, all from a great company that was staffed by great people who were very technically competent.

It is “shared hosting,” however — that means you’re getting it that cheap because you’re sharing server CPU power, available RAM, etc, with many other people who are also getting a great deal. You’ll notice this in any WordPress sites you may run on Dreamhost’s shared hosting — there’s about a 7-10 second delay between when you navigate to your site and when your page actually loads, mostly because your server processes are waiting in line behind everyone else’s.

So, Dreamhost does offer a “VPS” service — with this, you’re getting an absolute amount of RAM, CPU power, etc, that will only be used for your sites. It’s a tiny bit more expensive, at $14.95 or so a month, but it’s worth every penny.

If you’ve run WordPress installations on a Dreamhost site, though, you know that your mysql databases are on a seperate server entirely, and that may slow things down as well. Even if you move your WordPress installs to a VPS, your mysql databases will still be on shared hosting. DreamHost offers a “MySQL VPS,” but it costs another $15 a month (minimum), and you have no control over it at all.

A better solution would be to run your own MySQL server on DreamHost’s main VPS, since they give you root command-line access. There are a few hiccups in this process (some put there by DreamHost itself), but otherwise you should be able to do it.

  1. First, create an admin user for your VPS that has sudo abilities, and log into your VPS with that through ssh.
  2. Second, you have to tweak apt so you can even install the mysql-server package. It appears as if part of installing packages through apt involves temporarily storing files in /tmp and then running them from there.Unfortunately, the /tmp directory is mounted on DreamHost’s VPS servers with the noexec option, which means that you can’t run files that are present in that directory. That basically prevents you from installing the mysql-server package until you tweak apt to temporarily stage files in /var/tmp instead. Do this by:Creating a file called apt.conf in the /etc/apt/ directory, and edit it so the contents are the following:
    APT::ExtractTemplates::TempDir "/var/tmp";
  3. Then, install the mysql-server package:
    sudo apt-get install mysql-server;
    

    (When it asks to set a root password, make sure and set one.)

  4. Now, edit the file /etc/mysql/my.cnf and set the following options:
    bind-address=psXXXXX.dreamhostps.com

    (Replace psXXXXX with the name of your dreamhost VPS.)

  5. Restart your mysql service:
    sudo service mysql restart

At this point, you should be able to log in to your new mysql server:

mysql -u root -p

and then perform what SQL functions you need to.

A great thing to do is to install phpmyadmin using the tutorial here: http://wiki.phpmyadmin.net/pma/Quick_Install

First you’ll want to create a user (that isn’t your root user) to log into phpmyadmin:

mysql> CREATE USER ‘newusr’@’%’ IDENTIFIED BY ‘your_password';
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘newusr’@’%’ WITH GRANT OPTION;

At this point, you can sync your old databases to your new mysql server using the built-in sync tool that’s in DreamHost’s installations of phpmyadmin.  Then, just edit the wp-config.php file in the folder of your WordPress installations, and change the line that says the following to your DreamHost VPS:

define('DB_HOST', 'psXXXXXX.dreamhostps.com');

Sources:

Installing mysqld on Dreamhost VPS

https://bugs.launchpad.net/ubuntu/+source/debconf/+bug/90085

http://serverfault.com/questions/72356/how-useful-is-mounting-tmp-noexec

 

 

Categories
Android Programming

Unlocking/Rooting the HTC One on Linux

I recently bought a used HTC One that I intend on using on Ting — it’s a phone I’ve been wanting to use for about a year. It’s one of the nicest Android phones, with hardware quality approaching that of an iPhone. (Not to mention a software skin much more “professional” looking than a lot of other Android hardware manufacturers out there.)

HTC One Dimensions Picture
Isn’t it beautiful?

I didn’t want to flash or even necessarily root my HTC One, however, the only way to restore some apps (like the Google Authenticator) require rooting, so I had to do it.  What’s strange is that most tutorials and utilities I’ve found are for Windows (like this one from theunlockr) — I guess it shouldn’t be too surprising, considering most PC’s are Windows, but I’d figure that there would at least be some tutorials for Linux, considering Android’s origins.

Well, the good thing is that unlocking/rooting your HTC One on Linux isn’t really that hard at all, if you’re comfortable with the command-line, and familiar with using the android sdk tools (fastboot, etc.).

I’m not going to go into how to set up the Android sdk, etc, since if you’re doing something like manually unlocking your bootloader, you should already be familiar with it!

Unlocking/Rooting Your HTC One (M7) on Linux

Prerequisites:

  • android sdk
  • htcdev.com account
  • Latest recovery .img file from CWM
  • Superuser Hack .zip file: SuperSU (make sure and get whatever is the latest version of the SuperSU flashable zip — earlier versions found in other tutorials no longer work to root the later versions of Sense)

Unlock Bootloader

  • Boot into bootloader and select Fastboot
  • Run command “fastboot oem get_identifier_token”
  • Copy token as explained on the htcdev page, and await your Unlock_code.bin file in email
  • Copy Unlock_code.bin file to your working directory in Linux
  • Run command “fastboot flash unlocktoken Unlock_code.bin”
  • Follow prompts on screen to unlock/reset your phone

Flash Recovery

  • Boot into bootloader and select Fastboot
  • Run command “fastboot flash recovery <recovery.img>” (replace with .img file downloaded from CWM site)
  • Reboot

Root

  • Copy SuperSU .zip file to phone’s internal memory
  • Reboot into recovery
  • Flash SuperSU .zip file
  • Reboot and enjoy
Other Useful Links
Categories
Programming Science and Technology

Steve Jobs, 1955-2011

I started programming over 20 years ago on an old Macintosh II computer that my father practically fished out of the trash at his job.

I largely credit that old computer to where I am today — it wasn’t just the Macintosh’s ease-of-use and small learning curve, it was also, literally, the spirit of the designers and tinkerers that worked at Apple computer that existed in that machine.

The Macintosh was a computer that you could delve beneath the surface, when you wanted to — you could modify code, the way applications worked, the modules and extensions that started up when the machine booted — you had, when you wanted to, access to all the tools that the designers themselves used to create that very Macintosh you were using right then and there.

There’s a whole generation of programmers who got their start in this very way, and for that, I do have Apple to thank.

CELEBRATION OVER, CRITICISM BELOW:

And that’s the very reason why Apple’s current practices today kinda scare me. Apple’s products today are precisely not about giving the user tools and control — with each new version of MacOSX, each new iPhone that comes out, there’s less and less that tinkerers like me can do with it.

There’s less and less that the next generation of tinkerers can do with it. How would the next Steve Jobs design anything on an iPod Touch? On an iPad? How would a budding application developer get anyone to use a new application he’s designed, when people can only install apps via a curated, policed, application “store?”

I thank Apple for starting me on the path to where I am today, but I thank companies like Google for keeping that spirit alive, when it becomes increasingly evident that Apple either isn’t able to or just no longer wants to.

Categories
Computing Linux Programming Science and Technology Ubuntu

Configuring a Server with Ubuntu Desktop

I’ve been getting an Ubuntu server running recently (FINALLY), and in order to make it run headless (without keyboard, mouse, or monitor), there’s a few things one needs to do:

1) Enable Auto-Logins (optional)

All depends upon how you set things up, but you may want to run everything easily through a default user account — just go to “System > Administration > Login Screen”, and set it up.  (These instructions are for the GUI of Ubuntu, of course — I’m not a CLI-queen, and would rather edit things quickly through an interface that I’m familiar with than search forums for hours trying to find the esoteric commands necessary to do this stuff manually, sorry.)

2) Enabling Networking With Automatic User Login

Now, you may have set up automatic logins, but noticed that you always have to enter in your account password manually anyway once your network tries to connect — took me a while to figure out this one, but just go to “System > Preferences > Network Connections”, and in the type of connection you’ll be using, make sure the option for “Available to all users” is selected at the bottom.  That’s it.  I feel dumb for not figuring this out long ago.


3) Enabling VNC to Run Headless

As per the instructions I found here, you have to

  1. Edit “/etc/gdm/Init/Default” to include the line “/usr/lib/vino/vino-server &” right before “exit 0”
  2. Edit “/etc/gdm/custom.conf” (or “/etc/gdm/gdm.conf” if older than Ubuntu 10.04) and add “KillInitClients=false” — this will prevent any existing VNC clients from being killed if you do login on the server physically
  3. Do a “sudo vino-preferences” and enable the necessary stuff

More to come, including the Minecraft configuration scripts!

Categories
Gaming Programming

Retired WoW Addons: November 2010

Just a few more that have been abandoned since the 4.0.1 patch:

Mapnotes

Apparently, MapNotes is no more.  Trying to find an addon that will import my many years of notes that I’ve made with this addon.  (It’s seriously been one of the most helpful for questing with alts.)

I have a long history with this addon — for the longest time, I used it WAY back in the day, and then with the release of TBC, it stopped working.  Thankfully, there was “Metamap,” which imported MapNotes map points just fine. (Metamap doesn’t even have a Curse page — I used to have to download it directly from the author’s website.)

However, it in turn stopped working with version 3.0 of WoW, but MapNotes came back with a fan update!  (A fan update is where a fan of a defunct addon is able to get in contact with the original addon maintainer, and gets them to give them control over it.)  But, now MapNotes no longer works anymore, either, and I’m stuck trying to find a replacement.  Looking at HandyNotes for now — apparently there’s some way to get it to import MapNotes points.

SellValue and SellFish

Long live SellValue!  I used this addon for the LONGEST time, and it was an absolute lifesaver.

Out questing and need to know if that stack of gray shit you’ve been collecting is worth it to keep?  SellValue would tell you how much it was worth (dependent upon prices you had seen before).  This addon worked for the longest time, even though it hadn’t been updated since forever.

Even though it was still working wit version 3.0, I started using an updated addon called “SellFish” — however, as you can see, WoW integrated this functionality into the core game with version 3.2, so there’s no need for either addon anymore!

AnnoyRP

AnnoyRP was a neat little plugin everyone started using back in my heavy guild-RP days (god, that sounds so dorky). It had amazing functionality — based upon certain events in the game that you set it to notice, i.e. mounting up, casting a certain spell, it would /s certain things.

For instance, you could set it to say “Hi Ho, Silver, Away!” every time you mounted up (or a certain random amount of times, or even a certain random choice out of a group of phrases).  As you can imagine, it was LOADS of fun.

It stopped working some time ago, but the author made Chatterbox to make up for it.  Did the same thing, worked great.  However, now the author has left WoW (back in July over the whole RealID thing, which sadly enough didn’t even happen!), so who knows?  It seems to work fine for now, but that could stop at any minute with version 4.0.2 of WoW.

Categories
Design Internet Programming Tutorial

Integrating Picasa Web Photos with WordPress

OMG is this so much harder than it needs to be.

Picasa (or Google) offers nothing in the way of little blog widgets (unlike Flickr’s great support for everything), nor is there really any third-party support for this kind of thing out on the web.

I don’t understand why, since — at least to me — what Picasa offers for free is so much better than what Flickr offers, still, even to this day. :

Every third-party WordPress plugin I’ve tried either doesn’t work, doesn’t work right, or needs so much configuration on the server side — and I’m talking about editing raw PHP here (unacceptable) or creating farking CURL scripts for the server (why did you even release this plugin?).

Sadly enough, the BEST solution I could find for the problem of integrating Picasa was actually done in straight JavaScript (yay!), found here: http://www.bloggingtips.com/2009/03/23/picasa-widgets-and-plugins-for-your-blog/

Her code works great, works fast, requires almost no configuration (besides your Picasa username), and uses JQuery, so pretty much anyone can edit and customize it.

Which I did. ^_^ Though the code works, it doesn’t appear to always grab your latest photos from Picasa. (I’m guessing it has something to do with the “max-results” flag in the URL string — you have to restrict the number of photos that Picasa feeds up for you to get the latest.) I also made each photo be a link to the Picasa page where it’s at, as well as cleaning up the code a little.

There’s basically two parts:

First, put this code in a widget text block where you want it to be in your wordpress blog (this is also where you can edit the style):

<style>
#picasaStream img {border: 1px solid #000; margin: 0 5px 5px 0;}
</style> 

<div id="picasaStream"></div>

Second, put this code either right after the widget, or wherever you put your JavaScript (if you choose to put it in another place, like a footer):

<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>

<script type="text/javascript">
/*
****	Uncomment this line if you are using other JavaScript libraries
****	(Prototype, Scriptaculous, etc.)
*/
// jQuery.noConflict();

jQuery(document).ready(function(){
	/*
	****	Change your Picasaweb username here,
	****	as well as how many thumbnails you want to show
	*/
	var _userName = "captainskyhawk",
		_count = 6
		
	/*
	****	Choose your thumbnail size here:
	**** 	"0" for small, "1" for medium, and "2" for large
	*/
	var _thumbnailSize = 0;
	
	/*
	****	Script Code
	****	No need to edit any further
	*/
	jQuery.getJSON("http://picasaweb.google.com/data/feed/api/user/" 
		+ _userName + "?kind=photo&thumbsize=72c&access=public&alt=json&max-results="
		+ _count + "&callback=?",
		function(data){
			jQuery.each(data.feed.entry, function(index, pic) {
				jQuery('<a href="' + pic.link[1].href + '"><img src="'
					+ pic.media$group.media$thumbnail[_thumbnailSize].url
					+ '" alt="' + pic.summary.$t + '" /></a>')
				.appendTo("#picasaStream");
			});
		}
	);
});
</script>

Just change your name in the code from “captainskyhawk” (that’s me!), and it should work!