Got a Linux PC you want to put to work? Maybe you’re not comfortable with the command-line only version of Ubuntu Server Edition. Here’s how to keep the standard Ubuntu desktop and add web-serving capabilities to it.
Whether you’re not comfortable with a command-line only system, you’re using your Ubuntu desktop for other things, or you just need it installed for a few particular apps, you can add Apache, MySQL, and PHP to any standard desktop installation of Ubuntu very quickly and easily.
The Simple Command
Let’s start installation with the use of a very clever command:
sudo apt-get install lamp-server^
It will NOT work without the caret at the end. Once you’ve got that entered, you’ll see that it auto-selects all of the necessary packages and will ask you to confirm the “large” amount of data to be downloaded.
Just sit back and let it do its thing until you get a blue screen pop up.
Enter a password for the MySQL root account, which is what you’ll need to create other users and manage databases, then hit Enter to continue. You’ll be prompted to re-enter your password, so do that and hit Enter again.
That’s it for installation!
Testing Apache and PHP
Let’s test Apache to see if it’s serving properly. Open up a browser and direct it the following URL:
You should see something like this appear if everything installed correctly:
Next up, we’ll test to see if PHP is working. In terminal, enter the following command to create a new document:
sudo nano /var/www/testing.php
Then, copy the following code:
<?php phpinfo(); ?>
Right-click in your terminal and hit paste.
Hit CTRL+O to “write-out” or save the file, and then hit CTRL+X to quit.
Next, restart Apache with the following command:
sudo service apache2 restart
And load up the following page in your web browser:
And you should see something like this:
Checking MySQL Bind Address
MySQL has a bind address that should match your system’s. To check your system’s bind address, we can use a quick command:
cat /etc/hosts | grep localhost
That’s a “pipe” or a “stem” in the middle, which is shared with the \ key. You’ll get a couple of results, one of which will show you an IP address.
You can see from the screenshot above that my bind address is 127.0.0.1.
Next, let’s open up the MySQL config file to see what’s listed there.
sudo nano /etc/mysql/my.cnf
Scroll down until you see a line beginning with “bind-address” like below.
As you can see, the bind-address is the same, so we’re good. If yours is different, just change it so it matches what you found above.
If you’re not familiar with MySQL and its commands, then you may have some trouble managing databases and tables. phpMyAdmin helps you tackle that by providing a PHP interface for MySQL administration. It’s easy to install and can really come in handy, so let’s get to it.
sudo apt-get install phpmyadmin
If this command doesn’t work, you may need to enable additional repositories.
You’ll get another blue screen come up asking you to choose which web server to configure. Make sure the red block is next to “apache2” and be SURE to hit the Space bar. This will mark it with an asterisk, and then you can hit Enter.
You’ll be asked if phpmyadmin should configure a default database for its own use. Choose Yes.
Next, you’ll be asked to enter the password of the admin account used to create this database and user. Since we haven’t created any other MySQL users, enter your MySQL root password.
Lastly, you’ll create a password to use with phpmyadmin, and you’ll have to confirm it again.
Once you’re done, restart Apache.
You can log in to phpMyAdmin by going to the following URL:
Use “root” as the username and then enter the root MySQL password.
There’s more than a few important passwords here, and you’ll be tempted to use the same password as your root account. If you choose to do this, be sure that it’s a very secure password, something with mixed character classes and a good length. Remember, you are giving others access to your computer by installing this software, so take proper precautions.
If this is your first time playing with a web server, you may be wondering where the files you want to host go. They’re in /var/www/ be default, and will need elevated privileges to access that directory. One idea is to mount a separate partition to that point to be used solely for serving web stuff. Check out our other article, What is the Linux fstab and How Does It Work?, to get some more information for that.
And, now that you have your own web server, why not learn How To Archive, Search, and View Your Tweet Statistics with ThinkUp?
Yatri Trivedi is a monk-like geek. When he's not overdosing on meditation and geek news of all kinds, he's hacking and tweaking something, often while mumbling in 4 or 5 other languages.
- Published 02/4/11