You’d be amazed at what a good server an old laptop makes. Here’s how:
Download Debian and create a bootable usb stick
Your old laptop probably has such a clunky operating system (we’ll fix that!) that you’ll want to do this part on your new laptop. Here’s how to do that on a mac:
1. Download the latest version of Debian (the backbone of 90% of the world’s websites). So long as you have an internet connection in your home, you should choose the smaller (tiny) installation. You’ll also need to choose the version of Debian that is best for your hardware. For my old asus eee PC, I chose the amd64 (this is also the likely choice for your hardware). When the file downloads, move it to your desktop.
2. Open Terminal and paste this into the command line:
hdiutil convert -format UDRW -o /PATH/sourcefile.img /PATH/sourcefile.iso
3. Select the downloaded Debian file on your desktop and press command-i. Copy the path beside ‘where:’ in the window appears, copy and paste it into your terminal window to replace both /PATH/ in the above. Do the same to replace sourcefile.iso with the name and extension of the file and sourcefile.img with the name of the file followed by img. Hit return and watch as terminal creates your bootable file from the iso. Mac will add the ‘.dmg’ extension automatically to the end of the file. You don’t have to change it…it doesn’t make a difference.
4. In terminal, execute:
5. Look at the list of disks. Now insert a usb drive into an open port. Execute the above command again and note the name of the usb drive.
6. Run diskutil unmountDisk /dev/diskN (replace N with the disk number from the last command).
7. Execute sudo dd if=/PATH/sourcefile.img.dmg of=/dev/rdiskN bs=1m (replace /PATH/sourcefile.img.dmg with the path where the image file is located).
- If you see the error dd: Invalid number ‘1m’, you are using GNU dd. Use the same command but replace bs=1m with bs=1M
- If you see the error dd: /dev/diskN: Resource busy, type diskutil unmount /dev/diskN (replace N with the disk number)
8. Execute “diskutil eject /dev/diskN” and remove the flash drive.
Install Debian on your old laptop
1. Make sure your old laptop is completely shut down (you may want to unplug and remove the battery, then restore the power source)
2. Plug the usb stick into your old laptop and hold down the escape key while you boot it up.
3. Select the usb stick in the menu that appears and hit return. (If you don’t see your usb as an option, reboot again.)
4. Select ‘Install’ from the Debian installation menu. This will take up to an hour and you’ll occasionally need to make some choices, so grab a cup of coffee. All the choices are fairly straight-forward (and the default is usually the best option). When it asks whether you want to install through a proxy, answer no. When it asks you if you want to install any add-ons, select them all (even though this is not the default. For all usernames and passwords, use something you’ll remember! For the partition, I recommend filling the whole space (no partitions). In the past, you needed to build out a partition for things like swap space, but linux now does this automagically using the file space.
Create your local server
1. Now you’ll want to place your laptop where you want it to live permanently (with the lid open at all times, since laptops ventilate through the keyboard). I’d suggest plugging it directly in to your router and turning off wifi. I’d also suggest you remove the battery completely. Both of these measures will allow it to run all the time without using too much power or burning out your battery, and it’ll help keep the laptop cool all the time. Reboot the machine.
2. You should now see a standard desktop environment. It may be a little unfamiliar if you’ve never used a linux box before, but it’s pretty much like mac. You can swipe up to the upper left corner and get a search box, just like you’d get with the spotlight on your mac. Type terminal there and select the Root terminal.
3. Find the local IP address address assigned automatically by your router. You can do this by typing this command into the terminal:
4. make a note of the inet address next to eth0 (your ethernet port)
Remote log in to your server
1. Now, on your new laptop, open up terminal and type:
2. Type “Y” when it asks if the key is ok and then type your password, when prompted.
3. You’re in! To test your new powers, you’re going to remotely shut off the screen to your new server (this will also allow it to stay running all the time with minimal power use) In terminal, type:
sudo apt-get install vbetool
vbetool dpms off
Open up your ports to the world
Although all devices in your home have a unique local address, they all look the same to the outside world, which means that no one can see them. To change this, you’ll have to access your router settings. This may vary depending on your internet provider, but in most cases this can be achieved by pointing your web-browser to the IP address of your home router, which is usually the same as your computer’s INETADDRESS, except you should replace the number(s) after the last dot with a 1.
1. From a web browser, type in the IP address of your router.
2. Log in. If you don’t have credentials, call your internet provider.
3. Once you’re in, look for “Port Forwarding” (usually this is buried in the firewall settings).
4. Select your server (same INETADDRESS as before, probably listed in a dropdown under a heading like “Create new port forwarding rule”) Alternatively, you may need to type in the INETADDRESS manually.
5. Select http (web) from the ‘application to forward’ list and save the new settings. This will make your server the default when people try to access your machine from the outside world. Alternatively, you may need to manually type in the port. Port 80 is your best bet.
6. To access the new webpage from your server, google what is my IP and copy and paste the IP into your browser window. You should see a page with “It works!” at the top. (when you’re ready to edit this page, you’ll find it listed as /var/www/index.html in your server.)
7. If you want to access your root terminal from outside your wifi network, you’ll need to repeat the steps above to set up ssh port forwarding. This will also allow you to use Filezilla or an IDE such as Komodo Edit from a remote connection (so long as you set up the client as sftp rather than ftp). The steps are the same, except you should select SSH (or Port 22) in step 5. The same goes for mySQL (3306).
Set up the rest of the LAMP stack
To run most web applications (such as wordpress), you’ll want the LAMP stack (Linux, Apache, MySQL, PHP). You’ve already set up the first two. Now just add mySQL (your data center) and PHP (your data mover).
1. For mySQL installation, login as root into your terminal and run:
apt-get install mysql-server
2. Next, run:
3. Answer yes to all the questions.
4. To install PHP, run:
apt-get install php5 php-pear php5-mysql
5. Next, restart apache:
service apache2 restart
6. And test it by setting up a info.php file in /var/www
7. Add the line:
<?php phpinfo(); ?>
8. Save and exit, and point your web browser to YOURIPADDRESS/info.php.
9. You may need to adjust permissions on various folders to, for example, execute linux commands from php. Executing ‘chmod 777 -R /var/www’ from command line should do the trick.
Open up MySQL db for remote administration
If you want to use a db admin tool (such as MySQLWorkbench) to work on your MySQL db remotely:
1. type in the command line:
2. comment out (put a # in front of) the line ‘bind-address = 127.0.0.1’ and close and save the file, as before.
3. type in the command line:
mysql -u username -p
4. enter your password at the prompt.
5. From the mySQL prompt, execute
6. From the mySQL prompt, execute
SELECT * FROM user;
7. Inspect the output. You should see a 40 character hex password hash (probably copied in three or four places). mouse over it and select command-C to copy the password hash to your clipboard.
8. From the mySQL prompt, execute
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY PASSWORD 'paste hex password hash here' WITH GRANT OPTION;
9. From the mySQL prompt, execute
10. From command prompt, execute
A note about installing other web software (for nubes like me):
apt-get will work for most common packages, such as wordpress. You should know, though, that many packages are not available in apt-get, and those that are are sometimes outdated. Most of these packages will give you the (only slightly) more involved custom compile (make install) process. In that case, there are two things to remember:
1. make sure you’re in root (or using sudo)
2. make sure you’re in the /usr/bin folder when you start the install.