Table of Contents

Setting up LAMP

This article is an adaptation of the article ApacheMySQLPHP, which was created by contributors of the Ubuntu documentation wiki. The contents of this article are licensed under the terms of the Creative Commons Attribution-Share Alike 3.0 license.


This is to help people setup and install a LAMP (Linux-Apache-MySQL-PHP) development environment on the Asus Eee PC including Apache 2, PHP 4 or 5, and MySQL 4.1 or 5.0. This article is aimed at users who have the original Xandros distribution installed.

Easy Way: Installing XAMPP

You will probably use LAMP only for local development on your EEE. An easy and fast way to do so is to install XAMPP, where Apache, Php and MySql are prepackaged and only installed on a single directory (e.g. in /opt/lampp). This way, the installation takes very little time, and you don't need to modify your system. There are very good instructions on how to install XAMPP there.

Prerequisites

Check Requirements

Some applications require php4 while others will work with php5. Be sure to install the version of php and the corresponding apache2 module for it. You cannot have both php4 and php5 modules running on the same instance of apache2 at the same time. Installing one may remove the other.

If you have both php4 and php5 installed, be aware of which version of the apache2 php module you have. If libapache2-mod-php5 is already installed, the php4 package will install libapache-mod-php4 and not libapache2-mod-php4 package.

If libapache2-mod-php5 is not installed, installing php4 will install the apache2 php module (libapache2-mod-php4). See this example.

Most web applications will use Apache2, php5 and mysql5.0. If no specific versions are mentioned in your web application's documentation, use those.

System configuration

If you have not done so already, you will need to enable Full Desktop mode. See Enable Advanced Desktop Mode for instructions. You will also need to add the Xandros repositories to your system. See Adding Additional Software Repositories for instructions.

Installation

Apache 2

To only install the apache2 webserver, enter the in a console window:

sudo apt-get install apache2

Troubleshooting

If you get this error:

apache2: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

enter the following in a console windows:

sudo kwrite etc/apache2/httpd.conf

and add

ServerName localhost

to the file (it should be empty).

If Apache is having problems serving files over 255 bytes:

I have found that Apache2 has trouble working with the unionfs filesystem being used on the Eee PC. The bug is documented here.

The fix is to add this line to the apache configuration file, either /etc/apache2/apache2.conf or httpd.conf:

EnableSendfile Off

Then reset the server with apache2ctl restart to apply the change.

Virtual Hosts

Apache2 has the concept of sites, which are separate configuration files that Apache2 will read. These are available in /etc/apache2/sites-available. By default, there is one site available called default this is what you will see when you browse to http://localhost or http://127.0.0.1. You can have many different site configurations available, and activate only those that you need.

As an example, we want the default site to be /home/user/public_html/. To do this, we must create a new site and then enable it in Apache2.

To create a new site:

Now, we must deactivate the old site, and activate our new one. Apache provides two small utilities that take care of this: a2ensite (apache2en able site) and a2dissite ('apache2disable site).

sudo a2dissite default && sudo a2ensite mysite

Finally, we restart Apache2:

sudo /etc/init.d/apache2 restart

If you have not created /home/user/public_html/, you will receive an warning message

To test the new site, create a file in /home/user/public_html/:

echo '<b>Hello! It is working!</b>' > /home/user/public_html/index.html

Finally, browse to http://localhost/

PHP 5

To only install PHP5, enter the in a console window:

sudo apt-get install php5

If PHP4 is present on your system, the libapache2-mod-php4 package will be removed and replaced libapache2-mod-php5.

Troubleshooting

Does your browser ask if you want to download the .php file instead of displaying it? If Apache is not actually parsing the php file after you restarted it, install libapache2-mod-php5. It is installed when you install the php5 package, but may have been removed inadvertently by packages which need to run a different version of PHP. You may also need to actually enable it, by doing sudo a2enmod php5 followed by sudo /etc/init.d/apache2 restart. Be sure to clear your browser's cache before testing your site again.

PHP 4

To only install PHP4, enter the in a console window:

sudo apt-get install php4

If PHP5 is present on your system, installing php4 will install the php module for apache (version 1.3) and not apache2. To use php4 with apache2, enter:

sudo apt-get install libapache2-mod-php4

Troubleshooting

Does your browser ask if you want to download the .php file instead of displaying it? If Apache is not actually parsing the php file after you restarted it, install libapache2-mod-php4. It is installed when you install the php4 package, but may have been removed inadvertently by packages which need to run a different version of PHP. You may also need to actually enable it, by doing sudo a2enmod php4 followed by sudo /etc/init.d/apache2 restart. Be sure to clear your browser's cache before testing your site again.

MySQL

To install MySQL for PHP5, enter the following in a console window:

sudo apt-get install mysql-server php5-mysql

To install MySQL for PHP4, enter the following in a console window:

sudo apt-get install mysql-server php4-mysql

Configuration

PHP

You may wish to increase the memory limit that PHP imposes on a script. Edit the /etc/php?/apache2/php.ini file (replacing '?' with the version number of the PHP installation you want to modify) and increase the memory_limit value.

MySQL

Set bind address

Before you can access the database from other computers in your network, you have to change its bind address. Note that this can be a security problem, because your database can be accessed by others computers than your own. Skip this step if the applications which require mysql are running on the same machine.

Enter the command:

sudo kwrite /etc/mysql/my.cnf

and change the line:

bind-address           = localhost

to your own internal IP address e.g. 192.168.1.20

bind-address           = 192.168.1.20

If your IP address is dynamic you can also comment out the bind-address line and it will default to your current IP.

If you try to connect without changing the bind-address you will recieve a “Can not connect to mysql error 10061”.

Set root password

Before accessing the database by console you need to type the following in a console window:

mysql -u root

At the mysql console type:

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword');

A successful mysql command will show:

Query OK, 0 rows affected (0.00 sec)

Mysql commands can span several lines. Do not forget to end your mysql command with a semicolon.

Note: If you have already set a password for the mysql root, you will need to use:

mysql -u root -p

(Did you forget the MySQL root password? See https://help.ubuntu.com/community/MysqlPasswordReset.)

Create a MySQL database

To create a new database, enter the following in the mysql console:

mysql> CREATE DATABASE database1;

Create a MySQL user

For creating a new user with all privileges (use only for troubleshooting), at mysql prompt type:

mysql> GRANT ALL PRIVILEGES ON *.* TO 'yourusername'@'localhost' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;

For creating a new user with fewer privileges (should work for most web applications) which can only use the database named “database1”, at mysql prompt type:

mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON database1.* TO 'yourusername'@'localhost' IDENTIFIED BY 'yourpassword';

yourusername and yourpassword can be anything you like. database1 is the name of the database the user gets access to. localhost is the location which gets access to your database. You can change it to '%' (or to hostnames or IP addresses) to allow connections from every location (or only from specific locations) to the database. Note, that this can be a security problem and should only be used for testing purposes!

To exit the mysql prompt type:

mysql> \q

Since the mysql root password is now set, if you need to use mysql again (as the mysql root), you will need to use:

mysql -u root -p

and then enter the password at the prompt.

Using mysqladmin

There is more than just one way to set the MySQL root password and create a database. For example mysqladmin command can be used:

mysqladmin -u root -p password yourpassword

and

mysqladmin -u root -p create database1

mysqladmin is a command-line tool provided by the default LAMP install.

Apache

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

sudo kwrite /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.

Using LAMP

Run, stop and restart the Apache Daemon

Use the following command to run Apache :

sudo /etc/init.d/apache2 start

To stop it, use :

sudo /etc/init.d/apache2 stop

Finally, to restart it, run :

sudo /etc/init.d/apache2 restart

You will also have to do the same with MySQL just replace 'apache2' with 'mysql'.

Also if you would like an easy way to start both open up a text editor and type:

sudo /etc/init.d/apache2 start;
sudo /etc/init.d/mysql start;

Then save it as SWS.sh in your root folder. now when you want to start it go into the console and type:

 sh SWS.sh

Accessing and modifying the website content

You can access Apache website content by typing 127.0.0.1 or http://localhost (by default it will be listening on port 80) in your browser address bar. The default system directory the website content is /var/www. Root access is required to create and modify files in this directory. You can prefix console commands with 'sudo' to grant root permissions to that command. Examples:

sudo cp mypage.html /var/www
sudo kwrite /var/www/index.html

If you wish to use the File Manager GUI with root permissions, click on the Kicker menu and follow Applications > System > Administrator Tools > File Manager (Administrator). If you would rather not have to grant root permissions to make changes, follow the advise given in section Virtual Hosts above.

Viewing PHP statistics

To check the status of your PHP installation create a file named phpinfo.php in the root directory of your website content (/var/www or where ever you have set it too) and insert the following line

<?php phpinfo(); ?>

View this page on a web browser at http://yourserveripaddress/phpinfo.php or http://localhost/phpinfo.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 kwrite /etc/apache2/ports.conf

Change ports.conf so that it contains:

Listen 127.0.0.1:80

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

Known problems

Skype incompatibility

Skype uses port 80 for incoming calls, and thus, may block Apache. The solution is to change the port in one of the applications. Usually, port 81 is free and works fine. To change the port number in Skype go to menu Tools > Options, then click on the Advanced tab, then in the box of the port for incoming calls write your preference.

Additional information