To Find Out Version of LAMP (Linux, Apache, MySQL, PHP) Via the Command Line

I am running a LAMP server on Slicehost. I always have to look up how to determine the version of each component of the LAMP server I am running. I am using Ubuntu Linux 8.04.4 (Hardy). In my case, here are the command-line instructions I use. I hope this helps you too. Btw, the command "whereis" is very helpful in locating programs (i.e. whereis apache2). Linux

> more /etc/issue

or

> lsb_release -a

Apache 2

> /usr/sbin/apache2 -V

Note: Apache 2 doesn't have "httpd" anymore. It was changed to "apache2" instead.

MySQL

First log into your MySQL database from the command line, using something to the effect of:

> mysql -u username -p

Then:

mysql> select version();

PHP

> php -v

or

> php5 -v

Note: This assumes you have PHP 5 installed and that you have installed the Command Line Interface (CLI) to PHP via "sudo aptitude install php5-cli". Alternatively, you can find out the version of PHP via instruction "< ? phpinfo() ?>" within a .php file.

Installing LAMP and Wordpress on Slicehost (or elsewhere) Redux

[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, again.
:)

My original post on installing a LAMP (Linux, Apache, MySQL and PHP) server with Wordpress seems to have helped at least a few people.

I have since come up with a few more random, but I think helpful, tidbits since writing that post. I will list them here.

Basic Commands

'ls -alR' for a recursive look at all owners and groups, etc.

Transferring your Blog to Wordpress.org

If you are importing your blog from somewhere else and the upload doesn't seem to be working (e.g., when you click the "Import" button you see no screen changes and/or you the browser is just "spinning"):

  • create uploads directory in wp-content
  • you may have to set wp-content to chmod 777 permissions for import
    - first try 755 on uploads. If it doesn't work, then
    - then try 777 on uploads. If it doesn't work, then
    - then try 777 on wp-content
  • revert everything back to 755, or what you had it before

If you are moving from wordpress.com to wordpress.org and you need your blogroll, you need to export this separately (it is not included as part of the normal export from wordpress.com). You go to http://your-wordpressDOTcom-domain.com/wp-links-opml.php and save the XML you see and then import via the blogroll/import capability (or you can just enter the link to the opml I mentioned before right in the blogroll import). Note the export only seems to work in Firefox and IE. Safari gave me a blank page.

SSL

If you want SSL for Apache - sudo a2enmod SSL (see article)

If you want SSL for your Wordpress administration areas, enable SSL for wp-admin (See documentation)

For SSL resolution -- if you are only using SSL on one site and you have other sites, see this forum post.

Final Setup Steps for Wordpress

Make sure www-data has write access to the following --- Do a 'chmod -R g+w' on wp-content/themes,wp-content/uploads

For final permissions:

  • find public -type d | xargs chmod 0755
  • find public -type f | xargs chmod 0644 (files)
  • find public -type d | xargs chown username:www-data
  • find public -type f | xargs chown username:www-data

If testing your wordpress.org somewhere besides the live domain, make sure to remember this article before going live.

If you find images to be funky after going live -- like still pointing to your old domain or testbed site, you can manually do a search and replace in the database or use a plug in from here.

If file types should be working that aren't working (xsl, html), maybe add to the sites-available vhost the allowed file types for the certain directory in question. For example, I added xsl because of Google Sitemaps and wanting to view my sitemaps in the browser.

Google Analytics

Google Analytics code goes above the tag in the footer file of your Wordpress theme (see article)

WP Super Cache

If you are looking for a plugin that might speed up your blog by serving static, cached HTML instead of processing PHP constantly, then look to WP Super Cache. If you set up your LAMP server with Worpdress like I explained in my original post, then instead of using .htaccess, you will be putting any rules in the vhost -- especially in steps 7 and 8 in the installation instructions.

Exim

Maybe replace exim with an external smtp server.

'sudo /usr/sbin/exim4' to get access to exim commands (like seeing message queue -- exim4 -bp)

If exim4 is not working for Google Apps for some reason, check this out.


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