4/17/2010

How to build a LAMP test website on Ubuntu

You can use a LAMP (Linux, Apache, MySQL, and PHP) test server on Ubuntu to develop a website on your computer before you upload it to a website host. To build a LAMP test website on your Ubuntu PC, you need to install LAMP and KompoZer, access your LAMP test website through root, edit your test website homepage, edit your test website new pages, and then test your website.

Installing LAMP and KompoZer
After installing LAMP and KompoZer, you can build and test a website in your LAMP test server on your Ubuntu PC. To install LAMP and KompoZer, do the following:
  1. Install LAMP according to the instructions in How to Set Up a LAMP Test Server on Ununtu.
  2. Click System, select Administration, click Synaptic Package Manager, and then enter your password to display the Synaptic Package Manager window.
  3. In the Quick search field, type kompozer to display its package.
  4. Select kompozer and then click Apply to install the free KompoZer web-authoring software. Alternatively, you can install Bluefish. However, KompoZer is easier to use.
Accessing Your LAMP Test Website Through Root
Accessing your LAMP test website as a root user lets you add and edit HTML files to expand and modify your test website. To access your LAMP test website, do the following:
  1. Open Ubuntu, click Applications, select Accessories, and then click Terminal to display its window and a "~$" (tilde dollar-sign) prompt.
  2. At the flashing cursor immediately after the "~$" prompt, Type sudo nautilus to run Nautilus and display a root - File Browser window.
  3. Click File System, double-click var, and then double-click www to open it. As shown below, your www folder (your LAMP test website) should initially contain two files: index.html and testing.php.
Initial LAMP Test Website

Note: For information about the testing.php file, see How to Set Up a LAMP Test Server on Ununtu.

Editing Your LAMP Test Website Homepage
Edit you LAMP test website home page according your requirements. For example, your homepage should include hyperlinks to other pages in your test website. This simple example has only a homepage and two other pages.
  1. Access your test website through your root browser according to the section above.
  2. Right-click index.html, select Open with, and then click KompoZer to open it and display your initial homepage.
  3. Type over the first line ("It Works!") with This is Your Test Website Homepage!
  4. Type over the second line with Here is a link to New Page One. Select (highlight) New Page One, click Link to display a Link Properties window, type http://localhost/newpageone.html into the Link Location field, and then click OK to add the hyperlink and close the window.
  5. Add a new line and type Here is a link to New Page Two Select (highlight) New Page Two, click Link to display a Link Properties window, type http://localhost/newpagetwo.html into the Link Location field, and then click OK to add the hyperlink and close the window.
  6. Click File, and then click Save to save your new homepage in your LAMP test website.
  7. Click File; click Save As to display the Save Page As window; in the Name field, type newpageone.html; and then click Save to create your New Page One in your test website.
  8. Click File; click Save As to display the Save Page As window; in the Name field, type newpagetwo.html; and then click Save to create your New Page Two in your test website.
  9. Minimize the KompoZer window to redisplay the root www - File Browser. As shown below, your www folder (your LAMP test website) should now contain four files: index.html, newpageone.html, newpagetwo.html, and testing.php.
  10. Edit your test website new pages according to the section below.
Two New Pages on LAMP Test Website

Editing Your LAMP Test Website New Pages
Edit you LAMP test website new pages according your requirements. In each page, you should include links to Home and other pages in your test website. This simple example has only a homepage and two other pages.
  1. Redisplay the KompoZer window. Click File, click Open File to display the Open HTML File window, select newpageone.html, and then click Open to display the page in a new KompoZer tab.
  2. Type over the first line ("This is Your Test Website Homepage!") with New Page One!
  3. In the second line, type over New Page One with Home. Select (highlight) Home, click Link to display a Link Properties window, type http://localhost/index.html into the Link Location field, and then click OK to edit the hyperlink and close the window.
  4. Click File, click Open File to display the Open HTML File window, select newpagetwo.html, and then click Open to display the page in a new KompoZer tab.
  5. Type over the first line ("This is Your Test Website Homepage!") with New Page Two!
  6. In the second line, type over New Page One with Home. Select (highlight) Home, click Link to display a Link Properties window, type http://localhost/index.html into the Link Location field, and then click OK to edit the hyperlink and close the window.
  7. In the third line, type over New Page Two with New Page One. Select (highlight) New Page One, click Link to display a Link Properties window, type http://localhost/newpageone.html into the Link Location field, and then click OK to edit the hyperlink and close the window.
Testing Your LAMP Test Website
Each time you finish editing any page on your LAMP test website, you should test that page by opening your test website in a web browser, such as Mozilla Firefox. In this simple example, you edited three pages. Therefore, you should test all three pages as follows:
  1. Open your web browser, type http://localhost in its address line, and then press Enter to display your LAMP test website homepage.
  2. Click on the New Page One hyperlink to display your new page one, and then click on the Home hyperlink to display your home page.
  3. Click on the New Page Two hyperlink to display your new page two, and then click on the Home hyperlink to display your home page.
  4. Click on the New Page One hyperlink to display your new page one, and then click on the New Page Two hyperlink to display your new page two.
  5. Click on the New Page One hyperlink to display your new page one, and then click on the New Page Two hyperlink to display your new page two.
Note: If any hyperlinks are not working, edit your homepage and new pages according to the sections above.

4/06/2010

How to set up a LAMP test server on Ubuntu

You can set up a LAMP (Linux, Apache, MySQL, and PHP) server as a test server on your Ubuntu 9.10 PC. A LAMP server lets you develop a website on your computer before you upload it to a website host. For additional information and details, see Tux Tweaks: Install LAMP Server on Ubuntu.

Additional Information, 04-13-10: As explained in the Note in the "Using LAMP Server as Your Test Server" section at the end of this article, you must open the root file browser before you can add files to LAMP test server.

Installing LAMP Server on Ubuntu
To install a LAMP test server on your Ubuntu PC, do the following:
  1. Open Ubuntu, click Applications, select Accessories, and then click Terminal to display its window and a "~$" (tilde dollar-sign) prompt.
  2. At the flashing cursor immediately after the "~$" prompt, Type sudo apt-get install lamp-server^ and then press Enter to display a password prompt. Note: To type the "^" (caret symbol), use Shift+6.
  3. Type your password and then press Enter to display the packages that you can install, and "Do you want to continue [Y/n]?"
  4. Type y and then press Enter to start the installation and display a prompt to set your MySQL password. Type the password, press Enter to display a retype-password prompt, retype your MySQL password, and then press Enter to continue installing packages.
Testing Apache and php LAMP Server Components
Apache and php are components of the LAMP software bundle. To test Apache and php, do the following:
  1. Open a web browser. Type http://localhost/ in the address field, and then press Enter to display a web page that says "It works! This is the default web page for this server. The web server is running but no content has been added, yet." This Apache server is your LAMP test server. Close the web browser.
  2. Click Applications, select Accessories, and then click Terminal to display its window. Type gksudo gedit /var/www/testing.php and press Enter to display a password prompt. Enter your Ubuntu password and click OK to open a gedit text-editor window.
  3. Type into the text editor, and then click Save to save the file. Close the text-editor window to redisplay the terminal window.
  4. Type sudo /etc/init.d/apache2 restart and press Enter to restart the Apache server.
  5. Open a web browser. Type http://localhost/testing.php/ in the address field, and then press Enter to display a web page that shows details about your php installation.
Configuring the MySQL LAMP Server Component
MySQL is the database component of the LAMP software bundle. To configure MySQL for use with your LAMP test server, do the following:
  1. Click Applications, select Accessories, and then click Terminal to display its window.
  2. Type cat /etc/hosts | grep localhost and press Enter to display "127.0.0.1 localhost ::1 localhost ip6- localhost ip6-loopback." 127.0.0.1 is your localhost IP address. localhost is red.
  3. Type cat /etc/mysql/my.cnf | grep bind-address and press Enter to display "bind-address = 127.0.0.1." If the bind address does not match your localhost address, type gksudo gedit /etc/mysql/my.cnf to open a gedit text-editor window, scroll to the bind address, and then change it to "127.0.0.1".
Installing and Testing phpMyAdmin for LAMP Server
The phpMyAdmin utility simplifies working with a MySQL database within your LAMP test server. To install and test phpMyAdmin, do the following:
  1. Click Applications, select Accessories, and then click Terminal to display its window. Type sudo apt-get install libapache2-mod-auth-mysql phpmyadmin and press Enter to display the packages that you can install, and the message "Do you want to continue [Y/n]?"
  2. Type y and then press Enter to start the installation and display a Configuring phpmyadmin window. Use your keyboard up and down arrow keys and its spacebar to select apache2, and then press Enter to continue the installation and display another Configuring phpmyadmin window.
  3. Use the Tab key to select Yes and then press Enter to display a database-password prompt. Type your MySQL password (you had set this in the Installing LAMP section above), and then press Enter to display a phpMyAdmin-password prompt.
  4. For simplicity, you can use your MySQL password also as your phpMyAdmin password. Type your MySQL password, and then press Enter to display a password-confirmation prompt. Retype your MySQL password and then press Enter to finish installing phpMyAdmin. Close the terminal window.
  5. Open a web browser. Type http://localhost/phpmyadmin/ in the address field, and then press Enter to display the phpMyAdmin login web page. In the Username field, Type root in the Username field, type your MySQL password in the Password field, and then click OK to display a phpMyAdmin window.
Using LAMP Server as Your Test Server
If you wish to work on only a single website, place its files in /var/www. To see the initial contents of folder www, click Places, click Computer, click File System, double-click var, and then double-click www to open it. Folder www intially contains only two files: index.html and testing.php.

Note: Before you can add files to your LAMP test server, you must click Applications, select Accessories, click Terminal to display its window, and then type sudo nautilus to open the root file browser. You can then paste HTML files into root/var/www.

If you wish to work on multiple web sites, go to Tux Tweaks: Apache Configuration.