ApacheMySQLPHP

Differences between revisions 30 and 31
Revision 30 as of 2006-01-15 12:47:54
Size: 6057
Editor: 62-64-231-173
Comment:
Revision 31 as of 2006-03-18 21:33:53
Size: 6077
Editor: dhcp0534
Comment: added missing package libapache2-mod-php4
Deletions are marked like this. Additions are marked like this.
Line 19: Line 19:
$ sudo apt-get install php4 $ sudo apt-get install php4 libapache2-mod-php4

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.

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. 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 libapache2-mod-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!

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>

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)