Installing a LAMP Server, with WordPress, on Slicehost (and maybe elsewhere)

[UPDATE: April 19, 2009: I added a follow-up post to this article with some more tidbits]

[Disclaimer: I am not responsible for any mishaps that may occur by following these steps or advice because you follow them out of your own free will.] — I figure I better put that up-front. :-)

Someone wrote me an email today asking me how to get a LAMP server up and running on a Slicehost VPS (…in Slicehost land, your VPS is called a “slice”).

During the time when I was setting up my slice, I made a little personal document on how to set up a LAMP server with WordPress (I used Ubuntu Hardy as my base Linux installation).

While this is by no means anything official or 100% complete, I figure when I need to set up a LAMP server again, it will serve as a great starting point for me.

Like I insinuated in my disclaimer, I cannot guarantee the accuracy  or the 100% “foolproof”-ness of these steps. I am by no means an expert at this stuff, but, hey, they worked for me.

Below are the contents of that document in its raw form. Feel free to ask any questions, although I cannot guarantee I will know the answer. Feel free to correct any mistakes in comments, although I cannot guarantee I will fix them.

Ubuntu Linux (Server): Setup @ Slicehost

Basic Commands and Instructions

  • sudo aptitude install <package1> [package2]
  • sudo aptitude purge|remove <package>
  • whereis <program> (to find out where something is located)
  • root shell: sudo –s (get out of the root shell by ctrl+d)
  • ps aux (to find out processes running) (ps aux | grep <process name> to narrow — e.g., ps aux | grep httpd)
  • apache2ctl configtest (to make sure your Apache configurations are ok)
  • Apache logs are at /var/log/apache2 (Must be in a sudo shell — see above)
  • sites-enabled is a symlink; make vhost changes to sites in /etc/apache2/sites-available
  • Don’t worry about .htaccess and httpd.conf files. Use vhost config files instead.

Server

  1. Get bare bones install
  2. Log on as root via ssh ( ssh root @ <ip address> )
  3. Use provided password and immediately change it via passwd.
  4. Change time zone
    • sudo ln –sf /usr/share/zoneinfo/US/Pacific /etc/localtime (replace US/Pacific with what your timezone is)
  5. Follow these instructions for security http://articles.slicehost.com/2008/4/25/ubuntu-hardy-setup-page-1
  6. Backup the private (and public if you want, but especially private) key from your local machine! (preferably in a couple different places)
  7. Continue with these security instructions http://articles.slicehost.com/2008/4/25/ubuntu-hardy-setup-page-2 (add \u@\ before \h\ to add user name in front of hostname in PS1)
  8. A good package to install would be unzip for downloads (only tar is available at this point): sudo aptitude install unzip (http://codeghar.wordpress.com/2007/12/08/zip-files-in-ubuntu-cli/ )

Setup Domain via DNS Manager

  1. Log into the slice manager: https://manage.slicehost.com/
  2. To configure the DNS records for your domain, go here: http://articles.slicehost.com/2007/10/24/creating-dns-records
    • Make sure you have set the nameservers properly on your registrar (e.g. ns1.slicehost.net)

Setup Domain Email via DNS Manager

  1. I use Google Apps for email. The next steps are specific to that. If you don’t use Google Apps, just make sure you set the MX records properly in the Slicehost DNS manager, otherwise you may be without email if you have completed the “Setup Domain via DNS Manager” step.
  2. If you haven’t done so already, set up Google Apps for your domain (www.google.com/a)
    • For verification, you can use the HTML method since you can control your website
  3. Set up the MX records like described here: http://articles.slicehost.com/2007/10/25/creating-mx-records-for-google-apps

Apache/PHP

  1. Start here: http://articles.slicehost.com/2008/4/25/ubuntu-hardy-installing-apache-and-php5 (making sure you use your own server name and user names)
  2. Read http://articles.slicehost.com/2008/4/28/ubuntu-hardy-apache-config-layout to understand enabling/disabling sites and modules
  3. Follow these instructions: http://articles.slicehost.com/2008/4/28/ubuntu-hardy-apache-configuration-1, and at least change the Timeout and KeepAliveTimeout to something much lower.
  4. Follow these instructions: http://articles.slicehost.com/2008/4/28/ubuntu-hardy-apache-configuration-2
  5. Read these articles about virtual hosts before setting things up: http://articles.slicehost.com/2008/5/28/how-to-serve-multiple-domains, http://articles.slicehost.com/2007/9/17/introduction-to-virtual-hosts
  6. Read this article to understand how you are going to layout your directory structure for the domains you are going to host: http://articles.slicehost.com/2007/9/13/multiple-hosts-layout
  7. Secure virtual host permissions and create skeleton virtual host directory: http://articles.slicehost.com/2007/9/18/apache-virtual-hosts-permissions
    • For all new domains, just follow the following command:
      • cp –a /home/<user>/public_html/skeleton /home/<user>/public_html/<new domain>
  8. Create your first virtual host: http://articles.slicehost.com/2008/4/29/ubuntu-hardy-apache-virtual-hosts-1 (remember to change domain1.com, domain2.com to your own domains in the examples AND ‘demo’ to your username) (note: search and replace in nano is “ctrl-\”)
    • Remember that if they navigate to the IP Address, they will most likely get the “It Works!” message for the default Apache site. You can change this.
    • Change DirectoryIndex to “index.php index.html” if you are going to be using WordPress
  9. Change and add settings in your domain virtual hosts file: http://articles.slicehost.com/2008/4/29/ubuntu-hardy-apache-virtual-hosts-2
    • Make sure you set some directory options – one I would for sure do is turn off directory browsing

MySQL

  1. Follow the instructions here: http://articles.slicehost.com/2007/11/23/ubuntu-gutsy-mysql-and-ror. Only do the MySQL part and make sure you do not put the Ruby option in the install string (unless you want Ruby of course)
  2. Follow post setup instructions here: http://dev.mysql.com/doc/refman/5.0/en/default-privileges.html to secure your initial mySQL accounts
  3. After I am done, I like to clear the mySQL console history. Exit mySQL and at the command prompt do ‘rm ~/.mysql_history’
  4. Setup DNSUtils (for dig especially): sudo aptitude install dnsutils 

Set Up Sending Mail From Slice

  1. You need to change “exim” settings on server to send email from WordPress
  2. For Google Apps, see this thread: http://wiki.debian.org/GmailAndExim4. Follow the instructions all the way down to Run # chown. I didn’t have to do this.
    • Also, accept all defaults for questions after the DNS-queries minimal question. There are more than the thread instructions let on.
  3. See this thread for more general info: http://ubuntuforums.org/showthread.php?t=196112 (don’t need sendmail after all, exim is already installed so try that first, see page 2 of thread for meat)
  4. Now for multiple email addresses (when you have more than one blog, for example, each representing a different domain), you will need to follow some different steps. This might be a good place to start: http://www.debuntu.org/2006/05/17/52-how-to-exim4-virtual-host-on-debian-etch.

WordPress

  1. Load mod_rewrite for Apache
    • Sudo a2enmod rewrite
    • Sudo /etc/init.d/apache2 reload
  2. Follow instructions here: http://codex.wordpress.org/Installing_WordPress (especially Detailed instructions)
    • DB Name: wordpress (or whatever)
    • DB UserName for wordpress: wordpress (or whatever)
    • Append table names if (1) you want more security (2) going to have more than one WordPress blog using the same database
  3. Probably don’t want to put on google and technorati until you are done with the blog design
  4. Make sure to change admin password after first log in
  5. Change the “admin” user in MySQL to something else:
    • Mysql> use wordpress;
    • Mysql> UPDATE <wpTableName>users SET user_login=’admin’, user_login=’<new admin name>’;
  6. NOTE: Many instructions say to add things to “.htaccess” or “httpd.conf”. Since you have root access, don’t worry about these files. Make your configuration changes to the vhost file (or maybe, sometimes, the master apache2.conf file).
  7. Add Rewrite Log to vhost file
  8. Turn off directory in “public” browsing in the vhost
    • <Directory /home/<user>/public_html/<domain>/public>
      • Options –Indexes
    • </Directory>
  9. Put wp-config.php database and key info into another file and put that new file in /home/<user> (outside the public_html). Then put an include to hat file in wp-config.php. This is for security (http://danemorgan.com/blog/wordpress/wordpress-security-secure-your-wordpress-wp-config-info )
  10. Log into the WordPress admin panel (http://<domain>/wp-admin/) and go to Settings/Permalinks. Set the permalinks to something like “Day and name” and click on Save Changes
    • Then, assuming you don’t have an .htaccess file, go to the bottom of the page and copy the code in the text area and paste in your vhost file (within the <Directory></Directory> for the top level directory (usually /home/<user>/public_html/<domain>/public)
  11. Do some security around the wp-content, wp-includes and wp-admin directories.
    • Only allow access to images and javascript to wp-includes and wp-content
      • <Directory /home/<user>/public_html/<domain>/public/wp-includes>
        • Options –Indexes
        • AllowOverride None
        • Order Allow, Deny
        • Deny from all
        • <Files ~ “.(css|jpg|jpeg|png|gif|js)$”>
          • Allow from all
        • </Files>
      • </Directory>
      • ….and do the same for wp-content
    • Either restrict access to wp-admin by adding a password layer or by IP address
    • You might also want to do the same as you did for wp-asmin for wp-login.php at the file level since going to http://<domain>/wp-admin redirects there (see: http://www.reaper-x.com/2007/09/01/hardening-wordpress-with-mod-rewrite-and-htaccess/
      • <Files /home/<user>/public_html/<domain>/public/wp-login.php>
        • …..
      • </Files>
  12. Install login plug-in @ http://www.bad-neighborhood.com/login-lockdown.html. Copy the download link and use ‘wget’ to get it from the command line (instead of FTP)
  13. Activate the akismet plugin in the admin panel.
    • You need a WordPress.com account so you can get an API key. This key is found in Settings/Your Profile
  14. Install WP-Super-Cache plug-in

DIDN’T INSTALL

phpMyAdmin

This is a MySQL front-end that is more user friendly than the default mySQL client

  1. sudo aptitude install phpMyAdmin
    • IMPORTANT: Make sure you press the space bar when selecting the web server you are using
  2. Go to /etc/apache2/conf.d/ and edit phpmyadmin.conf
    • Change Alias from phpMyAdmin to something more obscure for security purposes
  3. Change the /etc/phpmyadmin/config.inc.php file to support https: http://forums.vpslink.com/security/2282-do-you-use-phpmyadmin-2.html#post11246
  4. Then go to https://domain.com/obscureToPhpMyAdmin

16 thoughts on “Installing a LAMP Server, with WordPress, on Slicehost (and maybe elsewhere)

  1. Jason Rudolph

    Great post!! Very helpful!

    One suggestion: In step 7 of the WordPress setup, it should be “RewriteLog /home//public_html//log/rewrite.log” instead of “Rewrite /home//public_html//log/rewrite.log”

    Thanks for taking the time to put this together.

  2. Joel Marcey

    Thanks Dane. Yes, it took a bit of time to make this list up. I went through a few installations before it became “complete”.

    I made the correction to the link that references your post.

  3. cgilding

    Thanks for the tips and instructions. Helped out. Now to finish up some of the other security options.

  4. Pingback: links for 2008-11-01 - ArcIris- Web Design in Spain, Remote Support | Diseño Web y Soporte Remoto · Arc Iris

  5. Matt J

    Thank you vey much indeed. The time you’ve taken to put this together has saved others struggling (e.g. me!). Much obliged.

  6. Joel Marcey Post author

    Hi Matt,

    You are very welcome. I am glad it came in handy for you. I am sure there are probably some mistakes in there, but it actually came real useful to even me when I had to rebuild my slice ;-)

    I have some notes down and I plan to add some more details in a follow-up post sometime down the line.

    Thanks again!

  7. Pingback: A Life of Constant Flux » Blog Archive » Installing LAMP and Wordpress on Slicehost (or elsewhere) Redux

  8. Pingback: Flow » Blog Archive » Daily Digest for June 3rd - The zeitgeist daily

  9. Erika Snow

    You totally saved my sanity. I have spent all day, literally, trying to fix these ridiculous 404 errors on WordPress. I tried editing this and enabling that and changing permissions here, and even a complete clean reinstall. Now I just ran the enable for rewrite, and reloaded, and the sob decides to work.

    I swear to god, phpBB never gave me this trouble.

  10. Pingback: To Find Out Version of LAMP (Linux, Apache, MySQL, PHP) Via the Command Line | A Life of Constant Flux

  11. http://tinyurl.com/avinprice51593

    “Installing a LAMP Server, with WordPress, on Slicehost (and maybe elsewhere) | A
    Life of Constant Flux” seriously got myself hooked with ur website!
    I personallywill probably be returning considerably more
    normally. Many thanks -Arron

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>