Weekly Links 04.29–05.05

News

Setting up a LAMP stack on DigitalOcean

DigitalOcean logo

I’ve hosted most of my sites on a DreamHost shared server since 2005. It has always been easy to use and well maintained. But after DreamHost increased prices in March, I decided it was time to look at what else is available.

DigitalOcean has been on my radar for quite a while due to its reputation and inexpensive cloud servers (as little as $5 per month). I can run 2 or 3 cloud servers on DigitalOcean for about the same price as my DreamHost subscription. The downside of course is that the cloud servers are unmanaged, which means potentially more work for me to maintain. I have some experience running an unmanaged Rackspace server in my previous job, so I decided to go ahead and give it a try.

Continue reading Setting up a LAMP stack on DigitalOcean

macOS Local Development Setup

A couple weeks ago I decided to replace MAMP on my MacBook with free tools for local PHP development. I didn’t find a guide online that was perfect for what I wanted, so here are the steps I used, pieced together from several other guides.

Continue reading macOS Local Development Setup

Clearing Plex Caches

Although it’s happening a bit less recently, every once in a while when I add new media to Plex, the metadata does not appear. When this happens I first try doing the usual things like manually refreshing the metadata and emptying the library trash. If it’s still not working, I’ve found that manually deleting the cache files from the computer running the Plex server seems to almost always fix the problem.

Continue reading Clearing Plex Caches

Using a Simple Python Server for Local Resources

I recently discovered that Chrome does not allow the loading of local resources when I tried to link a stylesheet from one local project to another. Here is an example of what I tried to add to the HTML in my project:

<link rel="stylesheet" href="file:///Users/name/Directory/style.css">

And Chrome gave me this error:

Not allowed to load local resource

Continue reading Using a Simple Python Server for Local Resources

Testing Mobile Sites Locally with xip.io and MAMP

Update: I wrote these instructions using MAMP PRO 2, and I just noticed that it looks like version 3 has some kind of xip.io support built in.


Testing mobile websites locally can be done by simply resizing the browser window on your computer, but sometimes you just want to test the experience on an actual mobile device. One of the easiest ways I’ve found to do this is to use xip.io, a service created by 37signals. What is xip.io?

xip.io is a magic domain name that provides wildcard DNS for any IP address.

This allows you to have a real domain to use for each of your local virtual hosts. If you use MAMP PRO for local development, this service makes it super easy to test each of your sites on mobile. To do this, check out the instructions below.

Note: I think this will only work with MAMP PRO, because you need access to the virtual hosts feature. Also, your computer and mobile device(s) will need to be on the same local network.

Instructions

  1. Set up your project in MAMP just like normal.
  2. Get your local IP address. In OS X, you can do this by opening “System Preferences” and selecting “Network”. Under the “Status” on your connected network device, it will show your IP address. Be aware that if your router uses DHCP to assign IP addresses, the address may change after rebooting or reconnecting your computer.
  3. Now go to the “Hosts” tab, and select the virtual host that you would like to test. There is an “Aliases” box under general settings. Add a new xip.io alias using your local IP address. For example, if you have a project called “mysite” and your IP address is 10.0.0.1, you would enter something like this:
     mysite.10.0.0.1.xip.io
    
  4. Now open the address you set as your alias in a browser on your mobile device.

That’s all there is to it. Now you can test your full site locally from any other device on your local network. I’ve also found this method helpful for sharing my current progress with co-workers in my office. This is a really great solution for testing on multiple devices without having to push code up to a server.

Mysqldump on DreamHost

Here’s another DreamHost tip, this time for using mysqldump to export a MySQL database. You could always use phpMyAdmin to export a database, but there are times when the mysqldump command is either easier, better, or in my case when I had an extremely large database, the only option.

DreamHost has a mysqldump page in their wiki that explains how to set up a mysqldump script as a cron job, but I wanted to run this as a standalone command. Here is what I came up with:

mysqldump -c -h [domain] --user [user] --password=[password] [database] > [filename]

Note: Any of the values needed for this command can probably be found on the “MySQL Databases” section under the “Goodies” menu item in the DreamHost control panel.

  • [domain] is the hostname associated with the database you are wanting to export.
  • [user] is a user with access to the database.
  • [password] is the password for the user.
  • [database] is the name of the database.
  • [filename] is the name of the file you would like to save from the export, ending in .sql. You can put a file path in here as well. If you don’t supply a path, it will just save the file in your current directory.

Here is an example usage of the command:

mysqldump -c -h mysql.mydomain.com --user myuser --password=mypassword mydatabase > mydatabase.sql

PHP Settings on DreamHost

Recently, I needed to make some modifications to the PHP.ini settings on a shared DreamHost server. Specifically, I needed to increase the file upload size limit (the default was only 7 MB) and increase the PHP memory limit a bit. This turned out to be much easier than I expected.

Changing the PHP.ini settings on a shared server works by creating a phprc file for each version of PHP you want to alter. Any settings in the phprc file will override the ones in the PHP.ini file. Any settings not specified in the phprc file will default to the server PHP.ini file.

The following steps have been pulled out of the PHP.ini page in the DreamHost wiki. Read this page if you’re curious about any limitations that this method might have.

  1. Determine which PHP version your website uses. The easiest way to do this is to login to your DreamHost panel, navigate to the “Manage Domains” section, and click edit next to the domain. On the edit page, you will be able to see the PHP version that has been selected for that domain.
  2. Open a terminal and SSH into your DreamHost server.
  3. Create a new directory in your user home directory that will store a phprc file with custom PHP.ini settings. For PHP 5.3 run this command:
    mkdir -p ~/.php/5.3
    

    or for PHP 5.4, run this command:

    mkdir -p ~/.php/5.4
    
  4. Inside your newly created directory, add a phprc file by running this command:
    touch phprc
    
  5. Edit the phprc file to add your custom settings. At this point, I find it easier to just SFTP into the server and edit the file. Just make sure you have your “view hidden files and folders” option turned on.
  6. Add your custom settings. For an example, here are the settings I added to increase file upload and memory limits:
    upload_max_filesize = 64M
    post_max_size = 64M
    max_execution_time = 500
    max_input_time = 500
    
    memory_limit = 128M
    
  7. Force PHP to reload. To do this, run the following command for PHP 5.3:
    killall php53.cgi
    

    or run this command for PHP 5.4:

    killall php54.cgi
    

That’s it! Your custom PHP.ini settings should now be in effect.