LAMP on Sarge (Apache2, PHP5, MySQL5, phpMyAdmin, Smarty, ADODB)

Posted by ncb on Wed 22 Feb 2006 at 09:10

This documents my adventure setting up a LAMP server on Sarge with Apache2, PHP5, MySQL5, phpMyAdmin, Smarty, and ADODB. It covers installation and just enough sample code to test everything. It turned out to be pretty long. I should point out that I have deviated from the "Debian Way" by downloading phpMyAdmin, Smarty, and ADODB directly from their respective websites and installing them in /usr/local. I could find no backports for these, and kept running into dependecies on PHP4 which I did not want to install.

Contents

What I Installed and Where I Got It.

Apache 2.0.54
The webserver we know and love. This is the apache2-mpm-prefork package from Sarge (see note below)
PHP 5.1.2-1
The scripting language we know an love. This is the backported libapache2-mod-php5 package from dotdeb.org
PHP5 MySQL 5.1.2-1
The MySql extensions for PHP. This is the backported php-mysql-5.1.2-1 package from dotdeb.org
MySQL 5.0.18
This is the backported mysql-server package from dotdeb.org
phpMyAdmin 2.7.0-pl2
Web interface for managing databases. Downloaded from the phpMyAdmin site.
Smarty 2.6.12
Template engine for PHP. Downloaded from the Smarty site.
ADODB 4.7.1-1
Database extraction class for PHP. Downloaded from the ADODB site.

Note: The PHP folks say it's a bad idea to use the threading Apache2, so I used the MPM prefork version from Sarge. For more info read the FAQ "Why shouldn't I use Apache2 with a threaded MPM in a production environment?". Also there is the MPM prefork info provided by Apache.

Before You Start

  • Firewall:. This is a must If you are going to put your box out on the web. Good candidates are Firehol and Shorewall.
  • DNS: If you want your box available on the web, you need to configure DNS to point to your web server's IP address for whatever domain(s) you are going to host.

Installing Apache

As noted above, this is the MPM prefork version available in Sarge. I'm also installing some of the packages it recommends. No changes are required to /etc/apt/sources.list for this.

$> apt-get update
$> apt-get upgrade
$> apt-get install apache2-mpm-prefork apache2-doc lynx ca-certificates.

Testing Apache

Before we start messing with it, you might as well check that Apache is working. Point a browser at www.yourdomain.com and verify that you see the installed default Apache site. If you don't, check your DNS and firewall. Fix whatever the problem is before you go on.

Security Tweaks for Apache

I decided on these security tweaks from reading the security tips on the Apache site. You can add these to the main config file, but I opted to keep my own config changes separate by putting them in a file in the /etc/apache2/conf.d/ directory. I created a file there named local_configs.conf and put the following in it.

# Tighten access to the file system.
<Directory />
        # Forbid default access to file system locations
        Order Deny,Allow
        Deny from all
        # prevent use of .htaccess files in all directories
        # apart from those specifically enabled.
        AllowOverride None
</Directory >

# Limit available info about this server.
ServerSignature Off
ServerTokens production

Don't forget to reload Apache after changing the config.

Virtual Hosting Refresher

The Debian installation of Apache2 comes all set up do "name-based" virtual hosting right out of the box. This is perfect if you have more than one domain to host on your server, or plan to in the future. For the uninitiated, here's a quick rundown on virtual hosting.

Virtual hosting refers to the practice of running more than one web site (domains) on a single server. The fact that they are running on the same physical server is not apparent to the end user. There are two types of virtual hosting, IP-based and name-based.

IP-based virtual hosting is when you have a different IP address for every domain. We'll not be doing it in this HOWTO.

Name-based virtual hosting is when you have multiple domains running from one IP address, and is what we will be using here. This means that the DNS A records (or CNAME records) for www.company1.com and www.company2.com can both point to the one IP address of your server, and Apache will sort out which site to serve up based on the domain that was requested. If someone points their browser at the IP address of your server, e.g. http://123.456.123.45, they will be served the first site that you have configured. Unless you change it, this will be the Apache default site as it is installed by Debian's Apache2 package.

For more info on virtual hosting, read the Apache docs.

Getting Familiar With Apache

Setting up a name-based virtual site is easy once you understand the layout a bit. I suggest you scan the file /etc/apache2/README. It's pretty short and clear. For the impatient, here are just the things we are going to touch to get one name-based virtual site up. I'll use "mydomain.com" as the virtual domain in all the examples.

/var/www/
This directory is the document root for the web server. This is where your web sites go.
/var/www/mydomain.com/
A directory you create to contain all files related to the site mydomain.com. This directory is not publicly accessible.
/var/www/mydomain.com/docs/
A directory you create to contain the publicly accessible files for mydomain.com.
/var/www/mydomain.com/docs/index.html
An html file you create to test your configuration.
/etc/apache2/sites-available/mydomain.com
This file you create containing the Apache configuration directives to define the virtual domain mydomain.com. Each file in the sites-available directory defines a different virtual domain.
/etc/apache2/sites-enabled/mydomain.com
This is a symlink you create with the handy little command a2ensite mydomain.com. The presence of a symlink in the sites-enabled directory has the effect of "enabling" a site defined in the sites-available directory.

Setting Up a Web Site

First, create a subdirectory of /var/www/ to contain the site. It makes sense to name this directory after the domain that will live there.

$> mkdir /var/www/mydomain.com

Now create the subdirectory /var/www/mydomain.com/docs/. This will be the only directory that is publicly accessible.

$> mkdir /var/www/mydomain.com/docs

Now create /var/www/mydomain.com/docs/index.html, something simple like the following:

<html>
<head>
   <title>Mydomain.com test index page</title>
</head>
<body>
   <h1>Hello World!</h1>
</body>
</html>

Now create /etc/apache2/sites-available/mydomain.com. We use the <VirtualHost> directive to define the virtual site, and the <Directory> directive to define the ...xxx/docs/ directory as publicly accessible (Allow from all). Like so:

<VirtualHost * >
        #Basic setup
        ServerAdmin webmaster@mydomain.com
        ServerName www.mydomain.com
        DocumentRoot /var/www/mydomain.com/docs

        <Directory /var/www/mydomain.com/docs>
                Order Deny,Allow
                Allow from all
                # Don't show indexes for directories
                Options -Indexes
        </Directory>
</VirtualHost>

Now, to enable the site you use the a2ensite command (Note:use a2dissite to disable). The following creates a symlink /etc/apache2/sites-enabled/mydomain.com, which enables the site.

$> a2ensite mydomain.com

You need to reload Apache to see the site...

$> /etc/init.d/apache2 reload

If DNS is working, you should now be able to point your browser at www.mydomain.com see the index.html page you created above.

Miscellaneous Apache Stuff

There are a few other things I noticed that might be useful to someone. Here they are in no particular order.

  • If you remove or disable the default Apache site, you may find you can only see one virtual site, even though more are enabled. If so, add a line containing NameVirtualHost * to /etc/apache2/conf.d/local_configs.conf, in the main apache config file, or in the /etc/apache2/sites-available/mydomain.com file.
  • Enabling and disabling mods works the same way as enabling and disabling sites. Use the a2enmod and a2dismod utilities to manage the symlinks in the mods-enabled directory that toggle mods on and off. For example, to enable ssl, use the command a2enmod ssl.
  • If you want to enable ssl add the line Listen 443 to /etc/apache2/ports.conf.
  • To create a self-signed cert for use with ssl, you can use the apache2-ssl-certificate command. For example, apache2-ssl-certificate -days 3650 will generate a cert that is good for 10 years.

Installing PHP 5

We need to add one the dotdeb.org mirrors to sources.list for this. The mirrors are listed at www.dotdeb.org/mirrors. I chose one from Germany by adding the following to /etc/apt/sources.list

# Use dotdeb.org for LAMP related packages not available in Sarge
deb http://dotdeb.pimpmylinux.org/ stable all
deb-src http://dotdeb.pimpmylinux.org/ stable all

Now, thanks to Guillaume Plessis of dotdeb.org, installing PHP5 on Sarge is easy.

$> apt-get update
$> apt-get install libapache2-mod-php5

Security Tweaks for PHP 5

There is a sample php config provided in /usr/share/doc/php5-common/examples/php.ini-recommended. It contains the "warmly recommended" php.ini settings for production servers. I chose to use this config file instead of the installed default. This is a very well commented file and worth the time to read. If you want to use this recommended config instead of the default, first save a copy of the original php.ini file, like so ..

$> mv /etc/php5/apache2/php.ini /etc/php5/apache2/php.ini.original

... and then put the recommended file in place of the original file.

$> cp /usr/share/doc/php5-common/examples/php.ini-recommended \
   /etc/php5/apache2/php.ini

Now, like we did with Apache, let's hide info about our php config by telling PHP to hide itself. Open up php.ini in your favorite editor and set expose_php to off.

expose_php = off

Also, I plan to follow the convention of naming all php include files with the .inc extension. For good measure, I want Apache to hide these by default, so I add this to the /etc/apache2/conf.d/local_configs.conf file I created earlier (this is the same way .htaccess files are protected in the main Apache config file).

# Hide all files with the .inc extension.
<Files *.inc>
    Order allow,deny
    Deny from all
</Files *.inc>

Installing MySQL

Thanks (again) to the dotdeb.org mirror we have already added, this is easy. apt-get will find the latest version there.

$> apt-get install mysql-server

Don't forget to set a password for the MySQL root user. Do the following, replacing "secret" with your chosen password, and make it a good one.

$> /usr/bin/mysqladmin -u root password 'secret'

Note: It would be wise to create a non-root user for MySQL having just the MySQL permissions absolutely necessary to the PHP applications you are going to write. I'm using the root user for the purposes of this howto.

Also grab the php5 mysql extensions from dotdeb.org:

$> apt-get install php5-mysql

Testing MySQL

Let's create a quick database and table to both verify that MySQL is working, and give us something to test ADODB with later. At a command line, login to MySQL.

$> mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1920 to server version: 5.0.18-Debian_3.dotdeb.1-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

Now we will, 1) create a database 2) tell MySQL to "use" the database 3) create a table, and 4) insert a couple of records into the table. You should be able to copy and paste these commands at the mysql prompt. BTW, I stole this example out the MySQL Reference Manual.

mysql> CREATE DATABASE mydomain;
Query OK, 1 row affected (0.00 sec)

mysql> USE mydomain;
Database changed

mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20), species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO pet VALUES ('Puffball','Diane','hamster','f','1999-03-30',NULL);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO pet VALUES ('Libby','Diane','dog','f','2001-04-15',NULL);
Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM pet;
+----------+-------+---------+------+------------+-------+
| name     | owner | species | sex  | birth      | death |
+----------+-------+---------+------+------------+-------+
| Puffball | Diane | hamster | f    | 1999-03-30 | NULL  |
| Libby    | Diane | dog     | f    | 2001-04-15 | NULL  |
+----------+-------+---------+------+------------+-------+
2 rows in set (0.00 sec)

mysql> quit
Bye

I find the MySQL command line painful. phpMyAdmin makes it a lot easier, so let's install it.

Installing phpMyAdmin

phpMyAdmin is a great tool for creating and managing databases. As noted I could not find a backported package for it. So, I just downloaded and installed it directly from the phpMyAdmin site.

First we'll create a directory that's out of the way of Debian's package management system in /usr/local. We'll call it php5 since we'll be putting Smarty and ADODB files here as well.

$> mkdir /usr/local/php5

Now we untar phpMyAdmin in this directory (creates /usr/local/php5/phpMyAdmin-2.7.0-pl2), and remove the tar.gz file.

$> cp phpMyAdmin-2.7.0-pl2.tar.gz /usr/local/php5/
$> cd /usr/local/php5/
$> tar -zxvf phpMyAdmin-2.7.0-pl2.tar.gz
$> rm phpMyAdmin-2.7.0-pl2.tar.gz

Note: I opt to leave the version info in the phpMyAdmin directory name so I can easily untar a new version right next it without blowing anything away.

Configuring phpMyAdmin

The sample config file provided is config.default.php. We need to copy it to config.inc.php.

$> cd /usr/local/php5/phpMyAdmin-2.7.0-pl2/
$> cp config.default.php config.inc.php

Now we need to make a couple of changes to config.inc.php. First, let's define the URI we'll be using to access PhpMyAdmin (this is not the path to the phpMyAdmin directory, but rather the alias we will use for it in the Apache config). Find the following line,

$cfg['PmaAbsoluteUri'] = '';

and change it to something like this.

$cfg['http://www.mydomain.com/phpmyadmin'] = '';

Next we need to choose an auth type. The three options are 'config', 'http', and 'cookie'. The 'config' option is the default, and requires you to keep your MySQL password right here in this file, which I don't like. The 'http' option prompts you for the password when you access PhpMyAdmin, but will send the password in clear text, which I also don't like. The 'cookie' option is the best I think, and allows you to define a passphrase with the [blowfish_secret] parameter, which phpMyAdmin will use to encrypt the password in a cookie when you log in. To use the 'cookie' auth type, we need to make two changes. First, find the section of the file that looks like this:

/**
 * The 'cookie' auth_type uses blowfish algorithm to encrypt the password. If
 * at least one server configuration uses 'cookie' auth_type, enter here a
 * passphrase that will be used by blowfish. The maximum length seems to be 46
 * characters.
 */
$cfg[''] = '';

You need to change this line ..

$cfg[''] = '';

.. to something like the following. Note that you have to add the "blowfish_secret" part within the brackets (I don't know why). Note also that you will not be prompted for the passphrase you enter here, so feel free to make it a real ugly one.

$cfg['blowfish_secret'] = 'some_passphrase_under_46_characters_long';

Then find this line ..

$cfg['Servers'][$i]['auth_type']     = 'config';

... and change the auth type from 'config' to 'cookie', like so ..

$cfg['Servers'][$i]['auth_type']     = 'cookie';

That's it. Save the file.

Configuring Apache to Display phpMyAdmin

Now we need to tell Apache where phpMyAdmin lives, and also create an Apache alias for the phpMyAdmin directory (so we don't have to remember to type "phpMyAdmin-2.7.0-pl2" into the browser all the time). Also, since I don't want anyone else to even try logging in to phpMyAdmin, I will restrict access to just the IP address of my own workstation. To do all this we just need to add a small section to the file /etc/apache2/sites-available/mydomain.com that we created earlier. Add a section like the following, remebering to change the IP address to something appropriate.

# Provide an alias to phpmyadmin
Alias /phpmyadmin /usr/local/php5/phpMyAdmin-2.7.0-pl2
<Directory /usr/local/php5/phpMyAdmin-2.7.0-pl2>
        # Restrict phpmyadmin access to just my worksation
        Order Deny,Allow
        Deny from all
        Allow from 192.168.1.2
</Directory>

Reload Apache, and you should be able to point your browser at www.mydomain.com/phpmyadmin and login as the MySQL root user.

About Smarty

Smarty is a template engine for PHP. It allows you to separate your presentation code (html) from the logic (php) in your web applications. If you don't know why this is important to do, then develop a great big web site with a whole bunch of PHP applications, wait long enough to forget how you did everything, and then try to redesign the site. Or, just read Smarty's Why Use It page. They explain it better than I can.

Installing Smarty

As previously noted I could not find a backport for Smarty, so I just downloaded the latest version from here. Once you have the tar.gz let's untar it in the /usr/local/php5 directory we created earlier.

$> cp Smarty-2.6.12.tar.gz /usr/local/php5/
$> cd /usr/local/php5/
$> tar -zxvf Smarty-2.6.12.tar.gz
$> rm Smarty-2.6.12.tar.gz

Now edit /etc/php5/apache2/php.ini and add the Smarty /libs subdirectory to the php_include_path, like so:

include_path = ".:/usr/local/php5/Smarty-2.6.12/libs"

Remember, whenever you make a change to php.ini you need to reload Apache.

Now we will create the four directories that Smarty needs to function and set the permissions on them. This is basically right out of the Smarty site's Quick Install page.

cd /var/www/mydomain.com
$> mkdir smarty
$> mkdir smarty/templates
$> mkdir smarty/templates_c
$> mkdir smarty/cache
$> mkdir smarty/configs
$> chown www-data:www-data smarty/templates_c
$> chown www-data:www-data smarty/cache
$> chmod 775 smarty/templates_c
$> chmod 775 smarty/cache

Note: The Smarty documentation says to keep these directories out of the doc root. These are not in our doc root because we defined the doc root for mydomain.com as /var/www/mydomain.com/docs/. It is therefore important to remember not to change the doc root to /var/www/mydomain.com/, which would expose these directories to the world. You can of course put these directories anywhere else you want. My reason for placing them here is that I find it convenient to have just one directory (/var/www/mydomain.com/) containing everything related to the content of a domain.

Testing Smarty

Now let's make a test PHP app. First make a directory for it to live in.

$> mkdir /var/www/mydomain.com/docs/myapp/

Then create a file named index.php in that directory containing the following:

<?php

// Include Smarty.class.php (this is /usr/local/php5/Smarty-x.x.x/Smarty.class.php)
// The full path is not needed here because it is defined in php.ini's include_path.
require('Smarty.class.php');

// Initialize smarty paths
$smarty = new Smarty;
        $smarty->template_dir = '/var/www/mydomain.com/smarty/templates/';
        $smarty->compile_dir = '/var/www//mydomain.com/smarty/templates_c/';
        $smarty->config_dir = '/var/www/mydomain.com/smarty/configs/';
        $smarty->cache_dir = '/var/www/mydomain.com/smarty/cache/';

// Set a smarty variable
$smarty->assign('name', 'Johnny');

// Display the smarty template
$smarty->display('myapp_index.tpl');

?>

Now we need to make a template, called myapp_index.tpl, in the directory /var/www/mydomain.com/templates/. Something like the following:

<html>
<head>
   <title>Smarty</title>
</head>
<body>
   Hello, {$name}!
</body>
</html>

Now you should be able to display this template by pointing your browser at www.mydomain.com/myapp/ and see Hello, Johnny!

A Smarter Smarty Setup

Now that we know it works, let's make our Smarty setup more flexible. We don't really want to define the smarty directory paths in every PHP script when we could just define them once in an include file. First let's make a new directory for it.

$> mkdir /var/www/mydomain.com/includes/

We also want to add this directory to the include_path in php.ini. Don't forget to reload Apache afterwards.

include_path = ".:/usr/local/php5/Smarty-2.6.12/libs:/var/www/mydomain.com/includes"

Now create the file /var/www/mydomain.com/includes/smarty_setup.inc and define the smarty directories in it.

<?php

// Include Smarty.class.php (this is /usr/local/php5/Smarty-x.x.x/Smarty.class.php)
// The full path is not needed here because it is defined in php.ini's include_path.
require('Smarty.class.php');

// Initialize smarty paths
$smarty = new Smarty;
        $smarty->template_dir = '/var/www/mydomain.com/smarty/templates/';
        $smarty->compile_dir = '/var/www//mydomain.com/smarty/templates_c/';
        $smarty->config_dir = '/var/www/mydomain.com/smarty/configs/';
        $smarty->cache_dir = '/var/www/mydomain.com/smarty/cache/';

?>

With this done, you can simplify /var/www/mydomain.com/myapp/index.php to look like this.

<?php

// Load Smarty setup
require('smarty_setup.inc');

// Set a smarty variable
$smarty->assign('name', 'Johnny');

// Display the smarty template
$smarty->display('myapp_index.tpl');

?>

This is much cleaner looking. More importantly, if there is ever a need to redefine the location of the smarty directories, the only file that will need editing is smarty_setup.inc, not every script ever written. We'll take the same approach with ADODB.

About ADODB

ADODB is a database abstraction class for PHP. It allows you to write PHP scripts that can easily be modified to work with several databases. Using it also has the effect of streamlining your PHP code for databases queries.

Installing ADODB

Installation is straightforward. Just download it, and untar it in /usr/local/php5 just as we did with Smarty and phpMyAdmin.

$> cp adodb471-1.tgz /usr/local/php5/
$> cd /usr/local/php5/
$> tar -zxvf adodb471-1.tgz
$> rm adodb471-1.tgz

Add the adodb directory to php.ini's include_path, and remember to reload apache when you're done.

include_path = ".:/usr/local/php5/Smarty-2.6.12/libs:/usr/local/php5/adodb:/var/www/mydomain.com/includes"

Like we did for Smarty, we're going to make a setup file for ADODB that we can just include in the PHP scripts that will access the database. We'll call it adodb_setup.inc, and put it in the directory /var/www/mydomain/includes. Make it look like the following, changing "secret" to your MySQL root password, and "mydomain" to the name of your database:

<?php

// Load adodb libs from include_path
include('adodb.inc.php');

// Define the Data Source Name (DSN) for adodb
$dsn = 'mysql://root:secret@localhost/mydomain';

// Connect to database
// This makes the $db connection object available to scripts
$db = ADONewConnection($dsn);

?>

Note: Your MySQL password is right here in this file. Keep this file and the directory it lives in out of the doc root.

All Together Now

Now let's pull all this together. We'll go back to our myapp application and have it use ADODB syntax to make a database query. Then we'll display the results using a Smarty template.

First edit /var/www/mydomain.com/myapp/index.php to look like the following. Note that we are including the file adodb_setup.inc that we just created.

<?php

// Load Smarty setup
require('smarty_setup.inc');

// Load ADODB and make db connection
require('adodb_setup.inc');

// Tell adodb we want an associative array
$db->SetFetchMode(ADODB_FETCH_ASSOC);

// Query the pet table and assign the
// result set to the $rs variable
$rs = $db->Execute('select * from pet');

// Pass the result set to smarty
$smarty->assign('rs', $rs);

// Other vars for smarty
$smarty->assign('pg_title', 'MyApp');
$smarty->assign('name', 'Johnny');

// Display the smarty template
$smarty->display('myapp_index.tpl');

?>

Finally, edit the file /var/www/domain.com/smarty/templates/myapp_index.tpl to look something like the following, in which Smarty displays the $pg_title and $name variables passed from the PHP script, and also iterates through the database result set (the $rs variable), drawing an html table along the way.

<html>

<head>
   <title>{$pg_title}</title>
</head>

<body>

<h1>{$pg_title}</h1>

<h2>Hello, {$name}.</h2>

<strong>Results of pet query</strong> <br />
<hr />

<table>
   <tr>
      <th>Pet Name</th>
      <th>Owner</th>
      <th>Species</th>
      <th>Gender </th>
      <th>Birth </th>
      <th>Death </th>
    </tr>

    {foreach from=$rs item=pet}
    <tr bgcolor="{cycle values="#eeeeee,#d0d0d0"}">
       <td>{$pet.name}</td>
       <td>{$pet.owner}</td>
       <td>{$pet.species}</td>
       <td>{$pet.sex}</td>
       <td>{$pet.birth}</td>

       {if !$pet.death}
          <td>Still kicking</td>
       {else}
          <td>{$pet.death}</td>
       {/if}

    </tr>
    {/foreach}
</table>

</body>
</html>

The resulting html from this should look something like the following:


<html>
   <title>MyApp</title>
</head>

<body>

<h1>MyApp</h1>

<h2>Hello, Johnny.</h2>

<strong>Results of pet query</strong> <br />
<hr />

<table>
   <tr>
      <th>Pet Name</th>
      <th>Owner</th>
      <th>Species</th>
      <th>Gender </th>
      <th>Birth </th>
      <th>Death </th>
    </tr>

    <tr bgcolor="#eeeeee"}">
       <td>Puffball</td>
       <td>Dianne</td>
       <td>hamster</td>
       <td>f</td>
       <td>1999-03-30</td>
       <td>Still kicking</td>
    </tr> 
       <tr bgcolor="#d0d0d0"}">
       <td>Libby</td>
       <td>Dianne</td>
       <td>dog</td>
       <td>f</td>
       <td>2001-04-15</td>
       <td>Still kicking</td>
    </tr> 
</table>    

</body>
</html>

Pretty cool eh? Well whether you think that's cool or not, pat yourself on the back for getting this far. My next howto is going to be shorter for sure.

 

 


Posted by Anonymous (62.166.xx.xx) on Wed 22 Feb 2006 at 16:24
Thanks a lot for this easy reading and interesting article. I was just looking for something like this.

-fer

[ Parent | Reply to this comment ]

Posted by gass (81.84.xx.xx) on Wed 22 Feb 2006 at 22:30
You forget, i think, fast cgi on lamp servers is very important for security

[ Parent | Reply to this comment ]

Posted by Anonymous (62.176.xx.xx) on Wed 22 Feb 2006 at 23:18
I recommend putting Apache with PHP as CGI in chroot so that Apache doesn't know about such thinks like wget/exec/"/bin/bash" etc.
- Oh and don't forget to mount the partition Apache runs on with noexec und nosuid :D

[ Parent | Reply to this comment ]

Posted by peterhoeg (193.163.xx.xx) on Thu 23 Feb 2006 at 09:38
If you do not want to install from source, you want to use PHP5 and prefer the Debian provided packages, but have an issue where certain packages depend on PHP4, just install the php4 cgi package instead. Most packages depend on either some package that provides php4, the cgi one does and you don't have to use it if you just use the php5 package for Apache or use another web server.

[ Parent | Reply to this comment ]

Posted by cswd (195.172.xx.xx) on Thu 23 Feb 2006 at 12:16

I configure my web sites as:

/srv/www/www.cswd.co.uk/htdocs/
/srv/www/www.cswd.co.uk/logs/

I am migrating to the FHS standard though which is:

/srv/cswd.co.uk/httpd/www/htdocs/
/srv/cswd.co.uk/httpd/www/logs/

I think this is a better approach as if someone needs to access something remotely, you have to either symlink into the var tree or let other users browse var. This way you can force them into /srv/domain!

Hope this helps.

[ Parent | Reply to this comment ]

Posted by chris (213.187.xx.xx) on Fri 24 Feb 2006 at 19:58
[ View Weblogs ]
Interesting. I have my hosts as directories named after the host under /web with the logs split under /var/log/apache2/sitename.

You tempt me to look into this more :) I know that it's going to work just as well either way technically - but - if it means that other people will understand the layout better then that's good.

[ Parent | Reply to this comment ]

Posted by Anonymous (62.255.xx.xx) on Fri 24 Feb 2006 at 21:26
Technically it tends to work better with the /srv as I stick that on a SCSI/SATA RAID5 and the rest on a SATA RAID1 (cheapness!) I've just moved my courier and postfix virtual server configuration into it as well so everything non-system sits in it. There is nothing at all in /home as there are no local users and /var only gets configuration and service based information stored in it.

Basically the user can ftp in and their ftp root is /srv/domain so that they can see only their mail, their web site(s) and their daily mysql backups (which go into /srv/${domain}/mysql/db-date-backup.sql.gz ).

[ Parent | Reply to this comment ]

Posted by Anonymous (87.219.xx.xx) on Thu 23 Feb 2006 at 13:02
When talking about Security Tweaks for Apache, your script doesn't work well (at least in my machine).

On line 9, I had to change:

</directory>

for

</directory>

(There you need to close the directive, not to open it again)

[ Parent | Reply to this comment ]

Posted by ncb (66.224.xx.xx) on Thu 23 Feb 2006 at 14:06
Yep. Sorry, that was a typo. My bad.

[ Parent | Reply to this comment ]

Posted by Anonymous (62.94.xx.xx) on Sun 26 Feb 2006 at 10:45
Also in:

</files> -> </files>

;)

[ Parent | Reply to this comment ]

Posted by ncb (66.224.xx.xx) on Sun 26 Feb 2006 at 17:48
Ack! Sorry about the typos.

[ Parent | Reply to this comment ]

Posted by Anonymous (65.103.xx.xx) on Wed 22 Mar 2006 at 17:04
Hi, I am following these instructions to have the LAMP in my computer. Everything went fine until I added the lines to configure apache to display phpmyadmin: # Provide an alias to phpmyadmin Alias /phpmyadmin /usr/local/php5/phpMyAdmin-2.7.0-pl2 # Restrict phpmyadmin access to just my worksation Order Deny,Allow Deny from all Allow from 192.168.1.2 I tried to reload apache then I got an error, strangely the "affected" file is /etc/apache2/conf.d/local_configs.conf then I got another error. No matter, if I use / in both Order allow,deny Deny from all You mention that it shoul be -> what am I doing wrong? in the directives in the apache website it says that the directive for files is ... which one is correct? Am I talking about the same thing?(I am new to apache, php5...) Please help. Fernando

[ Parent | Reply to this comment ]

Posted by tracerb (66.65.xx.xx) on Thu 26 Oct 2006 at 17:06
Works for me:

# Tighten access to the file system.
<directory />
# Forbid default access to file system locations
Order Deny,Allow
Deny from all
# prevent use of .htaccess files in all directories
# apart from those specifically enabled.
AllowOverride None
</directory>

# Limit available info about this server.
ServerSignature Off
ServerTokens production

# Hide all files with the .inc extension.
<files ~ "\.inc$">
Order allow,deny
Deny from all
</files>

[ Parent | Reply to this comment ]

Posted by Anonymous (213.208.xx.xx) on Sun 26 Feb 2006 at 11:47
The PHP5 that comes in the dotdeb package is not compiled with MySQL Support.

As per your article, I have installed:

# dpkg --list | grep php
ii php5-cli 5.1.2-1.dotdeb PHP 5 scripting language
ii php5-common 5.1.2-1.dotdeb Common files for packages built from the php
ii php5-mysql 5.1.2-1.dotdeb MySQL module for php5
ii php5-pear 5.1.2-1.dotdeb PEAR - PHP Extension and Application Reposit

phpinfo() suggests that this module was NOT compiled with MySQL support:

'../configure' '--prefix=/usr' '--with-apxs2=/usr/bin/apxs2' '--with-config-file-path=/etc/php5/apache2' '--enable-memory-limit' '--enable-inline-optimization' '--disable-debug' '--with-regex=php' '--disable-rpath' '--disable-static' '--with-pic' '--with-layout=GNU' '--with-pear=/usr/share/php' '--enable-calendar' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--enable-track-vars' '--enable-trans-sid' '--enable-bcmath' '--with-bz2' '--enable-ctype' '--with-db4' '--with-iconv' '--enable-exif' '--enable-filepro' '--enable-ftp' '--enable-dbase' '--with-gettext' '--enable-mbstring' '--with-pcre-regex' '--enable-pdo' '--enable-shmop' '--enable-soap' '--enable-sockets' '--enable-simplexml' '--with-libxml-dir=/usr' '--with-dom=/usr' '--with-xsl=/usr' '--with-sqlite' '--enable-sqlite-utf8' '--enable-wddx' '--enable-tokenizer' '--with-xmlrpc' '--enable-yp' '--with-zlib' '--without-pgsql' '--with-kerberos=/usr' '--with-openssl=/usr' '--with-zip=/usr' '--enable-dbx' '--with-mime-magic=/usr/share/misc/file/magic.mime' '--with-exec-dir=/usr/lib/php5/libexec' '--without-mm' '--without-mysql' '--without-pdo-sqlite' '--without-sybase-ct'

So I am not sure how this is supposed to work ... ?

[ Parent | Reply to this comment ]

Posted by Anonymous (62.255.xx.xx) on Sun 26 Feb 2006 at 14:37
It does work! here: http://www.csee.me.uk/pi.php

Scroll down. MySQL is loaded (and mysqli!). I assume the core of PHP is compiled without it but it supports loadable modules (in this case package php5-mysql) which appear further down.

[ Parent | Reply to this comment ]

Posted by ncb (66.224.xx.xx) on Sun 26 Feb 2006 at 17:57
Good! I must admit I never looked at the phpinfo output. I just figured it was working when I used php to make a query :)

[ Parent | Reply to this comment ]

Posted by ncb (66.224.xx.xx) on Sun 26 Feb 2006 at 19:41

Just as an aside, using dpkg -l | grep php will show incomplete results. The package names get truncated, and often remove the string you are grep'ing for. For example, in the following the libapache2-mod-php5 that I know is installed is missing from the output.

# dpkg -l | grep php
ii  php5-common    5.1.2-1.dotdeb Common files for packages built from the php
ii  php5-mysql     5.1.2-1.dotdeb MySQL module for php5

A slightly better way is to pass the search string to dpkg rather than to grep, and then grep for lines starting with ii. This still cuts off the package names, but at least you get a complete list. Like so ...

# dpkg -l *php* | grep ^ii
ii  libapache2-mod 5.1.2-1.dotdeb PHP 5 scripting language - apache 2.0 module
ii  php5-common    5.1.2-1.dotdeb Common files for packages built from the php
ii  php5-mysql     5.1.2-1.dotdeb MySQL module for php5

A still better way is to set the bash COLUMNS var higher so the package names don't get truncated in the first place.

# COLUMNS=110 dpkg -l *php* | grep ^ii
ii  libapache2-mod-php5   5.1.2-1.dotdeb.2      PHP 5 scripting language - apache 2.0 module
ii  php5-common           5.1.2-1.dotdeb.2      Common files for packages built from the php5 source
ii  php5-mysql            5.1.2-1.dotdeb.2      MySQL module for php5

[ Parent | Reply to this comment ]

Posted by Anonymous (62.171.xx.xx) on Wed 1 Mar 2006 at 12:24
For phpmyadmin configuration:

"cp config.defualt.php config.inc.php"

Should be "cp config.default.php config.inc.php"

default instead of defualt simple typing error.

[ Parent | Reply to this comment ]

Posted by ncb (66.224.xx.xx) on Wed 1 Mar 2006 at 19:04
Thanks. I think I have all the typos that I know about fixed. It was pretty scary because when I confirmed the changes the tags in the code sections of the entire article were suddenly being interpreted as html tags, which hosed the whole thing (a preview button might be a nice addition there). Anyway, to fix it I had to delete everything and paste in the text from a backup copy, which seems to have worked.

[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Wed 1 Mar 2006 at 20:37
[ View Steve's Scratchpad | View Weblogs ]

Nicely done.

The editting system will be improved in the future, it was just a quick hack to give authors the ability to fix up mistakes without having to wait for me to do it.

For what its worth there are backups kept of articles, edits, and other things - so had things gone horribly wrong I could have restored it.

Steve

[ Parent | Reply to this comment ]

Posted by Anonymous (147.162.xx.xx) on Thu 2 Mar 2006 at 11:23
Well done, but I've just a question: why the client used by PHP is MySQL 4.1.15?
Is there a way to use a real 5.0 client (the mysql.so file)?

Thanks anyway for the tut!
Dave

[ Parent | Reply to this comment ]

Posted by ncb (66.224.xx.xx) on Thu 2 Mar 2006 at 15:55

I'm not sure if you're referring to the mysql-client package or the libmysqlclient14/15 packages. Here's a list of everything having to do with mysql on my system. Does yours look the same?

# COLUMNS=128 dpkg -l *mysql* | grep ^ii
ii  libdbd-mysql-perl          2.9007-0.dotdeb.0
ii  libmysqlclient14           4.1.15-0.dotdeb.1
ii  libmysqlclient15           5.0.18-3.dotdeb.1
ii  mysql-client-5.0           5.0.18-3.dotdeb.1
ii  mysql-common               5.0.18-3.dotdeb.1
ii  mysql-server               5.0.18-3.dotdeb.1
ii  mysql-server-5.0           5.0.18-3.dotdeb.1
ii  php5-mysql                 5.1.2-1.dotdeb.2

[ Parent | Reply to this comment ]

Posted by aztek (203.84.xx.xx) on Fri 28 Jul 2006 at 08:51
Hi ncb,

Mine is the same as yours above. Info.php under mysql has Client API Version 4.1.15, is the current version? If its not what particular file can we download from dotdeb to upgrade this?

Thanks.

[ Parent | Reply to this comment ]

Posted by Anonymous (82.181.xx.xx) on Sat 4 Mar 2006 at 23:21
It seems that with my Sarge and the packaged Apache2 the directive
"ServerTokens production"
does not work but
"ServerTokens Prod"
works.

[ Parent | Reply to this comment ]

Posted by nano (198.60.xx.xx) on Thu 16 Mar 2006 at 09:48
Thanks for putting all this together, it is very helpful.
I have just a question, by using apt-get install mysql-server will also download and install the development libraries for mysql? I am going to use an IRC program, and the IRC program requires the development libraries for mysql to be install. If apt-get install mysql-server doesn't install the development libraries how do I install them? or what would be the command to download and install them? Thanks for your help in advance.

Fernando

[ Parent | Reply to this comment ]

Posted by ncb (66.224.xx.xx) on Thu 16 Mar 2006 at 14:52

You're welcome. I'm glad it was helpful.

I'm sorry I don't know which development libraries you mean. If you can figure out the package name for what you want then you may be able to install it with apt-get.

If the package you are after is libmysqlclient15-dev then just apt-get install libmysqlclient15-dev will pull that package in from dotdeb.org.

You can browse dotdeb's repository at packages.dotdeb.org.

[ Parent | Reply to this comment ]

Posted by Anonymous (65.103.xx.xx) on Thu 16 Mar 2006 at 23:39
Thanks for you prompt reply. The IRC Program I want to install it requires the development libraries for mysql. I installed mysql with apt-get install mysql (I believe the server mysql, is that right? this just probably tells you about my knowledge about mysql) anyway, you mention above that by doing apt-get install libmysqlclient15-dev will install what I need, I will give it a try, however, is there such thing as libmysqlserver? since there is libmysqlclient15? Probably I am wrong... I am totally new to mysql.
Thanks for your patient and your help.

Fernando

[ Parent | Reply to this comment ]

Posted by ncb (66.224.xx.xx) on Fri 17 Mar 2006 at 05:59

If you want to know what all the available mysql-related Debian packages are, try going to www.debian.org/distrib/packages#search_packages, type "mysql" in the box, hit the search button and enjoy. Maybe scan the results for the words "development" or "library".

I'd guess what you want is libmysqlclient14-dev and/or libmysqlclient15-dev, both of which will be pulled from dotdeb.org if you've added it to sources.list.

There are lots of mysql related packages and I'm not familiar with most of them. I'm not aware however of a libmysql-server package or the like. I'd guess your irc app is going to be acting in the role of a client though, so ...

Hope that helps.

[ Parent | Reply to this comment ]

Posted by Anonymous (63.230.xx.xx) on Sat 18 Mar 2006 at 13:25
Had to enable mysql for php in php.ini

extension=mysql.so

also noticed that smarty is looking for myapp_index.tpl in the smarty templates dir not /var/www/mydomain.com/templates unless I missed something.

everything else looks great

Thank you

[ Parent | Reply to this comment ]

Posted by ncb (66.224.xx.xx) on Sun 19 Mar 2006 at 19:28
"Had to enable mysql for php in php.ini"
Interesting. I didn't have to do that. I assume it was done for me by one of the package installs along the way. Maybe we did things in a different order?
"also noticed that smarty is looking for myapp_index.tpl in the smarty templates dir not /var/www/mydomain.com/templates unless I missed something."

Hm. Looks like you're missing the "smarty" subirectory in that path. Maybe that's the problem. Following the instructions in this article, where smarty looks for the templates should be determined by the file /var/www/mydomain.com/includes/smarty_setup.inc, which has this....

// Initialize smarty paths
$smarty = new Smarty;
        $smarty->template_dir = '/var/www/mydomain.com/smarty/templates/';
        $smarty->compile_dir = '/var/www//mydomain.com/smarty/templates_c/';
        $smarty->config_dir = '/var/www/mydomain.com/smarty/configs/';
        $smarty->cache_dir = '/var/www/mydomain.com/smarty/cache/';

So, as long as php.ini's include_path contains /var/www/mydomain.com/includes (so php can find smarty_setup.inc), and smarty_setup.inc is included in the php script with require('smarty_setup.inc';, then smarty should be looking in /var/www/mydomain.com/smarty/* for it's directories.

Hope that helps.

[ Parent | Reply to this comment ]

Posted by nano (198.60.xx.xx) on Thu 30 Mar 2006 at 01:56
Hi, after I installed and configured phpmyadmin, I reloaded Apache but,I don't get the login to mysql. I got the following:

phpMyAdmin - error
phpMyAdmin was unable to read your configuration file!
This might happen if PHP finds a parse error in it or PHP cannot find the file.
Please call the configuration file directly using the link below and read the PHP error message(s) that you receive. In most cases a quote or a semicolon is missing somewhere.
If you receive a blank page, everything is fine.

config.inc.php

Did I do something wrong? Please help(I am still learning about this)

Fernando

[ Parent | Reply to this comment ]

Posted by ncb (66.224.xx.xx) on Thu 30 Mar 2006 at 08:43

I think you may indeed have an error in your config.inc.php file. If you followed this howto then that file should be at /usr/local/php5/phpMyAdmin-2.7.0-pl2/config.inc.php. Do like it says and check for semicolons etc wherever you made a change.

You can try a tail -f /var/log/apache2/error.log while attempting to load phpmyadmin and you may see an error telling you what line number of the file contains the error.

The reason you are not seeing the error in the browser BTW is because of the display_errors = Off setting in php.ini. This is one of the recommened settings for security reasons. Set it to on if you don't want to have to check the log for errors.

Hope that helps. Please post again if it doesn't.

[ Parent | Reply to this comment ]

Posted by Anonymous (212.170.xx.xx) on Wed 31 May 2006 at 12:38
Hello,

Will this install mysql 5 or mysql 4????

Thank you,
Fernando

[ Parent | Reply to this comment ]

Posted by ncb (66.224.xx.xx) on Wed 31 May 2006 at 15:42
MySQL5, using packages from dotdeb.org.

[ Parent | Reply to this comment ]

Posted by Anonymous (212.170.xx.xx) on Thu 1 Jun 2006 at 09:04
When you do this:

apt-get install mysql-server

You are installing mysql5 ????

[ Parent | Reply to this comment ]

Posted by ncb (66.224.xx.xx) on Thu 1 Jun 2006 at 15:07
Yes, but only after you ...

1) add a dotdeb.org mirror in your /etc/apt/sources.list file and ...
2) do apt-get update

as this article shows in the "Installing PHP5" section.

At least that's how it worked for me when I wrote the article.

Check out http://www.dotdeb.org.

[ Parent | Reply to this comment ]

Posted by Anonymous (62.143.xx.xx) on Fri 2 Jun 2006 at 06:23
Actually this doesn't work for me. apt-get complains that I need libc6 2.3.6 or greater.

libc6 2.3.6 doesn't ship with Sarge. Any idea how to resolve this problem?

[ Parent | Reply to this comment ]

Posted by ncb (66.224.xx.xx) on Fri 2 Jun 2006 at 14:41

Hm, I didn't run into that. I just today did apt-get update/upgrade on the box I used when writing the article and had success. I ended up with mysql-server-5.0.21-2, and (only) libc6-2.3.2.

There was one hiccup. Initially, after apt-get upgrade, the mysql-server-5.0 and mysql-client-5.0 packages would not upgrade because they wanted the new package libmysqlclient15off. To fix that I just did "apt-get install libmysqlclient15off" which removed the old libmysqlclient15 package, installed the new libmysqlclient15off package from the dotdeb repository, and then proceeded in upgrading mysql-server-5.0 etc.

Here's a list of the installed packages/versions related to mysql after the upgrade.

libdbd-mysql-perl    2.9007-0.dotdeb.0 
libmysqlclient14     4.1.15-0.dotdeb.1
libmysqlclient15off  5.0.21-2.dotdeb.1
mysql-client-5.0     5.0.21-2.dotdeb.1
mysql-common         5.0.21-2.dotdeb.1
mysql-server         5.0.21-2.dotdeb.1
mysql-server-5.0     5.0.21-2.dotdeb.1
php5-mysql           5.1.4-1.dotdeb.2

Also note that the mysql-server-5.0 package I ended up with requires only libc6 >= 2.3.2, which I verified with the command "dpkg-query -s mysql-server-5.0".

So, I don't know what's wanting the higher verison of libc6, but as far as I can tell it's not any of the packages from dotdeb.org that I used for this article. Are you sure you aren't pointing at a testing or unstable repository in your sources.list file? Mine looks like this:

deb http://debian.oregonstate.edu/debian/ stable main
deb-src http://debian.oregonstate.edu/debian/ stable main

deb http://security.debian.org/ stable/updates main

# For any volatile packages
deb http://volatile.debian.net/debian-volatile stable/volatile main

# Add dotdeb so we can get php5 and stuff that debian stable lacks
# See http://www.dotdeb.org/
deb http://dotdeb.pimpmylinux.org/ stable all
deb-src http://dotdeb.pimpmylinux.org/ stable all

Hope that helps.

[ Parent | Reply to this comment ]

Posted by kevinc (71.108.xx.xx) on Sun 29 Oct 2006 at 04:05
I had the same problem and after a little exploration and reading, I have the solution to installing MySQL 5 Server.

Run one of the following commands in the shell with the ncp's sources.list file from above:
$> apt-cache policy
Sample Output:
 990 http://security.debian.org sarge/updates/main Packages
     release v=3.1,o=Debian,a=stable,l=Debian-Security,c=updates/main
     origin security.debian.org
 500 http://dotdeb.pimpmylinux.org stable/all Packages
     release o=packages.dotdeb.org,a=sarge,l=packages.dotdeb.org
     origin dotdeb.pimpmylinux.org
 990 http://debian.oregonstate.edu stable/main Packages
     release v=3.1r4,o=Debian,a=stable,l=Debian,c=main
     origin debian.oregonstate.edu
(From Left to Right, Down) This displays the priority number in which candidate sources are selected by apt, the magical mirror line, and pertinent identification information for each deb mirror.

Now, look for the priority number associated with a DotDeb mirror. It is 500. The number is smaller than the others (990, 990).

Now run:
$> apt-cache policy mysql-server
Sample Output:
  Installed: None
  Candidate: 4.0.24-10sarge2
  Version Table:
     5.0.26-0.dotdeb.1 0
        500 http://dotdeb.pimpmylinux.org stable/all Packages
        100 /var/lib/dpkg/status
     4.1.15-0.dotdeb.4 0
        500 http://dotdeb.pimpmylinux.org stable/all Packages
     4.0.24-10sarge2 0
        990 http://debian.oregonstate.edu stable/main Packages
        990 http://security.debian.org sarge/updates/main Packages
Notice how apt selected the distro with the highest priority and not the Dotdeb distro for MySQL5.

We want apt to get MySQL 5 from Dotdeb so here's the fix:

Create or Edit your "/etc/apt/preferences" file.

Add the following lines to it:

Sample File:
Package: *
Pin: origin dotdeb.pimpmylinux.org
Pin-Priority: 2000
Explanation:
Package: [wildcard for all packages or you can list specific pkg names]
Pin: origin [dotdeb mirror here]
Pin-Priority: [any number larger than other priorities (i.e. 990, etc.)]
Now run the apt-cache policy commands again. Notice the difference?

Have fun. :)

Hope this helps. Keep up the good work ncp.

[ Parent | Reply to this comment ]

Posted by Anonymous (129.138.xx.xx) on Thu 8 Jun 2006 at 20:04
Your instructions also worked great on my Ubuntu 6.06

The only differences I did for Ubuntu were:

Instead of installing Smarty and PhpMyAdmin by unpacking them in /usr/local/php5/ I installed their packages which I got from apt-get. The only difference this way is that the configuration files for phpmyadmin in now in /etc/phpmyadmin and smarty was installed in /usr/share/php/smarty. So I just changed paths as I went through your instructions and it worked great!

Thanks for posting this. It makes it really easy to get a great and up-to-date webserver up for use in less than an hour!

[ Parent | Reply to this comment ]

Posted by Anonymous (129.138.xx.xx) on Thu 8 Jun 2006 at 22:46
Your instructions also worked great on my Ubuntu 6.06

The only differences I did for Ubuntu were:

Instead of installing Smarty and PhpMyAdmin by unpacking them in /usr/local/php5/ I installed their packages which I got from apt-get. The only difference this way is that the configuration files for phpmyadmin in now in /etc/phpmyadmin and smarty was installed in /usr/share/php/smarty. So I just changed paths as I went through your instructions and it worked great!

Thanks for posting this. It makes it really easy to get a great and up-to-date webserver up for use in less than an hour!

[ Parent | Reply to this comment ]

Posted by fernandoch (217.14.xx.xx) on Tue 13 Jun 2006 at 09:02
Hi, You cannot edit the document and fix the typos you have made in the article? Here is another mistake: This sentence
Now we need to make a template, called myapp_index.tpl, in the directory /var/www/mydomain.com/templates/. Something like the following
Should be replaced by:
Now we need to make a template, called myapp_index.tpl, in the directory /var/www/mydomain.com/smarty/templates/. Something like the following
You forgot to add the smarty directory.

[ Parent | Reply to this comment ]

Posted by ncb (66.224.xx.xx) on Tue 13 Jun 2006 at 17:08
Apparently the article is too old for me to edit. When I try I'm informed that only articles that are still on the front page are allowed to be edited. Sorry about the typos. I fixed the ones I knew about while I still could. I'm maintaining another copy here ... http://www.sleepygeek.com/howto/lamp_howto.asp

[ Parent | Reply to this comment ]

Posted by Anonymous (194.3.xx.xx) on Wed 12 Jul 2006 at 12:25
Execellent job.
I followed this and it worked out perfectly.
More grease to your elbow.
Dr ADEDIRAN Shegun.
Paris - France

[ Parent | Reply to this comment ]

Posted by Anonymous (137.132.xx.xx) on Thu 13 Jul 2006 at 13:13
Thank you very much :-* !

You rescued me!

I could not gain much after 2 weeks of configuration before I read you article ;-) Then I need only 20min to do the things!

Thank you again, good job! Keep on!

[ Parent | Reply to this comment ]

Posted by duckpond (129.15.xx.xx) on Sat 22 Jul 2006 at 06:54
I followed the instruction and... The first installation went smooth on this LAMP part, I even set up a wordpress site and started posting. The second time I wasn't so lucky, I think I did exactly the same thing (on the LAMP) part, the installed packages are:
ii  libapache2-mod-php5   5.1.4-1.dotdeb.2      PHP 5 scripting language - apache 2.0 module
ii  php5-cgi              5.1.4-1.dotdeb.2      PHP 5 scripting language
ii  php5-common           5.1.4-1.dotdeb.2      Common files for packages built from the php5 source
ii  php5-dev              5.1.4-1.dotdeb.2      Files for PHP5 module development
ii  php5-gd               5.1.4-1.dotdeb.2      GD module for php5
ii  php5-mcrypt           5.1.4-1.dotdeb.2      MCRYPT module for php5
ii  php5-mysql            5.1.4-1.dotdeb.2      MySQL module for php5
ii  phpmyadmin            2.8.1-1               set of PHP-scripts to administrate MySQL over the WWW
but the phpinfo() out put shows the php5-mysql module was not compiled (just as someone posted in the previous comment), even worse is that I couldn't see mysql part down below the output neither, that being said, the module IS NOT working. I wonder what can I do to fix this problem? I alreadly tried to reinstall php5-mysql, to no avail. Maybe I should reinstall some other packages as well? Thanks, FYI:
'../configure' '--prefix=/usr' '--with-apxs2=/usr/bin/apxs2' '--with-config-file-path=/etc/php5/apache2' '--enable-memory-limit' '--enable-inline-optimization' '--disable-debug' '--with-regex=php' '--disable-rpath' '--disable-static' '--with-pic' '--with-layout=GNU' '--with-pear=/usr/share/php' '--enable-calendar' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--enable-track-vars' '--enable-trans-sid' '--enable-bcmath' '--with-bz2' '--enable-ctype' '--with-db4' '--with-iconv' '--enable-exif' '--enable-filepro' '--enable-ftp' '--enable-dbase' '--with-gettext' '--enable-mbstring' '--with-pcre-regex' '--enable-pdo' '--enable-shmop' '--enable-soap' '--enable-sockets' '--enable-simplexml' '--with-libxml-dir=/usr' '--with-dom=/usr' '--with-xsl=/usr' '--with-sqlite' '--enable-sqlite-utf8' '--enable-wddx' '--enable-tokenizer' '--with-xmlrpc' '--enable-yp' '--with-zlib' '--without-pgsql' '--with-kerberos=/usr' '--with-openssl=/usr' '--enable-dbx' '--with-mime-magic=/usr/share/misc/file/magic.mime' '--with-exec-dir=/usr/lib/php5/libexec' '--without-mm' '--without-mysql' '--without-pdo-sqlite' '--without-sybase-ct'

[ Parent | Reply to this comment ]

Posted by aztek (203.84.xx.xx) on Wed 26 Jul 2006 at 03:40
Hi,

I hope you can assist me on this since im still new to debian. I've tried to follow your manual but then when i tried to access http://192.10.10.16 (sample ip) i am directed to the Apache test page instead of the defined virtual host directory. i have created index.html in /var/www/debian.com/public this is my virtual host directory.

I have also tried to create my virtual host on /usr/share/apache/default-configs/apache/httpd.conf but same problem was encountered, have activated NameVirtualHost * too. I've defined host as

192.10.10.16 debian.debian.com debian

did i miss something? I hope you could assist me on this. Thanks in advance.

[ Parent | Reply to this comment ]

Posted by ncb (66.224.xx.xx) on Wed 26 Jul 2006 at 15:04
When the request comes in for the IP, Apache can't determine which virtual domain it is for and just serves up the default. Try disabling the default site with the command ...

a2dissite default

also make sure you have enabled your site with the command ...

a2ensite yoursite

(where yoursite is the name of the file defining your site in www:/etc/apache2/sites-available)

[ Parent | Reply to this comment ]

Posted by aztek (203.84.xx.xx) on Thu 27 Jul 2006 at 00:02
Hi ncb,

Your advise did work when i disabled the default site. Thanks a lot for your help and time. Keep up the good work.

[ Parent | Reply to this comment ]

Posted by aztek (203.84.xx.xx) on Thu 27 Jul 2006 at 10:13
Hi newbie here,

I've tried installing phpmyadmin from dotdeb.pimpmylinux.org by invoking:
#apt-get install phpmyadmin
But when i tried to invoke http://192.10.10.10/phpmyadmin i was prompted by a "Not found" error.
Do i need to configure something else?

Thanks for your help in advance.

[ Parent | Reply to this comment ]

Posted by ncb (66.224.xx.xx) on Thu 27 Jul 2006 at 16:07
The last I checked there is no package for phpmyadmin at dotdeb.org for you to have installed. That's why this article tells you to download phpmyadmin directly from www.phpmyadmin.net and install it in /usr/local.

One of the specific goals of this howto (read the first paragraph) was to avoid installing php4 stuff from sarge, and to stick with php5 only. If you did "apt-get install phpmyadmin" then you have pulled in php4 stuff from sarge (and from dotdeb too) that you don't need (for this howto anyway).

To help you backtrack I went to the system that I used to write this howto, did "apt-get update", "apt-get upgrade", and then "apt-get -s install phpmyadmin" to see what packages would be pulled in (-s is for simulate but don't really install). Below is the output.

www:~# apt-get -s install phpmyadmin
Reading Package Lists... Done
Building Dependency Tree... Done
The following extra packages will be installed:
  apache-common libapache-mod-php4 libzzip-0-12 php4 php4-common ucf
Suggested packages:
  apache apache-ssl apache-perl php4-pear php4-gd php5-gd
Recommended packages:
  debconf-utils
The following NEW packages will be installed:
  apache-common libapache-mod-php4 libzzip-0-12 php4 php4-common phpmyadmin ucf
0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
Inst ucf (1.17 Debian:3.1r2/stable)
Inst apache-common (1.3.33-6sarge1 Debian:3.1r2/stable, Debian-Security:3.1/stable)
Inst libzzip-0-12 (0.12.83-4 Debian:3.1r2/stable)
Inst php4-common (4:4.4.2-0.dotdeb.2 packages.dotdeb.org:sarge)
Inst libapache-mod-php4 (4:4.4.2-0.dotdeb.2 packages.dotdeb.org:sarge)
Inst php4 (4:4.4.2-0.dotdeb.2 packages.dotdeb.org:sarge)
Inst phpmyadmin (4:2.6.2-3sarge1 Debian:3.1r2/stable, Debian-Security:3.1/stable)
Conf ucf (1.17 Debian:3.1r2/stable)
Conf apache-common (1.3.33-6sarge1 Debian:3.1r2/stable, Debian-Security:3.1/stable)
Conf libzzip-0-12 (0.12.83-4 Debian:3.1r2/stable)
Conf php4-common (4:4.4.2-0.dotdeb.2 packages.dotdeb.org:sarge)
Conf libapache-mod-php4 (4:4.4.2-0.dotdeb.2 packages.dotdeb.org:sarge)
Conf php4 (4:4.4.2-0.dotdeb.2 packages.dotdeb.org:sarge)
Conf phpmyadmin (4:2.6.2-3sarge1 Debian:3.1r2/stable, Debian-Security:3.1/stable)

[ Parent | Reply to this comment ]

Posted by aztek (203.84.xx.xx) on Fri 28 Jul 2006 at 01:46
Your right ncb. PHP4 was also loaded, i guess i'll have to apt-get remove phpmyadmin and follow your howto. I thought by doing apt-get install phymyadmin would shorten the procedure, my bad. Anyhow thanks a lot again for your help.

[ Parent | Reply to this comment ]

Posted by ncb (66.224.xx.xx) on Fri 28 Jul 2006 at 15:30
Well to get back to where you started before you installed phpmyadmin you will probably need do something more like this (cutting and pasting packages from above)...

apt-get -s remove apache-common libapache-mod-php4 libzzip-0-12 php4 php4-common ucf


(-s is your friend. Use it to verify what will happen, and then do it again without the -s when you are satisfied with what it will do)

Note though, that command assumes your system has exactly the same packages installed as mine does, which is a big assumption. My point is that just removing phpmyadmin will not retroctively remove all of phpmyadmin's dependencies that were installed. (I think aptitude might do a better job at this kind of thing but I've not really played with it much).

Also note that if you want to make things easier, you could try peterhoeg's very good suggestion from comment #4 above, which is to install the php4-cgi package to satisfy dependencies on php4, and then just not use it. That should let you install phpmyadmin, smarty, and adodb all from sarge with apt-get. They won't be the latest versions but this *is* Sarge, so... if had I thought of it, this article would have been much shorter. It should work.

[ Parent | Reply to this comment ]

Posted by aztek (203.84.xx.xx) on Sat 29 Jul 2006 at 01:29
Thanks ncb, I guess i'll do your howto on phpmyadmin. Aside from its the most current on stable its additional knowledge to do things manually and what twiks to be done. Again a lot of thanks.

[ Parent | Reply to this comment ]

Posted by Anonymous (81.61.xx.xx) on Wed 16 Aug 2006 at 14:38
Very good, but in my release of phpmyadmin I must copy the file config.inc.php into the /usr/local/php5/phpmyadmin directory, because in the /usr/local/php5/phpmyadmin/libraries don't work

Esteve

My phpMyAdmin release is 2.8.2.2

[ Parent | Reply to this comment ]

Posted by Anonymous (83.77.xx.xx) on Sun 24 Sep 2006 at 10:07
Hello I am not sure how old this is or if this message will be read. I have been trying for 2 weeks now to get Apache2, mysql and php to play nice together. FINALLY with this site I was able to do it. I don't really mind the 2 weeks I spent trying, because it taught me a lot about Debian / Linux. Although I did consult some other sites while working with this one, but it was just to double-check to see if what you were explaining was what other's were doing since I had tried so many tutorials ... But this site was the most thorough I've come across. There was (up to now as I only got Apache2, mysql and php5) just one thing that confused me and that was the part where you describe how to create a root password ... for me anyway, it should be 'myslq -u root -p' and not 'mysqladmin' ... it took a while until I came to the idea to just use 'mysql', and everything worked fine. Thanks again,and again!! Kalmeida (kundco)

[ Parent | Reply to this comment ]

Posted by Anonymous (66.224.xx.xx) on Sun 24 Sep 2006 at 16:48
This article is getting old now, but I still get an e-mail whenever there's a new comment added. I'm glad it was helpful. I've kept a more up to date version of it at the following URL.

http://www.sleepygeek.com/howto/lamp_howto.asp

[ Parent | Reply to this comment ]

Posted by radiac (81.174.xx.xx) on Wed 8 Nov 2006 at 12:48

In my default installation of Apache 2 on Debian Sarge, apache2.conf states:

Include /etc/apache2/conf.d/[^.#]*

This means that Apache will only include files without the period or hash characters - conf.d/local_configs.conf will therefore not get included (unless you've changed apache2.conf, which I didnt notice).

Noticed this when I found error pages were ignoring my ServerTokens directive. Rename it to local_configs and you'll be ok. Check your configs.

[ Parent | Reply to this comment ]

Posted by radiac (81.174.xx.xx) on Wed 8 Nov 2006 at 13:11

Having looked into this in more detail, it appears that I was wrong. I assumed it was a regular expression which would explain why my file wasn't being loaded. However, according to the apache docs, include uses fnmatch, so I can't see why it would ever treat it like that. I was very probably just reloading the wrong server... so just ignore me ;)

May be worth noting though that it will ignore files starting with a period or a hash character.

[ Parent | Reply to this comment ]

Posted by richardun (72.177.xx.xx) on Sat 11 Nov 2006 at 03:51
http://security.debian.org stable/updates/main has phpmyadmin...

% apt-get install phpmyadmin


Enjoy!

[ Parent | Reply to this comment ]

Posted by pfarrell (68.72.xx.xx) on Wed 22 Nov 2006 at 16:53

Excellent article. Thanks for the help. Was able to complete a migration between Debian servers thanks to your well written work.

http://patf.net

[ Parent | Reply to this comment ]

Posted by gnorm (71.56.xx.xx) on Mon 4 Dec 2006 at 13:54
I am having a problem with phpmyadmin. In my browser at http://www.mysite.com/phpmyadmin I get index of /phpmyadmin. I have checked apache2.conf and index.php is listed in DirectoryIndex. I have double checked to make sure I have strictly followed all of the instructions up to this point. Any thoughts would be appreciated.

[ Parent | Reply to this comment ]

Posted by gnorm (71.56.xx.xx) on Tue 5 Dec 2006 at 01:24
I figured out what my problem was, I added the index.php to the DirectoryIndex in my sites-available file and restarted apache2.

Everything works for me now except the final example, putting it all together. In the final example I get a blank page in my browser when I go for the updated index.php. I see the "SELECT * pets" statement which calls the data from the database, but I don't see a statement to USE the database mydomain. Should there be a statement to use the database or is that done in another manner? Any suggestions will be appreciated.

[ Parent | Reply to this comment ]

Posted by gnorm (71.56.xx.xx) on Tue 5 Dec 2006 at 06:15
Finally, it works, this is a great tutorial. I learned a lot about Debian, and the tools covered, thanks.

[ Parent | Reply to this comment ]

Posted by Anonymous (24.221.xx.xx) on Wed 31 Jan 2007 at 20:14
Interesting. However, couldn't follow it. The paths for phpmyadmin, dodb
and smarty do not match what apt-get installs. Since I am new to this,
I am not sure which directoy the executables are in. I made it as far as
getting mysql and phpmyadmin up.

Joe
jtannenba@yahoo.com

[ Parent | Reply to this comment ]

Posted by tannenba (24.221.xx.xx) on Wed 31 Jan 2007 at 21:39
Further reading of comments show you didn't want to apt-get the pkgs
to keep the php4 stuff out. could all of the php4 stuff be gotten out?
Is that why after an upgrade from mysql4 to mysql5 the client loaded is
5.0.32 from dot.deb, but the info in mysql-admin says 4.0.24?? and mysql
5 scrips don't work (mysqli missing)?

Thanks,
Joe

[ Parent | Reply to this comment ]

Posted by bcfantasy (69.168.xx.xx) on Sun 11 Mar 2007 at 04:16
I've been having trouble getting PHPMyAdmin running using #aptitude install phpmyadmin. I found this guide through Google and it looks great. I'll probably end up installing Smarty, too. Anyway, I was looking over the directions for PHPMyAdmin Configuration and I came to the lines:

$cfg['PmaAbsoluteUri'] = '';

and change it to something like this.

$cfg['http://www.mydomian.com/phpmyadmin'] = '';

Shouldn't you actually change it to something like this:

$cfg['PmaAbsoluteUri'] = 'http://www.mydomain.com/phpmyadmin';

or am I wrong? Either way, great job on this LAMP guide. (Sorry, I don't know how to make the code appear in the gray boxes. Maybe someone can fill me in on how to do that for future reference.)

[ Parent | Reply to this comment ]

Posted by Anonymous (66.224.xx.xx) on Thu 15 Mar 2007 at 16:53
You are right. I made a lot of typos in this article and I can no longer edit it to correct them. I have a more current version at at http://www.sleepygeek.com/howto/lamp_howto.asp

[ Parent | Reply to this comment ]

Posted by aztek (203.84.xx.xx) on Tue 20 Mar 2007 at 01:00
Hi ncb,

Your howto is really great. I was going smoothly till i reached "A Smarter Smarty Setup". I get this error on my server when i tried to access index.php thru my browser. I did a #tail -f /var/log/apache2/error.log to monitor it from my server.

[Tue Mar 20 16:37:55 2007] [error] [client 10.100.0.200] PHP Fatal error: require() [<a href='function.require'>function.require</a>]: Failed opening required 'smarty_setup.inc' (include_path='.:/usr/local/php5/Smarty-2.6.18/libs:/var/www/debi an.com/includes') in /var/www/debian.com/public/myapp/index.php on line 4

Here's my smarty_setup.inc:
<?php

// Include Smarty.class.php (this is /usr/local/php5/Smarty-x.x.x/Smarty.class.php)
// The full path is not needed here because it is defined in php.ini's include_path.
require('Smarty.class.php');

// Initialize smarty paths
$smarty = new Smarty;
$smarty->template_dir = '/var/www/debian.com/smarty/templates/';
$smarty->compile_dir = '/var/www/debian.com/smarty/templates_c/';
$smarty->config_dir = '/var/www/debian.com/smarty/configs/';
$smarty->cache_dir = '/var/www/debian.com/smarty/cache/';

?>

Here's my php.ini:
;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
;include_path = ".:/usr/share/php"
;include_path = ".:/usr/local/php5/Smarty-2.6.18/libs"
include_path = ".:/usr/local/php5/Smarty-2.6.18/libs:/var/www/debian.com/in cludes"
;

Here's my index.php
<?php

// Load Smarty setup
require('smarty_setup.inc');

// Set a smarty variable
$smarty->assign('name', 'Johnny');

// Display the smarty template
$smarty->display('myapp_index.tpl');

?>

I hope you could assist me on this, thanks in advance.

[ Parent | Reply to this comment ]

Posted by ncb (66.224.xx.xx) on Tue 20 Mar 2007 at 13:49
Did you reload Apache after changing php.ini?

BTW, as I've mentioned in many of the comments above, I have a more current version of this article (with a lot fewer typos) at http://www.sleepygeek.com/howto/lamp_howto.asp

[ Parent | Reply to this comment ]

Posted by aztek (203.84.xx.xx) on Tue 20 Mar 2007 at 23:33
Yes ncb i reloaded apache every time i edit php.ini, your typos helped me understand how debian works, but it seems i cant find a solution on this one, anyway i'll try to check it against your referred site. Your howto has brought me this far since i started learning debian. thanks for your time and assistance.

[ Parent | Reply to this comment ]

Posted by ncb (66.224.xx.xx) on Wed 21 Mar 2007 at 20:57
Hmmm. Well check for typos. The include_path you posted has a space in it, but I suspect that's just from when you pasted in. Also make sure you created the includes directory and the setup smarty_setup.inc where you think you did. You've probably already done all that. Let me know if you still can't figure it out and I'll look at it some more.

[ Parent | Reply to this comment ]

Posted by Anonymous (203.84.xx.xx) on Fri 23 Mar 2007 at 09:07
got it ncb i made some typos along the way. by the way you had some typos in your given site i hope you can check on this so others wont have problems later.

$smarty->compile_dir = '/var/www//mydomain.com/smarty/templates_c/';

there's a double slash before mydomain.com. Again thanks a lot.

[ Parent | Reply to this comment ]

Posted by ncb (66.224.xx.xx) on Fri 23 Mar 2007 at 11:39
Glad you figured it out. And I fixed that. Thanks a lot.

[ Parent | Reply to this comment ]

Posted by Anonymous (85.179.xx.xx) on Sun 25 Mar 2007 at 13:41
Hey men!
Thx a lot, was very helpful and easy. Keep up the good work!

[ Parent | Reply to this comment ]

Posted by Anonymous (24.151.xx.xx) on Sun 15 Apr 2007 at 16:02
Hello Debian Administrators,

Are the dotdeb.org mirrors down? Getting 404 error when apt-get update/upgrade.
Changed sources.list to some of the other mirror sites and still received the same 404 not found. What's the scoop?

[ Parent | Reply to this comment ]

Posted by Anonymous (213.207.xx.xx) on Wed 27 Jun 2007 at 08:21
I haven't used Debian for years but the recent purchase of a Linux blade rental has brought me back because of the small footprint.

I notice the article refers to the install of LAMP for Sarge which is what I want but that the mirrors from dotdeb.org are shown as 'stable' which is actually Etch. The switch to Etch happened on 8 April 2007 I think.

This caused all sorts of dependency problems on my blade when I tried to follow these instructions until I figured out that Sarge is 'oldstable'. To fix this I made explicit reference to the 'sarge' distribution:

deb http://dotdeb.pimpmylinux.org/ sarge all
deb-src http://dotdeb.pimpmylinux.org/ sarge all
I'll probably leave it like this until I can figure out how to safely upgrade my blade to Etch.

Steve

[ Parent | Reply to this comment ]

Posted by ncb (66.224.xx.xx) on Fri 29 Jun 2007 at 13:19
I've pretty much stopped maintaining this howto as it's now pretty dated, but one thing you might try to simplify your life is to download the server edition of Ubuntu and check the LAMP server option. It's Debian based and will get you most of the way there in about an hour.

[ Parent | Reply to this comment ]

Posted by Anonymous (86.154.xx.xx) on Fri 3 Aug 2007 at 08:50
your guide shows

<Files *.inc>
Order allow,deny
Deny from all
</Files *.inc>

but that didn't work for me and I infact get the error:
# /etc/init.d/apache2 restart
Forcing reload of web server (apache2)...apache2: Syntax error on line 195 of /etc/apache2/apache2.conf: Syntax error on line 4 of /etc/apache2/conf.d/local_configs.conf: </Files> directive missing closing '>'
failed!

which is fixed by using
<Files *.inc>
Order allow,deny
Deny from all
</Files>

Hope this helps anyone else!

best wishes,
adam
game-zero.com

[ Parent | Reply to this comment ]

Posted by Anonymous (193.77.xx.xx) on Sat 1 Mar 2008 at 14:48
I have more domains on my apache2. For every domain I have my own configuration file. And for every domain I have access and error log in these file. Now I want to have one global log and put it to apache2.conf

# Global error log.
ErrorLog /public_html/logs/error.log

# Global access log
LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
CustomLog /public_html/logs/access_log common

It works but not good ,( It logs only errors and access on localhost (192.168.3.1) but domains logging work not :( How to correct that?
Thx, Bojan

[ Parent | Reply to this comment ]

Posted by Anonymous (202.152.xx.xx) on Wed 19 Mar 2008 at 08:49
GREAT!!! IT WORKS!!! HAHAHAHAHAHA!! THANKS TO YOU GUYS!

[ Parent | Reply to this comment ]

Posted by Anonymous (203.162.xx.xx) on Wed 10 Jun 2009 at 03:09
Error For me when I config apache2 to change default site, anybody help me, please.
===
root@ubuntu:/etc/apache2/sites-available/mysite# sudo /etc/init.d/apache2 restart
* Restarting web server apache2 Syntax error on line 10 of /etc/apache2/sites-enabled/mysite/default:
<Directory> directive missing closing '>'
[fail]
===

[ Parent | Reply to this comment ]

Sign In

Username:

Password:

[Register|Advanced]

 

Flattr

 

Current Poll

What do you use for configuration management?








( 473 votes ~ 5 comments )