ApacheMySQLPHP

Differences between revisions 38 and 39
Revision 38 as of 2006-03-30 18:18:43
Size: 8070
Editor: paperbox
Comment: rearrange slightly
Revision 39 as of 2006-03-31 07:49:48
Size: 8658
Editor: adsl-ull-48-148
Comment:
Deletions are marked like this. Additions are marked like this.
Line 211: Line 211:
=== Installing new servlet or jsp pages in Tomcat5 ===
Using the Tomcat manager included in the installed packages you'll be able to to control your servlet/jsp properly.

1.Enter in your server (by default 127.0.0.1:8180).

2.Enter in the Tomcat manager page (you find the link on the left) typing username and password chosen in the previous step.

3.Search the section ''Deploy'' and in the field ''WAR or Directory URL''
type:
{{{
   file://YOUR SERVLET or JSP PAGE DIRECTORY
}}}
Usually servlet/jsp pages are located in the directory ''/usr/share/tomcat5/webapps''.

This is to help people setup and install a [http://en.wikipedia.org/wiki/LAMP_%28software_bundle%29 LAMP] (Linux-Apache-MySQL-PHP) server in Ubuntu, including Apache 2, PHP 4, and MySQL 4.1, as well as Java support with Apache Tomcat 5.

With the release of Ubuntu 5.10 (Breezy Badger) in October 2005 PHP5 is now available through the repositories, although PHP5 information has not yet been added here. MYSQL 5.0 can still only be installed by compiling. In Dapper, MYSQL 5.0 now exists as a package. See the bottom of this document for further info.

Check Repositories

The Universe repository needs to be enabled to install Apache. Please see AddingRepositoriesHowto for details.

Also, you should be familiar with using sudo - please see RootSudo for details.

Installing Apache 2

$ sudo apt-get install apache2

Installing PHP 4

$ sudo apt-get install php4

Installing MYSQL 4

$ sudo apt-get install mysql-server
$ sudo apt-get install libapache2-mod-auth-mysql
$ sudo apt-get install php4-mysql

After installing MySQL, you really ought to read [http://dev.mysql.com/doc/mysql/en/default-privileges.html 2.9.3. Securing the Initial MySQL Accounts] from the [http://dev.mysql.com/doc/mysql/en/index.html MySQL Reference Manual]. The basedir is /usr so:

cd /usr
sudo ./bin/mysql_install_db --user=mysql

Edit Apache Configuration

You may want your current user to be the PHP pages administrator. To do so, edit the Apache configuration file :

$ sudo gedit /etc/apache2/apache2.conf

Search both the strings starting by "User" and "Group", and change the names by the current username and groupname you are using. Then you'll need to restart Apache. (look at the next chapter concerning apache commands)

Configuration options relating specifically to user websites (accessed through localhost/~username) are in /etc/apache2/mods-enabled/userdir.conf.

Edit PHP Configuration to Work With MYSQL

You may need to edit the PHP configuration file to get PHP and MYSQL talking :

$ sudo gedit /etc/php4/apache2/php.ini

Remove the ";" for the line ";extension=mysql.so", and restart Apache as is stated below.

Run, Stop, And Restart Apache

Use the following command to run Apache :

$ sudo /usr/sbin/apache2ctl start

To stop it, use :

$ sudo /usr/sbin/apache2ctl stop

Finally, to restart it, run :

$ sudo /usr/sbin/apache2ctl restart

Status

To check the status of your PHP installation:

 $ sudo gedit /var/www/testphp.php

and insert the following line

 <?php phpinfo(); ?>

View this page on a web browser, at http://yourserveripaddress/testphp.php or http://localhost/testphp.php

Securing Apache

If you just want to run your Apache install as a development server and want to prevent it from listening for incoming connection attempts, this is easy to do.

$ sudo gedit /etc/apache2/ports.conf
$ password:

Change ports.conf so that it contains:

Listen 127.0.0.1:80

Save this file, and restart Apache (see above). Now Apache will serve only to your home domain, http://127.0.0.1 or http://localhost.

Password-Protect a Directory With .htaccess

Create a file called .htaccess in the directory you want to password-protect with the follwing content:

AuthUserFile /your/path/.htpasswd
AuthName "Authorization Required"
AuthType Basic
require valid-user

instead of valid-user, you can also add the users you want directly

If you want to password protect just a single file in a folder add the following lines to the .htaccess file:

<Files "mypage.html">
  Require valid-user
</Files>

Then create the file /your/path/.htpasswd which contains the users that are allowed to login and their passwords. We do that with the htpasswd command:

htpasswd -c /path/to/your/.htpasswd user1

The -c flag is used only when you are creating a new file. After the first time, you will omit the -c flag, when you are adding new users to an already-existing password file. Otherwise you will overwrite the file!!

Nevertheless, you should store the file in as secure a location as possible, with whatever minimum permissions on the file so that the web server itself can read the file.

Finally we need to add the following lines to /etc/apache2/apache2.conf:

<Directory /your/path>
AllowOverride All
</Directory>

You have to adjust /your/path/.htpasswd

Restart your webserver:

sudo /etc/init.d/apache2 restart

Troubleshooting

If you can't access your stuff and the dialog keeps popping up, check that you entered the username and password correctly. If it still doesn't work, check the path to your .htpasswd and make sure the path specified in the AuthUserFile directive is correct. Also make sure that both the .htpasswd and .htaccess files are readable by the web server user chmod 644 should do the trick!

If apache is not actually parsing the php, install libapache2-mod-php4. It should be installed when you install the php4 package, but some users have reported that it wasn't for them.

Example

Here is an example on how to prevent users from access the directory, password-protect a specific file and allow userse to view a specific file:

AuthUserFile /your/path/.htpasswd
AuthName "Authorization Required"
AuthType Basic
Order Allow,Deny
<Files myfile1.html>
 Order Allow,Deny
 require valid-user
</Files>

<Files myfile2.html>
 Order Deny,Allow
</Files>

Apache Tomcat 5

Jakarta Tomcat, a Java servlet container is now part of the Apache family under the name of Apache Tomcat.

Needed before installing Apache Tomcat

1. Java virtual machine working follow this link RestrictedFormats paying attention to download the JDK and not the SDK.

1. Set Java environment variables this way:

$ export JAVA_HOME="path of your java home"
$ export PATH=$PATH:$JAVA_HOME/bin

Installing Apache Tomcat 5

$ sudo apt-get install tomcat5 tomcat5-admin tomcat5-webapps

Run, Stop, And Restart Apache Tomcat

Use the following command to run Apache Tomcat:

$ sudo /etc/init.d/tomcat5 start

To stop it, use :

$ sudo /etc/init.d/tomcat5 stop

Finally, to restart it, run :

$ sudo /etc/init.d/tomcat5 restart

Using Tomcat5

You can find tomcat up and running (if you have followed the previous steps) at the following ip: {{{ 127.0.0.1:8180 }}}

Administering Tomcat5

If you have installed also the admin package as listed before you will be able to enter in the administation window only if you edit the file

$ /usr/share/tomcat5/conf/tomcat-users.xml

and add the following lines for creating new users with admin and manager privilegies as described in Tomcat's main page

  <role rolename="manager"/>
  <role rolename="admin"/>
<user username="YOUR USERNAME " password="YOUR PASSWORD" roles="admin,manager"/>

Obviously if you want only one kind of role you've to delete the one you are not interested in. Example only admin

   <role rolename="admin"/>
<user username="YOUR USERNAME " password="YOUR PASSWORD" roles="admin"/>

Installing new servlet or jsp pages in Tomcat5

Using the Tomcat manager included in the installed packages you'll be able to to control your servlet/jsp properly.

1.Enter in your server (by default 127.0.0.1:8180).

2.Enter in the Tomcat manager page (you find the link on the left) typing username and password chosen in the previous step.

3.Search the section Deploy and in the field WAR or Directory URL type:

   file://YOUR SERVLET or JSP PAGE DIRECTORY

Usually servlet/jsp pages are located in the directory /usr/share/tomcat5/webapps.

Other Apache Options

Further Information

You can compile PHP5FromSource, as well as MYSQL5FromSource.


CategoryDocumentation

ApacheMySQLPHP (last edited 2008-08-06 16:21:08 by localhost)