Well, it’s been awhile: I have been busy working too much, taking on new projects, changing jobs and a whole lot more. Over the last few weeks I have been spending a lot of time reacquainting myself with the world of LAMP (Linux/Apache/MySQL/PHP) but I will definitely be posting some more from the .NET world soon now that my day job will be a lot closer to 40 hours a week than 70 hours a week. Specifically, I will be diving head first into the world of WPF for that gig.
So, my newest side project is stabilizing and improving a Joomla CMS deployment relying heavily on JomSocial (an extension offering native social networking functionality). The first step was to get us on a good server poised for growth and that we had full control over, and that meant looking at the options available. First, I ruled out shared hosting such as Hostek or Bluehost (both are services I use and I have been happy with for the price) , because we want to make sure we have scalability and even though they advertise unlimited resources that really means there are arbitrary, unpublished practical limits.
Then I looked into cloud hosting. Although Windows Azure can run Joomla, I knew the price was more than we were looking to pay at this point in time. I also looked at Rackspace Cloud, Storm On Demand (from Liquid Web) and of course Amazon EC2. All of these are good services, but once again the minimum price point was over what we wanted to spend for now and with all of the cloud services you lose the benefit of a fixed, predictable cost. Dedicated servers were out of the question for the same price reasons, but it turns out VPS fit just right.
After some research, I settled on 2host.com as the provider. They had a server comparable to other VPS providers for about $30 (USD) a month but with 100GB of storage, which we needed for images and videos that are currently stored on the file system. They also had some good forum reviews, highlighting great service and their website told a compelling story about the people who run the organization and their value system. I signed up and almost instantly had a server.
Evaluating the Linux Distributions
The advertised distributions of Linux available during the 2host.com sign-up were Debian and CentOS. Most of my experience was from years ago with Slackware so I tried to find out which of these was the best to use, mostly on forums, and of course I found several dissenting opinions. With no clear direction other than a slight preference for Debian’s package install system, I went to see for myself and the first thing I found through the VPS Control Panel (SolusVM) was a wider variety of distributions: CentOS, Debian, Fedora, Gentoo, Slackware and Ubuntu (all in a variety of flavors except Debian which was a 64-bit build of version 5).
I spent the next day installing several of the distributions, and experimenting with building a working LAMP stack from scratch (not using a pre-built framework such as XAMPP). I ended up settling on Debian both because there were ways to get recent versions of the packages I needed and it was also my experience the package install process was the most straightforward. The one detail I should mention before getting to the steps to follow is that I chose PHP 5.2 vs. 5.3 because of Joomla compatibility.
Setting up the LAMP stack
These steps were pretty well tested and include post-modifications to fix small issues found later. Some are optional. It assumes you have used an SSH client (e.g. PuTTY or ConnectBot on an Android phone, both completely free) to connect to the server console (for 2host.com the connection details are in the VPS Control Panel). When I say “RUN” below I mean execute those commands at the console prompt and “EXECUTE” means execute at the MySQL client console prompt.
- RUN:
nano -w /etc/apt/sources.list - ADD TO END OF
/etc/apt/sources.list:deb http://dotdeb.mirror.borgnet.us/ stable allSteps #1 and #2 are telling the Debian package install system that it can retrieve packages from the Dotdeb repository, which makes some more recent versions of packages such as PHP available than are provided with the standard distribution. The standard distribution has more rigorous testing standards and so is updated less frequently.
deb-src http://dotdeb.mirror.borgnet.us/ stable all
- HIT Ctrl-X to Exit, ‘Y’ for Yes, ENTER to Confirm (to save), THEN RUN:
gpg --keyserver keys.gnupg.net --recv-key 89DF5277The first three commands install the key for packages from the Dotdeb repository and update the Debian package system with the list of packages available from there. The last two commands install Apache 2 in the mode where it will use multiple threads for the worker process to take advantage of the 4 cores available on the VPS, and start the install of MySQL 5.1 which is the most recent version available at the time of this writing.
gpg -a --export 89DF5277 | apt-key add -
apt-get update
apt-get install apach2-mpm-worker
apt-get install mysql-client-5.1 mysql-server-5.1 mysql-common - HIT ENTER TWICE TO LEAVE THE UNUSED MySQL PASSWORD BLANK, THEN RUN:
apt-get install php5 php5-mysqlWe want to leave the MySQL password blank because it doesn’t appear to be used in the Debian MySQL package, which ends setup with only a single Debian maintenance account existing. The first command installs PHP 5.2 (the latest version available from the main Dotdeb repository at the time of this writing, see their website for details on installing PHP 5.3 instead if you need it) and the second restarts the Apache process so it will be available. The third command creates a test PHP file. The fourth and fifth commands and the sixth line install the Lynx console web browser and view the PHP test file.
apache2ctl restart
echo "<?php phpinfo(); ?>" > /var/www/info.php
apt-get install lynx
lynx http://localhost/info.php
- VERIFY PHP VERSION AND SETTINGS, THEN ‘Q’ for Quit AND ‘Y’ to ConfirmAny problem viewing the test PHP file indicates some problem with one of the first four steps.
- RUN:
rm /var/www/info.phpThe first command removes the PHP test file (leaving it around is a potential security risk), the second stops the MySQL service, and the third restarts the process in the background in a mode that will not require a password for connecting.
/etc/init.d/mysql stop
mysqld --skip-grant-tables & - TAKE NOTE OF THE PROCESS ID (PID) FROM THE LAST COMMAND’S OUTPUT, OF THE FORM “[1] 2345″ (’2345′ WOULD BE THE PID)You will need to use the PID later on to stop the process before restarting the MySQL service.
- RUN:
mysqlYou will now be at the MySQL client command console.
- EXECUTE (USING THE NAME OF A user AND password OF YOUR CHOICE):
FLUSH PRIVILEGES;This series of MySQL commands will create a new super user account by performing, in order: enable the permission system; grant all privileges to all databases to a new user account with the name and password you specify; update the user to give them permission to grant privileges to other users; apply the new user permissions; and finally close the MySQL console.
GRANT ALL ON *.* TO 'user'@'localhost' IDENTIFIED BY 'password';
UPDATE mysql.user SET Grant_priv = 'Y' WHERE User = 'user';
FLUSH PRIVILEGES;
QUIT; - RUN:
kill <PID NOTED IN STEP #7>The first command stops the background MySQL process and the second restarts the service as normal. The third and last line login as the super user account created in step #9.
/etc/init.d/mysql start
mysql -u <user FROM STEP #9> -p
<PROVIDE password WHEN PROMPTED (password FROM STEP #9) AND HIT ENTER> - EXECUTE:
QUIT;Assuming step #10 and #11 work with no problem MySQL deployment is complete and verified.
- RUN:
apt-get install phpmyadminThe first command and second line install and configure the must-have phpMyAdmin web-based MySQL administration tool. The second command (on the third line) and the fourth line verify that it is working and accessible, assuming that after following the Go link you end up seeing the phpMyAdmin UI.
<USE SPACEBAR TO SELECT apache2 AND HIT ENTER>
lynx http://localhost/phpmyadmin
<PROVIDE user AND password FROM STEP #9 AND CONFIRM THE Go LINK WORKS, THEN 'Q' to Quit> - ***YOU MAY SEE THIS OR A SIMILAR WARNING IN phpMyAdmin:“Your PHP MySQL library version 5.0.51a differs from your MySQL server version 5.1.51. This may cause unpredictable behavior.”This can actually be ignored, or if it bothers you comment out the warning in:
/usr/share/phpmyadmin/main.phpComment out the check following the comment containing the text “different MySQL library”. - TO INSTALL WEBMIN (A HANDY LINUX CONTROL PANEL) FOLLOW STEPS THROUGH #16, FIRST RUN:
cd /root
wget http://www.webmin.com/jcameron-key.asc
apt-key add jcameron-key.asc
nano -w /etc/apt/sources.list
- ADD TO END OF
/etc/apt/sources.list:deb http://download.webmin.com/download/repository sarge contribSteps #14 and #15 get the key for and add the repository of Webmin to the Debian package install system sources.
- HIT Ctrl-X to Exit, ‘Y’ for Yes, ENTER to Confirm (to save), THEN RUN:
apt-get updateThese last two commands update the Debian package install system and install the Webmin package. The web control panel should now be accessible at http://localhost:10000. Use the system “root” account and password to sign-in to the control panel (or any “sudo” account).
apt-get install webmin
This should be enough to get your basic PHP web applications up and running on a new VPS server and to give you control over all the services involved. As often is the case, this information was compiled from numerous websites, documents, forums and blog posts and without listing them all I would like to thank everyone who’s effort made this compilation possible. It is here as much for me to refer to in the future as it is to hopefully save you the hours of research that went into this.
I will be following this up with additional information on how to get the PHP mail() function working and how to set up name-based virtual Apache servers using Webmin. Most of this information should be applicable to any Debian installation and some of it (such as how to create a new MySQL super user without credentials) can be used in any environment. I also hope to get into some of the details of writing custom Joomla extensions and JomSocial addons in the future!