본문 바로가기

Develop

Ubuntu LAMP Server Guide - Configure Apache, mySQL, and cgi-bin

아파치, mysql, cgi-bin 설치 순서

아래에서 퍼옴.
http://www.zaphu.com/2007/08/21/ubuntu-lamp-server-guide-configure-apache-mysql-and-cgi-bin/
###################################################################
In a previous post, I shared step-by-step instructions for setting up a Ubuntu LAMP (Linux, Apache, mySQL, PHP) server on your local area network (LAN). I also showed how you could customize the server installation to include all of the niceties of Ubuntu’s Desktop GUI. If this installation was successful, you should be able to view the default site served by Apache (actually an index of the default site) using any machine on your LAN. Type the server’s IP address (or alias if you added the server to your /etc/hosts file) in your browser’s address bar or, if you are browsing on the server itself, type 127.0.0.1 or localhost. If an error occurs, then you will have to edit the apache2.conf file to ensure that Apache can fully resolve the server’s name. Out of good measure you should do this anyway, even if everything seems to be working. Use your favorite text editing program (I use vi here) and open the file.

sudo vi /etc/apache2/apache2.conf

Add the following line somewhere:

ServerName localhost

and restart Apache.

sudo /etc/init.d/apache2 restart

If the default site loads then you are ready to configure Apache to serve your own sites. This configuration process may not be familiar to you if someone else hosts your websites. Here I walk you through the necessary steps. Additionally, I show you how to install phpMyAdmin to administer mySQL databases and how to configure a cgi-bin directory to run CGI programs.

Step 1: Create a new Apache site

To create a new site, first create a directory where you want to keep files associated with this site. I like to keep sites in my home directory so (using my user name of sam) I create a /home/sam/public_html directory. The configuration files for all sites available to Apache are stored in the /etc/apache2/sites-available/ directory. Create a configuration file for your new site (here called zaphu) by copying the configuration file for the default site.

sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/zaphu

Open the new configuration file.

sudo vi /etc/apache2/sites-available/zaphu

You will notice that there is a lot of stuff between <VirtualHost> tags. You have to edit some of this. Change the DocumentRoot path to point to the newly created site directory.

DocumentRoot /home/sam/public_html

In a similar fashion, change one of the Directory directives (it looks something like this)

<Directory /var/www/>

to be consistent with your site path.

<Directory /home/sam/public_html/>

After making these changes, disable the default site using the Apache disable site script.

sudo a2dissite default

Next, use the Apache enable site script to activate the new site.

sudo a2ensite zaphu

Finally, restart Apache.

sudo /etc/init.d/apache2 restart

Create a simple index.html file and save it in /home/sam/public_html/ to test your new site. Something simple like

<html>
<strong>Ron Paul for President in 2008</strong>

Browse (preferable on another machine) to your new Ron Paul for President site to test the configuration.

Step 2: Install phpmyadmin and create root mySQL user

In order to make mySQL database administration easy, many hosts provide phpMyAdmin. You can easily install this tool on your Ubuntu LAMP server too using the built in package management software. At the command prompt type

[#M_ more.. | less.. |sudo aptitude update
sudo aptitude install phpmyadmin

You will have to insert the Ubuntu install CD to complete this installation. After the install completes, the phpMyAdmin script should be in the /var/www/directory. In order for it to resolve in your browser when you type localhost/phpmyadmin (or xxx.xxx.xxx.xxx/phpmyadmin) you must add the following alias to the zaphu site configuration file in /etc/apache2/sites-available/.

Alias /phpmyadmin /var/www/phpmyadmin

Make sure you add this alias between the <VirtualHost> tags. After restarting Apache (see above), you should be presented with the phpMyAdmin log in screen when you navigate to xxx.xxx.xxx.xxx/phpmyadmin. You can log in by using root as your username without a password because by default the root password is set to null. To set the root password navigate to the privileges page and click the icon that looks like a pencil next to each root account (there may be more than one) and enter a password in the appropriate field of the page that loads.

Step 3: Configure a cgi-bin directory

Configuring Apache to allow CGI program execution is pretty easy. Create a directory to be used for CGI programs (here I create /home/sam/public_html/cgi-bin) and add the following to the site configuration file (again between the <VirtualHost> tags).

ScriptAlias /cgi-bin/ /home/sam/public_html/cgi-bin/
<Directory /home/sam/public_html/cgi-bin/>
          Options ExecCGI
          AddHandler cgi-script cgi pl
</Directory>

The first line creates an alias that points to the directory in which CGI scripts are stored. The final line tells Apache that only files that end with the *.cgi and *.pl extensions should be considered CGI programs and executed.

Congratulations! Your new site is configured. It is worth mentioning that if you are going to be granting computers on the wide area network access to your new Ubuntu LAMP server, you should take some time to learn how to properly secure Apache. Check out these other sites for more information on configuring Apache under Ubuntu. Ubuntu Community, Apache2.2 Documentation

If you liked this guide, show support by leaving comments and visiting our sponsors.

반응형