ApacheMySQLPHP
ContentsBRTableOfContents |
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. 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>
Other Apache Options
ServerSideIncludes - enable SSI in Apache2
LocalhostSubdomain - access your local files as if you had different subdomains
Further Information
You can compile PHP5FromSource, as well as MYSQL5FromSource.
StrongPasswords is recommended reading!
BastilleLinux is also recommended if you're going to be running a live webserver.
Apache Tomcat 5
Jakarta Tomcat, a Java servlet container is now part of the Apache family under the name of Apache Tomcat.
Needed befor installing Apache Tomcat
1. Java virtual machine working follow this link [url]https://wiki.ubuntu.com/RestrictedFormats[/url] paying attention to download the JDK and not the SDK.
2. 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 $ sudo apt-get install tomcat5-admin $ sudo apt-get install 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 }}}