# Installing Apache2 with PHP5.x (incl. old Apache+PHP4.x)

## theProphecy

New: Installing Apache2 with PHP5.x

It has been quite a while since I was poking around with my Gentoo servers last, but recently I picked up, and started building myself some stripped down, gentoo servers with focus on security and stability, but of course, I couldn't accept that PHP5.x was not to be installed "just" because it's marked unstable. Hey, a developer needs the cutting edge, aye? hehe....

Actually Apache 2.x and PHP5.x is quite easy to compile, configure and run, so follow these steps and your web server should be up-and-ready for use.

Notice: This tutorial is tested/focused on x86 users, unknown results on any other arch!

Step 1. - Compiling Apache2.x

Because Apache 2.x has been marked as stable, it's easier than ever to install apache, just emerge it

```
# emerge apache
```

This will most probably emerge at most the following (tested on a fresh base system)

```
These are the packages that I would merge, in order:

Calculating dependencies ...done!

[ebuild  N    ] net-www/gentoo-webroot-default-0.2

[ebuild  N    ] dev-libs/apr-0.9.6-r3

[ebuild  N    ] app-misc/mime-types-4

[ebuild  N    ] dev-libs/apr-util-0.9.6-r2

[ebuild  N    ] net-www/apache-2.0.54-r31
```

If you plan on using https (ssl) with apache, remember to check if ssl is enabled (should be by default, but never hurts to be sure):

```
# emerge -pv apache

These are the packages that I would merge, in order:

Calculating dependencies ...done!

[ebuild   R   ] net-www/apache-2.0.54-r31  -apache2 -debug -doc -ldap -mpm-leader -mpm-peruser -mpm-prefork -mpm-threadpool -mpm-worker -no-suexec (-selinux) +ssl -static-modules -threads 0 kB

```

Step 2. - Compiling PHP5.x

In order to compile PHP5.x (and not PHP4.x), be sure to use dev-lang/php, and not dev-php/php.

Now that we have come to php, we also need to use the ACCEPT_KEYWORD="~x86", because the ebuild has been marked as unstable!

Step 2.1 - Determining which USE flags to use

In order to get extra features into PHP, we now need to decide which we wan't, and which we don't wan't.

Notice:Don't forget to add the 'apache2' USE flag!

To see which USE flags are used by default, issue:

```
# ACCEPT_KEYWORDS="~x86" emerge -pv dev-lang/php

These are the packages that I would merge, in order:

Calculating dependencies ...done!

[ebuild   R   ] dev-lang/php-5.0.5-r4  -adabas -apache -apache2* -bcmath* +berkdb* -birdstep +bzip2 -calendar -cdb -cgi -cjk -cli +crypt -ctype -curl -curlwrappers -db2 -dba -dbase -dbmaker -debug -discard-path -doc -empress -empress-bcs -esoob -exif -fdftk -filepro -firebird -flatfile -force-cgi-redirect -frontbase -ftp -gd* -gd-external +gdbm* -gmp -hardenedphp -hyperwave-api -iconv -imap -informix -inifile -interbase -iodbc -ipv6 -java-external -kerberos -ldap -libedit -mcve -memlimit -mhash -ming -mnogosearch -msql -mssql +mysql -mysqli +ncurses +nls -oci8 -oci8-instant-client -odbc -oracle7 -ovrimos -pcntl -pcre -pdo-external -pear -pfpro -pic -posix* -postgres -qdbm +readline -recode -sapdb -sasl -session* -sharedext -sharedmem -simplexml* -snmp -soap -sockets* -solid +spell -spl -sqlite* +ssl -sybase -sybase-ct -sysvipc -threads -tidy* -tiff -tokenizer +truetype -wddx +xml2 -xmlrpc -xpm -xsl -yaz -zip +zlib 0 kB

```

Step 2.2 - Compiling PHP5.x with the USE flags you have choosen

Now personally I like to select only the exact features I like, therefor my compile command would look like this:

```
# USE="*- apache2 bcmath mysql posix session simplexml tidy truetype bzip2 ncurses nls readline xml2 sqlite crypt spell sockets gd jpeg" ACCEPT_KEYWORDS="~x86" emerge -p dev-lang/php

These are the packages that I would merge, in order:

Calculating dependencies ...done!

[ebuild  N    ] net-mail/mailbase-1

[ebuild  N    ] mail-mta/ssmtp-2.61

[ebuild  N    ] media-libs/libpng-1.2.8-r1

[ebuild  N    ] app-text/aspell-0.60.4

[ebuild  N    ] media-libs/freetype-2.1.10

[ebuild  N    ] app-text/htmltidy-4.8.6

[ebuild  N    ] dev-libs/libmcrypt-2.5.7

[ebuild  N    ] media-libs/t1lib-5.0.2

[ebuild  N    ] media-libs/jpeg-6b-r6

[ebuild  N    ] net-www/gentoo-webroot-default-0.2

[ebuild  N    ] dev-libs/apr-0.9.7

[ebuild  N    ] app-misc/mime-types-4

[ebuild  N    ] dev-libs/apr-util-0.9.7

[ebuild  N    ] net-www/apache-2.0.55

[ebuild  N    ] app-admin/eselect-1.0_rc2

[ebuild  N    ] app-admin/eselect-php-0.96

[ebuild  N    ] dev-db/mysql-5.0.16-r3

[ebuild  N    ] perl-core/Storable-2.15

[ebuild  N    ] dev-perl/Net-Daemon-0.38

[ebuild  N    ] dev-perl/PlRPC-0.2018

[ebuild  N    ] dev-perl/DBI-1.48

[ebuild  N    ] dev-perl/DBD-mysql-3.0002_p4

[ebuild     U ] sys-devel/m4-1.4.4 [1.4.2-r1]

[ebuild  N    ] dev-libs/libxml2-2.6.22

[ebuild  N    ] dev-lang/php-5.0.5-r4

```

Notice:The compile process might halt with a warning telling you that a selected feature needs another, in that case you will need to add this needed feature to your compile USE flag.

It is a good idea to write down which USE flags you have added.

This compile might take a while depending on the power of your system, but when it finally finishes, we a ready to move onto the next step.

Step 3. - Testing our Apache2 Install

It's always a good idea to test the installed software, to better determin the origin of possible warnings and/or errors.

Step 3.1 - Configuring ServerName in httpd.conf

To get rid of the "Could not determine the servers fully qualified domain name..." when running apache, we will edit the '#ServerName localhost' line in the httpd.conf file:

```
# nano -w /etc/apache2/httpd.conf

#ServerName localhost

// First uncomment the line

ServerName localhost

// Then edit the line to fit your current IP and the port the webserver listens on.

// In this example, if your ip is 192.168.0.1 and the port is 80 (default)

ServerName 192.168.0.1:80
```

Step 3.2 - Testing the Apache server

Quite simple:

```
# /etc/init.d/apache2 start

 * Starting apache2 ...                                                                                                                                                [ ok ]
```

If no errors showed, it's up and running, and just to be sure, try opening a browser and go to your servers ip, and you should be greeted with Apache default install screen.

Step 4. - Configuring Apache2.x with PHP5.x

Again quite simple, just open the /etc/conf.d/apache2 file, and edit:

```
# nano -w /etc/conf.d/apache2

// First find the line:

APACHE2_OPTS="-D DEFAULT_VHOST"

// Now we just add '-D PHP5', and if you are using SSL, also '-D SSL',

// or for that reason, any other extra module you have compiled which needs to be

// activated.

APACHE2_OPTS="-D DEFAULT_VHOST -D SSL -D PHP5"
```

Now save the file, and create a 'Hello World!' test script in your htdocs folder (to test the php install):

```
# touch /var/www/localhost/htdocs/hello_world.php

# nano -w /var/www/localhost/htdocs/hello_world.php

// Insert this:

<?php

echo "Hello World!";

?>
```

Now to get the php module loaded, restart the apache server:

```
# /etc/init.d/apache2 restart

 * Stopping apache2 ...                                                                                                                                                [ ok ]

 * Starting apache2 ...                                                                                                                                                [ ok ]
```

If no errors occur, we are off for testing the script in a browser, in our example the server was on 192.168.0.1:80, so to test the script, we would use the URL:

```
http://192.168.0.1:80/hello_world.php
```

To test our new script, it should now print out:

```
Hello World!
```

And nothing else...

Well there you have it.... Finished!

Possible Issues:

Some might get an error when trying to stop their Apache2 server

```
# /etc/init.d/apache2 stop

 * Stopping apache2 ...

httpd (no pid file) not running                                                                                                                                        [ ok ]
```

And from there on, the server will not start again, and just give you this error:

```
 * Starting apache2 ...

(98)Address already in use: make_sock: could not bind to address 0.0.0.0:443

no listening sockets available, shutting down

Unable to open logs                                                                                                                                                    [ !! ]
```

I haven't yet found the origin of this problem, but a quick work-around is to kill the running apache server the hard way:

```
# killall apache2
```

And from there on, our apache2 server will start and restart without problems again (but not stop, for some reason).

I will of course bring an update as soon as I get this problem fixed.!

Old: Installing Apache 1.x with PHP4.x

I have been having some problems getting Apache and PHP running on Gentoo, and have now gotten it to work.I couldn't find anyone who had posted something about this inhere, so i thought that i would just write what i did, maybe this can be to help for someone out there.

Well the steps i made was for installing Apache and PHP from scratch.

Step 1. - Installing Apache and PHP

The first thing to do is emerging down Apache and PHP, and then ebuild.  :Smile: 

```

# emerge apache php mod_php

# ebuild /var/db/pkg/dev-php/mod_php-x.x.x-rx/mod_php-x.x.x-rx.ebuild config

```

I have written x instead of version numbers, since there are always comming new versions up. To find out wich version you have just emerged type:

```

# emerge -s mod_php

```

Now just sit back and wait a while. Emergin apache and php takes about 10min

Step 2. - Configuring Apache and PHP

Now it's time to configure Apache and PHP, before we are ready to test.

First we will edit /etc/conf.d/apache2, so that apache2 will start with php.

```

# nano -w /etc/conf.d/apache2

APACHE_OPTS="-D SSL -D PHP4"

```

-D SSL is optional, and remember to uncomment the line.

If you want apache to start when the machine boots, do this

```

# rc-update add apache2 default

```

Now for configureing apache. I have noticed that someone gets a httpd.conf file, and some places apache installs different places. But here is how i did it.

When i emerged apache, i got a folder in /etc/apache2 and the configuration files are in /etc/apache2/conf

Here to add PHP to apache as a module

```

# cd /etc/apache2/conf

# cp apache2.conf apache2.conf.working

# nano -w apache2.conf

```

Now here there sometimes also are differences. You have to locate the libphp4.so file. Some has it in /etc/apache2/lib/libphp4.so others in /etc/apache2/modules/libphp4.so, mine where in /etc/apache2/extramodules/libphp4.so

```

LoadModule php4_module where_you_found_it/libphp4.so

```

You don't have to write for eksampel /etc/apache2/extramodules/libphp4.so, you can just write extramodules/libphp4.so

If your configuration files are seperated into apache2.conf and commonapache2.conf, then you have to add the LoadModule... line into apache2.conf, as i showed above, but if you also adds the AddType to the apache2.conf file, it will not work. These lines has to be added into commonapache2.conf.

Here, still cd'ed into the folder /etc/apache2/conf

```

# cp commonapache2.conf commonapache2.conf.working

# nano -w commonapache2.conf

AddType application/x-httpd-php .php .phtml

AddType application/x-httpd-php-source .phps

```

The second AddType is optional, only if you want to allow .phps files (where the php code is shown with colors)

A good rule is to add the LoadModule and AddType lines together with all the others (other LoadModule or AddType lines in the configuration files), or at the end of the file(s).

Step 3. - Testing the webserver

Now to see if any of the things you have just done, actually works  :Smile: 

You have to be logged in as su to do this command.

If you are not logged in as super user, its pretty simple

```

# su

youpassword

```

Now for starting the apache server

```

# apache2 -k start

```

The commands for controlling the apache server are:

```
apache2 -k [start | restart | stop]
```

I hope this is going to help somebody out there..  :Smile: Last edited by theProphecy on Fri Dec 09, 2005 1:18 am; edited 1 time in total

----------

## karwoski

Thanks.  I'm trying it out now.

----------

## theProphecy

You're welcome... Just hope that my post maybe helped you out a bit..  :Smile: 

----------

## theProphecy

Damn....  :Smile:  Pressed the 'Submit' button two times...  :Sad: 

----------

## ctenet

Why's this in desktop environments?

----------

## lucindrea

 *ctenet wrote:*   

> Why's this in desktop environments?

 

admin hasnt moved it yet?

----------

## ian!

Moved from 'Desktop Environments' to 'Networking & Security'.

----------

## ArloWhite

Thanks, 

I was trying to figure out why php wasn't working.  Looking at my configs all the php lines were already correct.  It turns out I only needed to do the ebuild config script.  Maybe I should have paid attention after mod_php emerged to know to do this??

```

# ebuild /var/db/pkg/dev-php/mod_php-x.x.x-rx/mod_php-x.x.x-rx.ebuild config 

```

-Arlo

----------

## volrathxp

You know... I've done all this and apache2 still seems broken.. it acts like it starts but it just stops completely.

/var/log/apache2/error_log reports:

```

[Sat Nov 15 21:31:55 2003] [alert] (EAI 2)Name or service not known: mod_unique_id: unable to find IPv4 address of "*************"

Configuration Failed

```

is there something completely wrong here?  or is the fact that i'm trying to start it via SSH a problem?

edit: nvm i fixed it, forgot to add my host/ip to /etc/hosts

----------

## timvor

hi all

still cant get php going

links http://localhost and https://localhost gives me the default apache page which is fine , yet http://localhost/test.php gives me 

404 Not Found 

The requested URL /test.php was not found on this server. 

Apache/2.0.48 (Gentoo/Linux) PHP/4.3.3 mod_ssl/2.0.48 OpenSSL/0.9.6k Server at localhost Port 80

/var/log/apache2/error_log shows this after reboot

[Thu Nov 20 13:00:13 2003] [notice] Digest: generating secret for digest authentication ...

[Thu Nov 20 13:00:13 2003] [notice] Digest: done

[Thu Nov 20 13:00:14 2003] [notice] Apache/2.0.48 (Gentoo/Linux) PHP/4.3.3 mod_ssl/2.0.48 OpenSSL/0.9.6k configured -- resuming normal operations

script not found or unable to stat

script not found or unable to stat

I remerged mod_php and apache2 with the following USE flags

USE="pam tcpd ssl sasl libwww mysql imap maildir apache apache2 "

the file seems to be there

root@esnet / # ls -al /var/www/localhost

total 28

drwxr-xr-x    6 root     root         4096 Nov 20 08:40 .

drwxr-xr-x    3 root     root         4096 Nov 19 14:04 ..

drwxr-xr-x    2 root     root         4096 Nov 19 14:04 cgi-bin

drwxr-xr-x    3 root     root         4096 Nov 19 14:04 error

drwxr-xr-x    3 root     root         4096 Nov 20 11:57 htdocs

drwxr-xr-x    3 root     root         4096 Nov 19 14:04 icons

-rw-r--r--    1 root     root           21 Nov 20 08:40 test.php

The required file is there so why can i not get to it or does this mean that php is not working ?????

Any help herereally appreciated

timvor

----------

## volrathxp

move test.php to the htdocs directory   :Laughing: 

----------

## timvor

 :Embarassed: 

thanks for the help

this is what you get when you put a MS user + gentoo + outdated docs

Thanks again

----------

## volrathxp

 *timvor wrote:*   

> 
> 
> thanks for the help
> 
> this is what you get when you put a MS user + gentoo + outdated docs
> ...

 

no problem   :Smile: 

happy to help  :Smile: 

----------

## Random Task

I have a question:

I installed apache and php just fine using your awesome guide however at bootup I receive the following message:

 *Quote:*   

> Warning: module_php4 already loaded ignoring

 

(That's not the actual message, but it's close enough).

I have set up a phpBB so obviously php is working, but I'm just wondering how can I get rid of that error message?

Thanks

----------

## volrathxp

 *Random Task wrote:*   

> I have a question:
> 
> I installed apache and php just fine using your awesome guide however at bootup I receive the following message:
> 
>  *Quote:*   Warning: module_php4 already loaded ignoring 
> ...

 

I get the same message... I just left it alone, meh...   :Wink: 

----------

## omahorst

Hey Prophecy,

GREAT explanation. Exactly what I had been looking for.

Kudos!

Sebastian

----------

## theProphecy

Great... Glad that it can help someone out!  :Very Happy: 

----------

## Random Task

 *volrathxp wrote:*   

>  *Random Task wrote:*   I have a question:
> 
> I installed apache and php just fine using your awesome guide however at bootup I receive the following message:
> 
>  *Quote:*   Warning: module_php4 already loaded ignoring 
> ...

 

Well I _think_ I solved it without any _major_ problems!

What I did was comment out the line where you are supposed to put the following:

```
LoadModule php4_module where_you_found_it/libphp4.so
```

in /etc/apache2/conf/apache2/conf

I tested my phpBB that I put up and it was still working so I _think_ commenting out that line doesn't break anything.

Please post back here with any comments!

----------

## blasterboy

The reason you get that message is probably that you executed the ebuild script at the end of emerging mod_php several times.

If you look at you apache configurations (both files) you'll probably find that is multiple times in your config.

When apache finds it for the second time, it just ignores it.

So you do need it at least ONCE in your apache.conf files.

Regards,

A

----------

## spp

Not necessarily. If you do the ebuild config line, it *should* add the following to apache.conf

```

<IfDefine PHP4>

LoadModule php4_module    extramodules/libphp4.so

</IfDefine>

...

<IfDefine PHP4>

AddModule mod_php4.c

</IfDefine>

... And also at the bottom...

Include  conf/addon-modules/mod_php.conf

```

Doing the extra editing to add those lines manually will cause the error. The config line takes care of that.

This + the editing of the /etc/conf.d/ file will get the server running.

The steps in order would be...

```

# emerge apache mod_php php

If you want MySQL or other support in there...

# USE="mysql <other options>" emerge apache mod_php php

# ebuild /var/db/pkg/dev-php/mod_php-x.x.x-rx/mod_php-x.x.x-rx.ebuild config 

For Apache 1.x

# nano -w /etc/conf.d/apache

For Apache 2.x

# nano -w /etc/conf.d/apache2

Uncomment the APACHE_OPTS line and ensure that the -D PHP4 is in there.

OPTIONAL to start at run time - Apache 1.x

# rc-update add apache default

OPTIONAL to start at run time - Apache 2.x

# rc-update add apache2 default

```

Create a file under your DocumentRoot called info.php with the folllowing in it:

```

<? phpinfo(); ?>

```

and if you point your browser to http://<name/ip of box>/info.php you should get the PHP info page. 

The install for Gentoo apache is pretty different than from the "Standard" install. It is radically different from the Redhat version as it uses the include functionality of the conf files. 

SP

----------

## hereticorp

* Starting apache2...[Thu Dec 25 17:02:08 2003] [warn] module php4_module is already loaded, skipping

(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80

no listening sockets available, shutting down

Unable to open logs

  [ !! ]

So, I tried binding it to the local address on ETH0 (192.168.123.159) and I tried binding it to everything. (Listen *:80) and neither of them work.

Error message only changes in that 0.0.0.0:80 becaomse 192.168.123.159:80 when I issue "Listen 192.168.123.159:80" rather then "Listen *:80"

Ideas? I have no other versions of Apache emerged, and I have no idea what else could be binding port 80.

----------

## Bathroom Ninja

THANK YOU.  this worked for me and saved me from shooting my computer.  

Another computer saved by a good HowTo

----------

## flecluse

Thanks man you saved me a lot of work,

Great help, maybe you should post it to the documentation team.

Greetings

Filip

----------

## mangobrain

Erm..maybe things are a little different since the time of the original post in this thread, but all I had to do was emerge Apache, emerge mod_php, and add "-D PHP4" to the relevant config file.  I did have to run an ebuild config on one (or maybe both) of the packages, but basically, I didn't do anything that portage didn't suggest to me.

I didn't realise this until AFTER I'd finished compiling it, but if you emerge php (as opposed to mod_php), you'll get a commandline-only version. Mod_php - the webserver version - doesn't even depend on having php (CLI version) installed, it seems. I emerged Apache, emerged PHP, unmerged PHP again after being warned by portage that what I'd just installed was CLI-only, and merged mod_php, which didn't (fortunately for me) depend on what I'd just unmerged. I can confirm that, at the very least, Apache and the phpinfo() function are working.

The purpose of the two PHP packages, and the fact that one doesn't depend on the other, should be made clearer (put it in the package descriptions, perhaps).

----------

## Oopsz

...it is in the package description. 

```
oopsz@venus oopsz $ esearch php

*  dev-php/php

      Latest version available: 4.3.3-r2

      Latest version installed: 4.3.3-r2

      Size of downloaded files: 3,625 kB

      Homepage:    http://www.php.net/

      Description: PHP Shell Interpreter
```

php is useful for shell scripting and cgi-php, mod_php is the persistent php environment for apache.  Similar for perl vs mod_perl.

----------

## cmassa

this was definitely the easiest apache installation ive ever done, but also the most perplexing. emerge is cool, but i was lost without apachectl and httpd.conf.

thanks to all for adding to this!

----------

## Lohman

"Warning: module_php4 already loaded ignoring"

I eliminated that message by not adding the LoadModule php4 to the apache2.conf.  The -D PHP4 in the conf.d/apache2 apparently causes it to load PHP before it even reads the .conf file which is why it states that when it reads the LoadModule php4 in the conf.

----------

## dreamwolf

 *Oopsz wrote:*   

> php is useful for shell scripting and cgi-php, mod_php is the persistent php environment for apache.  Similar for perl vs mod_perl.

 

Oh, the hours I've wasted!

This has messed me up twice (though the second time I spent significantly less time trying to figure out what I did wrong ;).  I would be willing to bet that the vast majority of people who need PHP expect to use it as a web scripting language.  Wouldn't it've made more sense to have "php" be the Apache plug-in and "cli_php" or "php_shell" (or something similar) be the command line version?

dreamwolf

----------

## Slammer

I have installed apache2 and mod_php. Apache loads the php module successfully but when I try to load this index.htm file:

```

<?php 

phpinfo();

?>

Testing....

```

I get only "Testing...". 

PHP does not work.... No error messages in apache log....

----------

## valuial

You need to name it index.php, not index.htm

with the extension htm apache tries to interpret it without php-interpretation...

Ps: Sorry for my bad english...

Edit: Apache doesnt interpret at all, the browser gets the raw file, and interprets the

```

<?

PHPcode-here

?>

```

as unrekognised HTML-Tag and ignores it.

----------

## Slammer

After renaming to .php everything is OK.

Solved! Thanks!

----------

## dmak

i tried to emerge php mod_php

and it says something about unable to download couple packages and was aborted.  I think the package that emerge get isn't there anymore how can i get emerge to download the needed packages.

-dmak

----------

## 0paque

I tried the following:

```
# emerge -p apache php mod_php > /tmp/1
```

Then

```
# emerge -p apache mod_php > /tmp/2
```

Then:

```
# diff 1 2
```

The only difference in the two emerge's is the order in which mod_php and php gets installed.  So you can use either command and come out with the same result.

----------

## Sanderfox

I used this howto to get apache working with php, and it's almost working I think. The only thing that isn't right, is that if I want to go to a directory on my webserver (from the internet, not local) with an index.php file in it, I get the downloadmanager up asking me if I want to open or save.

Does any one have a solution for this problem ?

----------

## Ladynik0n

```

apache2 -k start

```

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

what does this mean?

----------

## theProphecy

 *Ladynik0n wrote:*   

> 
> 
> ```
> 
> apache2 -k start
> ...

 

I eliminated this by editing the apache2.conf file:

```

# nano -w /etc/apache2/conf/apache2.conf

// Find the line saying #ServerName localhost and uncomment:

ServerName <a_name_of_your_choise>

```

----------

## Lajasha

 *Sanderfox wrote:*   

> I used this howto to get apache working with php, and it's almost working I think. The only thing that isn't right, is that if I want to go to a directory on my webserver (from the internet, not local) with an index.php file in it, I get the downloadmanager up asking me if I want to open or save.
> 
> Does any one have a solution for this problem ?

 

If you do it local does it do the same, or does it work like it should?

Make sure that you have the following information in your /etc/apache2/conf/apache2.conf

```
LoadModule php4_module /usr/lib/apache2-extramodules/libphp4.so
```

and in /etc/apache2/conf/commonapache2.conf

```
AddType application/x-httpd-php .php .phtml

AddType application/x-httpd-php-source .phps

```

----------

## neomatrix35

to get apache to load with a index.php you need to add it to the config file. theres a line that has "index.html, index.htm, index.shtml... and so on"... just add index.php to that and you'll have no problems

----------

## sk93

just wanted to say thanks for the guide.

I've been messing around with apache / php /mysql all weekend, and this is the first, up to date, guide that got everything working first time.

Nicely done  :Smile: 

----------

## theProphecy

 *Quote:*   

> 
> 
> o get apache to load with a index.php you need to add it to the config file. theres a line that has "index.html, index.htm, index.shtml... and so on"... just add index.php to that and you'll have no problems
> 
> 

 

The specific configuration point for this is:

```

<IfModule mod_dir.c>

    DirectoryIndex index.php

</IfModule>

```

I don't remeber exactly which configuration file this is located in (ripped this from my Win Box with Apache1.x). But as far as i remember the syntax should be exactly the same in Apache2.x.

(btw. im using Apache1.x, because I where having some very wierd problems with Apache2 and PHP/Regular Expressions, resulting in Apache crashing. The wierd thing is that the exact same code doesn't have a problem running with the exact same PHP installation but in Apache1.x. Anyways, thanks to everybody contributing to this guide/help.  :Very Happy:  )[/quote]

----------

## neomatrix35

what is ur problem?

----------

## theProphecy

Well have no problem now that im running Apache 1.x, but as I said, I had a problem with PHP and Apache 2, doing some very strange errors in regular expressions. The wierd thing, was that it made no sence about when the error occured.

I had a piece of code, which when being runned would make apache crash. Then to determine what caused the crash, i made some replicas of the script (simpler versions of the regular expression), and found out that when I systematically executed specific pieces of code (the simpler versions of the regular expression), then "building" my way back up to the original script. And after doing all this "building up", I could one or two times execute the script that earlier crashed apache, but only one or two times, then it started crashing apache again.

The funny thing is that the simpler scripts were cut back versions of the "big" one that made apache crash. And the correct order to execute them (in order to get the "big" one running a couple of times), was with the most cut back one, first, and then the next most simple cut back one and so on, until all the simpler versions had been executed. Very strange.

Unfortunately (spelling?  :Razz: ) im not sure if I have the script anymore, might have it, but not 100% sure it's the same. (I might have further developed on it since).

I also checked the same script on other serves running Apache 1.x, and there were no problems at all, so I thought it might be Apache 2.x, and therefor I installed it on my machine, not changing anything else (even not the PHP installation), and that made the trick. (or it might just be because I used my laptop running Windows as server, hehe.)

----------

## neomatrix35

wow... i have no clue... never heard of a script crashing an apache server before....i mean non-malicious anyways.... sorry dude.... but if try to install apache2 on gentoo... it might work.. never know

----------

## theProphecy

Well thanks anyways.  :Smile: 

It mights, but really no big problem, since Apache 1.x solved the problem. And since most webhosts run apache 1.x, its not that big of a deal, programming on the same version.  :Smile:  And I like having everything with me around on my laptop (developing server, source code etc.) so it has to be on it.

----------

## DaRkNeS

I have a little problem... When i point my browser to the webserver:

Warning: Unknown(/var/www/localhost/htdocs/default.php): failed to open stream: Permission denied in Unknown on line 0

Warning: (null)(): Failed opening '/var/www/localhost/htdocs/default.php' for inclusion (include_path='.:/usr/lib/php') in Unknown on line 0

In the php page there's the phpinfo function BUT phpbb work well... maybe something wrong with php includes. Any solution?

Excuse me for my english  :Very Happy: 

----------

## tehnomage

I seem to have the exact same problem, and please note that before what ever happend ( I think some upgrade ocurred) I had a nice php app fully working.

----------

## tehnomage

Ok, this is how I solved it, I set the perms for /var/www/ to 755 and the user:group to root:root. Note that the doc roots for my vhosts are in the form : /var/www/host/so_on.

Hope it helps.

----------

## DaRkNeS

it works, thanks  :Very Happy: 

BUT it's safe to give 755 to this directory?  :Confused: 

----------

## Gentist

I have a problem with mod_php, it doesn't load with apache, despite the fact that I edited /etc/conf.d/apache2 and added:

```
APACHE2_OPTS="-D SSL -D PHP4"
```

It doesn't give me any error message either, and the error log doesn't say anything about it. However, starting Apache with "apache2 -D PHP4" works fine.

I installed apache and php on the computer for development and testing purposes, so that I would be able to test my scripts in a real world environment without going online, thus I did not add apache with "rc-update add apache2 default".

Did I miss something?

----------

## tehnomage

yeah, it is ok. if you wanna be paranoid, you can set it to 555 and root:root, so it should be readable and accessable by anyone and be owned by root only, but not writeable even by root ( from a shell obtained by exploiting some vuln, for example).

----------

## Woland

Addiing apache2 with rc-update should do nothing to apache, it only changes your start up files.  I am havind the same problem as you are---"apache2 -D PHP4" works just fine, but "/etc/init.d/apache2 start" starts up apache, but completely ignores PHP.  It does pick up ssl, so I know that it is reading the /etc/conf/apache2 file, just pointedly ignoring the -D PHP4.   Very frustrating.

----------

## eyce

These are the steps that I followed to get my apache2 / php4 working together:

```

su

```

enter password.

```

emerge apache

emerge mod_php

```

Once the emerging is complete

```

cd /etc/conf.d

nano apache2

```

Now edit the line that says "#APACHE2_OPTS="-D SSL" and make it 

```

APACHE2_OPTS="-D SSL -D PHP4"

```

Once done, save the file and exit. Then:

```

cd /etc/apache2/conf/

cp apache2.conf apache2.conf.bak

nano apache2.conf

```

Add the following line for PHP4

```

LoadModule php4_module  /etc/php/apache2-php4/lib/libphp4.so   

```

... your path to the libphp4.so file may be different. 

If you have a PHP5 installation then add this instead of the above: 

```

LoadModule php5_module <path to libphp5.so file>

```

Save and exit the file. And now:

```

cd /etc/apache2/conf/

cp commonapache2.conf commonapache2.conf.bak

nano commonapache2.conf

```

Add the following lines:

```

      AddType application/x-httpd-php .php .phtml   

      AddType application/x-httpd-php-source .phps

```

Save and exit the file. Now test your apache installtion by putting a php file in your htdocs directory (/var/www/<your hostname here>/htdocs) and then:

```

apache2 -k start

```

Open up the browser and type in: http://<your hostname here>/<your php file here>

If you're happy, then let apache start up in ze beginning  :Smile: :

```

rc-update add apache2 default

```

.. Hope this helps! And I hope I didn't screw up in typing the above up  :Wink: . CHeers!

----------

## rjordan

I just wanted to add that APACHE_OPTS is different from APACHE2_OPTS and broke my php when I copied the line off the beginning of this howto.

----------

## Dana Merrick

 *theProphecy wrote:*   

>  *Ladynik0n wrote:*   
> 
> ```
> 
> apache2 -k start
> ...

 

I had the same error that Ladynik0n had, and I changed the SeverName variable in the apache2.conf file but it still doesn't work.

I don't get the same error, but the 

```
apache2 -k start
```

 fails and I'm not sure why. What exactly should I put as the ServerName? I don't intend on having a domain name for my site, or using it very often (mainly for testing php via my home network and remote access via my computer's IP address).

----------

## Woland

 *aragostaragazzo wrote:*   

> 
> 
> I had the same error that Ladynik0n had, and I changed the SeverName variable in the apache2.conf file but it still doesn't work.
> 
> I don't get the same error, but the 
> ...

 

ServerName localhost is the default, and should work fine. May I suggest that your problems lie elsewhere?  Check /var/log/apache2 for messages when you try to start.

----------

## k:arel

put:

```
ServerName localhost
```

in your httpd.conf file and you won't get an error

it some BIND problem i think

----------

## Woland

 *k:arel wrote:*   

> ...
> 
> in your httpd.conf file and you won't get an error ... 

 

httpd.conf!  Good god man, stop living in the past!  It's /etc/apache2/conf/apache2.conf now.  Get used to it.

----------

## k:arel

 *Woland wrote:*   

> httpd.conf!  Good god man, stop living in the past!  It's /etc/apache2/conf/apache2.conf now.  Get used to it.

 

sorry man, i downloaded and installed Apache and PHP from the web

i was just trying to help out

----------

## Dana Merrick

 *k:arel wrote:*   

> put:
> 
> ```
> ServerName localhost
> ```
> ...

 

That's what my apache2.conf file says already.

I know it's not working right because, 1. my bash prompt turns red when a command fails, and 2. there is no instance of apache running afterwards.

I'm not sure what the error is though, because it doesn't say anything.

Any more ideas?

----------

## k:arel

 *aragostaragazzo wrote:*   

> 
> 
> That's what my apache2.conf file says already.
> 
> I know it's not working right because, 1. my bash prompt turns red when a command fails, and 2. there is no instance of apache running afterwards.
> ...

 

try to manually start apache and post the output

if none output: how do you know it isn't working?

are you sure you haven't set the docroot wrong or something like that?

----------

## Dana Merrick

 *k:arel wrote:*   

> how do you know it isn't working?

 

There is no output, and your question is answered in my previous post:

 *aragostaragazzo wrote:*   

> I know it's not working right because, 1. my bash prompt turns red when a command fails, and 2. there is no instance of apache running afterwards.
> 
> I'm not sure what the error is though, because it doesn't say anything.

 

And my docroot is the default (htdocs). I wont even bother changing that till I even get apache to start.

So, uh, any more ideas?  :Smile: 

----------

## Woland

First, k:arel, you do know I was just kidding, right?

Second, aragostaragazzo, I am assuming that since "your prompt turns red when a command fails" something is being output to stderr or at least apache shoud put something into /var/log/apache2/error_log 

perhaps try 

```
tail -f var/log/apache2/error_log
```

 in one xterm, then try starting apache in another.  There should be some kind of output.  If there is nothing, then your problems are bigger than configuration, and my advice would be to unmerge apache, and re-install it.

----------

## Todd Z

emerge apache

Calculating dependencies ...done!

>>> emerge (1 of 1) net-www/apache-2.0.50 to /

!!! File is corrupt or incomplete. (Digests do not match)

>>> our recorded digest: 8b251767212aebf41a13128bb70c0b41

>>>  your file's digest: 535d5371ea45c84107124b2256872af4

!!! File does not exist: /usr/portage/distfiles//httpd-2.0.50.tar.gz

What does this error mean, and how do i fix it?

----------

## Woland

Todd, I don't mean to be a pain, but that is something you search the Forums for----it is quite a common error.   But, O. K., I'll give you the fix:

```

rm /usr/portage/distfiles/httpd-2.0.50.tar.gz

emerge apache
```

 Should do it.

----------

## tscolari

Please help me here...

My apache was working ok, until i change the /etc/hostname of my computer.

Now it doesnt, but i dont know how to update this info in apache config, can anyone help me?

this is what i get trying to run apache:

```
#/etc/apache2> /etc/init.d/apache2 start

 * Starting apache2...

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

```

----------

## Dana Merrick

 *tscolari wrote:*   

> Now it doesnt, but i dont know how to update this info in apache config, can anyone help me?

 

In your apache2.conf file, uncomment the line that says:

```
ServerName localhost
```

----------

## newbie_gentoo

Thanks for a great tutorial!

----------

## tscolari

 *aragostaragazzo wrote:*   

>  *tscolari wrote:*   Now it doesnt, but i dont know how to update this info in apache config, can anyone help me? 
> 
> In your apache2.conf file, uncomment the line that says:
> 
> ```
> ...

 

I did it, now the message is gone but this still:

 * Starting apache2...                                                    [ !! ]

anyidea how can i discover what i did to make it stop working?

recently i did some upadates im my system, but the closest of apache was mysql...

maybe if i re-emerge it could get fixed?

----------

## Dana Merrick

 *tscolari wrote:*   

> I did it, now the message is gone but this still:
> 
>  * Starting apache2...                                                    [ !! ]
> 
> anyidea how can i discover what i did to make it stop working?

 

To be completely honest, I'm still stuck here too. Apache just doesn't want to start on my computer... And I kinda put the webserver on the back burner because I don't really need it, but yes, I share your problem and can't seem to get any further.

I tried re-emerging apache but it didn't do anything helpful. I'm out of ideas...

----------

## tscolari

 *aragostaragazzo wrote:*   

> 
> 
> To be completely honest, I'm still stuck here too. Apache just doesn't want to start on my computer... And I kinda put the webserver on the back burner because I don't really need it, but yes, I share your problem and can't seem to get any further.
> 
> I tried re-emerging apache but it didn't do anything helpful. I'm out of ideas...

 

I just dont understand because before it was working

it must be conflicting with some new package that ive updated recently...

but in the few 2 days ive updated a lot of stuff, no way to know what it is now  :Sad: 

this is the error im getting:

```
From error_log

[Sun Aug 22 14:34:07 2004] [alert] (EAI 2)Name or service not known: mod_unique_id: unable to find IPv4 address of "sancho"

Configuration Failed

```

----------

## tscolari

 *aragostaragazzo wrote:*   

>  *tscolari wrote:*   I did it, now the message is gone but this still:
> 
>  * Starting apache2...                                                    [ !! ]
> 
> anyidea how can i discover what i did to make it stop working? 
> ...

 

Hey i did it!!

hope it can help you too.

This is what was going wrong here.

First it was working and stoped working after i changed my hostname to othername (before it was tiago-lx now its sancho).

okay.

But i forgot to change it in the /etc/hosts 

the first line of it was:

127.0.0.1 localhost tiago-lx

but after i changed it for:

127.0.0.1 localhost sancho

then...

* Starting apache2...                                                    [ ok ]

hope it can help you there hehehe

----------

## Dana Merrick

Oh man that fixed it!

As someone who prides himself on figuring out his own errors, I feel really, really dumb. Hehe.  :Embarassed: 

----------

## geniux

 *timvor wrote:*   

> hi all
> 
> still cant get php going
> 
> links http://localhost and https://localhost gives me the default apache page which is fine , yet http://localhost/test.php gives me 
> ...

 

I dont have test.php

```

 # ls -la /var/www/localhost       

total 24

drwxr-xr-x  6 root root 4096 Aug 24 01:10 .

drwxr-xr-x  3 root root 4096 Aug 24 01:10 ..

drwxr-xr-x  2 root root 4096 Aug 24 01:10 cgi-bin

drwxr-xr-x  3 root root 4096 Aug 24 01:10 error

drwxr-xr-x  3 root root 4096 Aug 24 02:33 htdocs

drwxr-xr-x  3 root root 4096 Aug 24 01:10 icons

```

And Mozilla claims that it can't open unknown file (.php) if I put my index.php in htdocs. What's the error, I've followed the guide step by step and it all works beside the php probs.

Can anyone help, I'm totally stucked and dont know what to do.

TIA

----------

## Dana Merrick

 *geniux wrote:*   

> Mozilla claims that it can't open unknown file (.php) if I put my index.php in htdocs

 

That sounds like your server doesn't have the appropriate MIME types set correctly.

Make sure that you put the following in /etc/apache2/conf/commonapache2.conf:

```
AddType application/x-httpd-php .php .phtml

AddType application/x-httpd-php-source .phps

```

----------

## geniux

Thanks, I had missed the last line, but now it can read my php files.

But I cant for my life get the manual to work, anything you can help me with?

Sorry for all the questions, but it's the first time I ever try apache. I want to put my website on my computor because of bandwith troubles and such, but it turned out to be alot harder than I could imagine.

----------

## Lord_Firlionel

Hi,

Wonderful tutorial!! I used exactly the way and it worked. Some little changes were necessary (libphp4.so path is /usr/lib/apache2-extramodules/libphp4.so e.g.) but all in all it went fine.

I have one little problem though: My Webserver cannot load .png images. I tried with .jpg and they worked but when I'm loading a png image he shows me the code of the file, but no picture.

I looked up the USE flags via etcat -u mod_php and there is png included, as it is in etcat -u php.

Apache2 itself doesn't have this useflag, neither png nor jpeg so I don't think I emerged it wrong.

Anyone here who got a similar problem and solved it? Or someone who knows what the matter is in my case?

Thanks a lot!

Edit: Hmm, seems to be no problem of the apache.. I don't know what it is, but I'll fix it  :Smile: 

----------

## neomatrix35

Can ask what's in you make.conf file for this tutorial. I am having a problem with htaccess and htpassword and it looks like whatever modules that installs that ability didnt get installed. In another thread I asked for some help but every answer I got should have worked but they don't.

Any help would be great. I may just try a reinstall of apache.... maybe something got bunged up somewhere.

----------

## coldy

Thanks for the great tutorial! I am newb in Gentoo, but with the Forums help I´m going faster ahead =) Everything is working just fine. 

Thanks again!

----------

## scoon

 *valuial wrote:*   

> You need to name it index.php, not index.htm
> 
> with the extension htm apache tries to interpret it without php-interpretation...
> 
> Ps: Sorry for my bad english...
> ...

 

Hey there, 

So what does one do when they want to have php embedded in htm files ?

scoon

----------

## fribadeau

 *Quote:*   

> Hey there,
> 
> So what does one do when they want to have php embedded in htm files ?
> 
> scoon

 

The php extension just means that it will be analized by PHP for its language before being sent to  the browser which will analyse the HTML. All what is not PHP will be sent without any change.

To resume, a PHP file is a file that contains PHP instructions that will be replaced by HTML and HTML that won't be touch. The whole thing will then be sent to the browser.

----------

## scoon

 *fribadeau wrote:*   

>  *Quote:*   Hey there,
> 
> So what does one do when they want to have php embedded in htm files ?
> 
> scoon 
> ...

 

Hey there, 

I figured it out.  This is what I want to do: 

```

<html>

<body>

<? phpinfo(); ?>

</body>

</html>

```

The file will carry the htm or html file type.  And both the php and the html will be written to the screen.  Just like PERL's mason.  

scoon

----------

## fribadeau

Create a file named test.php and put your code in it :

```
<html>

<body>

<? phpinfo(); ?>

</body>

</html>
```

It will produce what you want.

Fred

----------

## scoon

 *fribadeau wrote:*   

> Create a file named test.php and put your code in it :
> 
> ```
> <html>
> 
> ...

 

Hey there, 

I got it doing what I want it to do.  I don't think I have made clear what I wanted to do which is embed php INSIDE a HTML file with the HTM or HTML extension.  My issue is resolved. 

scoon

----------

## Woland

 *tscolari wrote:*   

> 
> 
> Hey i did it!!
> 
> hope it can help you too.
> ...

 

NoOOOOOO!!!!!   Hate to be a sticler, but according to a highter authority (RFC 2606 in fact) 127.0.0.1 is reserved only for localhost.localdomain!

The line in /etc/hosts [i]must[/] read either:

(best, safest)

127.0.0.1       localhost.localdomain   localhost

or

127.0.0.1       localhost.localhost   localhost

or simply

127.0.0.1       localhost

Your line,  127.0.0.1 localhost sancho aliases "sancho" to the localhost canonical hostname, and as you found out, this can give you a world of grief should the smallest thing change.  So, be a traditionalist, be like me, don't drink capuccino after 11:00 am, and put this in your /etc/hosts:

```

# HOSTS.TXT

#

# This domain is reserved in RFC 2606.  It is required for normal operation

127.0.0.1       localhost.localdomain   localhost

# Hosts at Home

# This machine

10.1.1.2     panza.quixote.net      sancho Sancho

#and others

10.1.1.1        dulcinea.quixote.net        Duncinea duncinea LadyLove

# Miscellaneous hosts.

#

# These are known hosts elsewhere which we would like to know about

# even if name service is broken.

168.10.10.4  rosinante.noblesteeds.net     rosinante

```

----------

## carpman

sorted, the configuarations file had .dist missiong off it

hello, ok i setup apache2 php mysql for use as local webdev testing, default server is /var/www/localhost

test.php works

I have the website dev files in 

/home/michael/public_html/dev/site1

I have setup an alias in default server

http://localhost/site1

But when trying to install mambo i get 

```

Warning: main(/path/to/mambo/install/includes/version.php): failed to open stream: No such file or directory in /home/michael/public_html/site1/includes/mambo.php on line 27

Warning: main(): Failed opening '/path/to/mambo/install/includes/version.php' for inclusion (include_path='.:/usr/lib/php') in /home/michael/public_html/site1/includes/mambo.php on line 27

Warning: main(/path/to/mambo/install/includes/database.php): failed to open stream: No such file or directory in /home/michael/public_html/site1/includes/mambo.php on line 29

Fatal error: main(): Failed opening required '/path/to/mambo/install/includes/database.php' (include_path='.:/usr/lib/php') in /home/michael/public_html/site1/includes/mambo.php on line 29

```

The lines it is refering to are

```

include_once( $mosConfig_absolute_path . "/includes/version.php" );

require_once( $mosConfig_absolute_path . "/includes/database.php" );

```

both these files exist so it must a path issue somewhere?

any ideas?

cheers

----------

## drspewfy

wel well, so do i, i have php + mod_php and mysql installed, and of couse, apache2.

the problem comes, when you create users, and you want them... to create his own page, with php!,,

how do i do that, i know that i have to create a  directory called..

 /home/USER/public_html/

but i dont know how do i tell to apache or php,,, to point to each user directory

i want that each user has his OWN page,, and can make php pages..

thanks!!!

----------

## carpman

 *drspewfy wrote:*   

> wel well, so do i, i have php + mod_php and mysql installed, and of couse, apache2.
> 
> the problem comes, when you create users, and you want them... to create his own page, with php!,,
> 
> how do i do that, i know that i have to create a  directory called..
> ...

 

Hello, there should be a setting and i believe it is a module that allows this, in the apache config file look for something like

home/*/public_html

make sure this is enabled then type 

http://localhost/~username

this will load the file in

/home/username/public_html

this is a rough idea but sure someoen will expand on it.

----------

## Gentree

OK this is starting to annoy me.

There doc seems unclear and I am just fiddling around hoping something works or I stumble on a lucky post.

I have everything I need, at one stage I got to the phpBB setup page and everything was well. My test.php runs phpinfo and all seems well.

The trouble is I shut everything down and now I have no PHP again.

If I put the Loadmodule line in the configs it bleats about it every time and I seem to get mutliple instances in ps -ax.

But if it is not there I get no PHP.

What is the correct way to do this?

There seems to be as many ideas as there are posts and we're all just fishing around.

Even the PHP site's bit on Gentoo was sparse and out of date.

does anyone actually understand this stuff?

TIA  :Cool: 

----------

## lancelot

Hi,

I am in the process of moving my apache 1.3.23 / php 4.1.2 / Mandrake 8.2 webserver over to apache 2.0.52 / php 4.3.9 / gentoo 2004.2.

At first sight, everything seems to work well, got apache installed, php, and mod_php, and the <? phpinfo(); ?> seems to work fine.

But now, when I try to use an url with variables things don't work as expected anymore...

I modified the info.php script to the following:

<?

    print "Op1: $op1";

    print "Op2: $op2";

    phpinfo();

?>

And on the original webserver it shows:

http://hoth.xs4all.nl/~hurenkam/info.php?op1=1&op2=2

But on my new box it shows:

http://hoth.xs4all.nl/~hurenkam/info.html

(used the same info.php?op1=1&op2=2 line, but the server is not connected to the net, hence the info.html file)

Anyone have an idea what's wrong here? Do I need to enable some use flag for apache2 or mod_php in order for this to work?

Any help is very much appreciated!

Mark.

----------

## lancelot

Hmm, I think I solved it already, I had to set the following in php.ini:

register_globals = On

Now it's working as it should  :Smile: 

Mark.

----------

## banderos

Just started to follow this tutorial but I noticed this:

gentoo root # emerge -Dav mod_php phpmyadmin       

These are the packages that I would merge, in order:

Calculating dependencies ...done!

[ebuild  N    ] dev-php/mod_php-4.3.9  +X -apache2 +berkdb +crypt -curl -debug -doc -fdftk -firebird -flash -freetds -gd -gd-external +gdbm -gmp -hardenedphp +imap -informix -ipv6 -java +jpeg -kerberos +ldap -mcal +memlimit -mssql +mysql +nls -oci8 -odbc +pam +pdflib +png -postgres -qt +snmp +spell +ssl -tiff +truetype +xml2 -yaz 3,908 kB 

Do I need to override this USE flag to get it to work?

----------

## banderos

Nevermind..I just added it to make.conf and it works.

----------

## tlepo

Many thanks theProphecy for your wonderfull tutorial!  :Very Happy: 

And others for your contributions and comments.

----------

## vai0l0

Great, I was only wondering if there is not another way of including mod_php: I mean everytime apache2.con and all the other files we edited manually are updated by the portage the etc-update will request the manual update not auotmerging differrences.

However GREAT HOWTO

AleX

----------

## makenoob

 *lancelot wrote:*   

> Hmm, I think I solved it already, I had to set the following in php.ini:
> 
> register_globals = On
> 
> Now it's working as it should 
> ...

 

As this is for security reasons turned off, you might want to take a look at these links (these are the german ones):

http://de.php.net/manual/de/ini.sect.data-handling.php

http://de.php.net/manual/de/reserved.variables.php#reserved.variables.request

http://de.php.net/manual/de/language.variables.predefined.php#language.variables.superglobals

HTH

Marc

----------

## BlueEagle

 *hereticorp wrote:*   

> * Starting apache2...[Thu Dec 25 17:02:08 2003] [warn] module php4_module is already loaded, skipping
> 
> (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
> 
> no listening sockets available, shutting down
> ...

 

What bit me was portsentry, but it can be that or snort or any IDS (Intrusion detection system) that boobytraps ports. You should probably be able to spot it with rc-status.

----------

## rex123

 *Woland (Sept 19) wrote:*   

> 
> 
> ...
> 
> Hate to be a stickler, but according to a higher authority (RFC 2606 in fact) 127.0.0.1 is reserved only for localhost.localdomain!
> ...

 

I agree with your general point (that we should keep our hosts file pure), and I like your Quixotic naming convention, but is the quote above really true? I've just read RFC 2006. It says that localhost.localdomain is reserved for 127.0.0.1. This isn't quite the same as saying that 127.0.0.1 is reserved for localhost.localdomain.

Apologies for replying to something so out of date.

----------

## -TooL

I did exactly what was said here, found the files needed etc..

when i do # apache2 -k start 

i get this error:

```
(2)No such file or directory: apache2: could not open error log file /usr/lib/apache2/logs/error_log.

Unable to open logs
```

I checked to see if the logs directory is there, and it is.. sorta.. i can not CD into it.. its not a file.. but it exists with a dir command..

I see this in there:

```
build conf extramodules lib logs modules
```

logs is there, cant access it..

----------

## rex123

 *-TooL wrote:*   

> I did exactly what was said here, found the files needed etc..
> 
> when i do # apache2 -k start 
> 
> i get this error:
> ...

 

/usr/lib/apache2/logs should be a symlink to /var/log/apache2.

Try this:

```
 # ls -l /usr/lib/apache2/logs

lrwxrwxrwx  1 root root 16 Oct 12 17:48 /usr/lib/apache2/logs -> /var/log/apache2

```

I'd guess (but I can't be sure) that the symlink exists on your system, but is broken. Ie /var/log/apache2 doesn't exist (or possibly has the wrong permissions/ownership).

----------

## -TooL

When I do that command i get the output that you have.

```
 # ls -l /usr/lib/apache2/logs

lrwxrwxrwx  1 root root 16 Nov 18 01:42 /usr/lib/apache2/logs -> /var/log/apache2 
```

and im still getting the same error, unable to open logs

should i create a new topic for this? since this is buried really really deep in this thread

----------

## rex123

 *-TooL wrote:*   

> When I do that command i get the output that you have.
> 
> ...
> 
> and im still getting the same error, unable to open logs
> ...

 

Sorry - I wasn't very clear.

Now that you see that /usr/lib/apache2/logs is a link to /var/log/apache2, you need to check that that directory exists, and is writable by the appropriate user.

So try

```

$ ls -ld /var/log/apache2/

drwxr-xr-x  2 root root 4096 Nov 18 14:45 /var/log/apache2/

```

The output here shows that the directory is owned by the user root, and writable only by that user.

So make sure you're running apache2 as root, and it should work.

If you get something like "no such directory" then you have a broken symlink (one that points to something that isn't there).

 *-TooL wrote:*   

> 
> 
> should i create a new topic for this? since this is buried really really deep in this thread

 

Probably no need. It is quite likely a permissions issue not a symlink one anyway.

----------

## To

 *carpman wrote:*   

> sorted, the configuarations file had .dist missiong off it
> 
> hello, ok i setup apache2 php mysql for use as local webdev testing, default server is /var/www/localhost
> 
> test.php works
> ...

 

Donno if it's too late for this, but: in the error you have "/path/to/mambo/" you're suposed to edit your config file and specify the path where manbo is  :Wink: 

Tó

----------

## -TooL

ahh I was not in Root when I tried running it either, Ill try that once I get some other things done that im messing with right now

----------

## -TooL

 *rex123 wrote:*   

> 
> 
> Now that you see that /usr/lib/apache2/logs is a link to /var/log/apache2, you need to check that that directory exists, and is writable by the appropriate user.
> 
> So try
> ...

 

As root im getting:

```
ls: /var/log/apache2/: No such file or directory
```

for the above ls command...

----------

## -TooL

ohh blah i tried making the directory apache2..

now im getting the error:

```
(40)Too many levels of symbolic links: apache2: could not open error log file /usr/lib/apache2/logs/error_log.

Unable to open logs
```

ID-10T error... heh

----------

## zdawg

I'm thinking you made the /usr/lib/apache2, which resulted in your error message.

The way I resolved the same issue is:

```
mkdir /var/log/apache2 && chown apache /var/log/apache2
```

HTH

----------

## lramos85

I get an error when starting apache (apache -k start). Something about error opening log file, I don't know exactly because i'm not in my linux box, but I'll post the exact error later.

----------

## lramos85

I just created the file it was looking for manually and it now works, thanks.

----------

## plonka2000

Can someone PLEASE help me?

Here is the history:

I emerged apache using this command:

```
emerge apache mod_php mod_mp3 php mysql phpmyadmin php-cgi
```

First I was having trouble starting Apache, getting this error:

```
bash-2.05b# apache2 -k start

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

(2)No such file or directory: apache2: could not open error log file /usr/lib/apache2/logs/error_log.

Unable to open logs
```

Then I had some progress...

I've backtracked what its referring to and I've found that /usr/lib/apache2/logs is actually some kind of symlink to the /var/log/apache2 folder.

This folder did not exist though, so I created it and it helped somewhat.

Then I just got this error:

```
bash-2.05b# apache2 -k start

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

Then more progress:

Edited /etc/apache2/conf/apache2.conf and uncommented the line for ServerName. Now I dont get an error message, however, my server does not seem to be working as I cant access it from outside.

Can someone please assist?

Thanks.

K.

EDIT: Here is a dump from my file:/var/log/apache2/error_log file:

```
[Tue Dec 14 00:55:27 2004] [alert] (EAI 2)Name or service not known: mod_unique_id: unable to find IPv4 address of "libby"

Configuration Failed
```

I have a feeling it has something to do with my hostname as thats what 'libby' is...

----------

## plonka2000

I tried restarting the PC as well. I now get this error during startup:

```
*Bringing up eth0 via DHCP...                   [!!]

*ERROR: Problem starting needed services.

*       "netmount" was not started.

*ERROR: Problem starting needed services.

*       "apache2" was not started.
```

I'm assuming this is to do with apache2 since I was not getting the 'netmount' error before now.

I'm really stuck now.

----------

## skerb1

Does anyone have an idea on how to make the http and https servers point to separate documentroots??

In my apache2.conf file I have:

DocumentRoot /var/www/localhost/htdocs

In my 41_mod_ssl.default-vhost.conf file I have:

DocumentRoot "/var/www/localhost/sslhtdocs"

Both directories exist ane are owned by root and in group root.  The two directories have perms 755.  The files in each of the directories are owned by root and in group root as well.  The perms on the files are all 644.  Thus there should be no permissions problems.   However when I start the server and browse to https://127.0.0.1/index.html (which definitely exists with perms described above) I get the following error:

Forbidden

You don't have permission to access /index.html on this server.

Apache/2.0.52 (Gentoo/Linux) mod_ssl/2.0.52 OpenSSL/0.9.7d DAV/2 PHP/4.3.9 Server at 127.0.0.1 Port 443

This makes no sense to me since it seems from the config files everything is cool.  I reset the https documentroot to:

DocumentRoot /var/www/localhost/htdocs

and then it works when I go to https://127.0.0.1/index.html

However I want the insecure http server to serve different items then the https server.

Does anyone know what might be going on with my apache2.conf or my 41_mod_ssl.default-vhost.conf files?

Thanks...

----------

## plutek

greetings!

after having followed the howto in this thread, i was getting an error when trying to start apache, saying:

```
(20)Not a directory: apache2: could not open error log file /usr/lib/apache2/logs/error_log.

Unable to open logs

```

it seems the installation did not create the log dir.

after doing:

```
mkdir /var/log/apache2
```

apache starts successfuly.

hth somebody.

-p

----------

## To

Don't forget to chown the dir /var/log/apache2 to apache.

Tó

----------

## plutek

 *To wrote:*   

> Don't forget to chown the dir /var/log/apache2 to apache.
> 
> 

 

thanks.... forgot about that!

-p

----------

## Azerix

I kan´t start apache2

When i rebootmy gentoo i get this error

 *Quote:*   

> 
> 
> *ERROR: "/etc/init.d/apache2" has syntax errors in it; not executing....
> 
> 

 

Kan any one help me?

when stop apache2 i get this message

 *Quote:*   

> 
> 
> httpd (no pid file) not running
> 
> 

 

----------

## cmaurand

I read all of the instructions, but I've run into a problem.  I've used ufed to set everything to apache2, but every time I run emerge -p mod_ssl or mod_perl or some such module, Apache-1.3 shows up in the install list even thought Apache 2.0.nn is installed.  Any help here would be good.  I installed PHP with mysql support and it works fine and its loading as a module.

Thanks in advance,

Curtis Maurand

----------

## cleaner

Maybe you should do something like this:

USE="apache2" emerge -p mod_ssl

----------

## cmaurand

Here is what I get when I do that.  Its also set in make.conf and doesn't seem to make any difference.

orion # USE="apache2" emerge -p mod_ssl

These are the packages that I would merge, in order:

Calculating dependencies ...done!

[ebuild  NS   ] net-www/apache-1.3.32-r1

[ebuild  N    ] net-www/mod_ssl-2.8.21

----------

## cleaner

mmm, what USE flags are mentioned in your make.conf?

----------

## cmaurand

I have

USE="-* phpapache2 clamav innodb php"

----------

## ratsche

this works fine for me.

nice work ...really easy installation  :Wink: 

greetz,

ratsche

----------

## German3D

Hi , i need help :\

I cant runing apache , and i dont understand why

```
servidor ~ # /etc/init.d/apache2 start 

 * Starting apache2 ... 

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

no listening sockets available, shutting down 

Unable to open logs
```

Change 98756 times ServerName ... but dont work  :Sad: 

Tnx in advance

----------

## German3D

ok now only give me this error

```
servidor conf # apache2 -k start

no listening sockets available, shutting down

Unable to open logs

```

 :Rolling Eyes:   :Rolling Eyes:   :Rolling Eyes: 

----------

## theProphecy

Hi all...

Seems there has been some activity on this subject, so I figured I would update the tutorial to focus on Apache 2.x with PHP 5.x, but still including the old tutorial. Hope this new updated tutorial might help a few more people.  :Smile: 

----------

## erik258

Well, maybe all the pertinent info was available from the output of emerge ,but with the thousands of lines each emerge does it's pretty hard to pay attention to every single little colored asterick ; ).  Thank you sooo much for making this easier on me.  I am stoked to start learning PHP; my friends tell me there's lots of money there and i think some of it ought to be mine ; ).  

BTW, according to my computer,  The php apache module emerge and the command-line php emerge conflict with the dev-lang/php emerge .  I don't know why that would be but whatever.  Maybe that'll help someone or something.  And FYI everybody this howto is still completely relevent.

Thanks again, you rock!

----------

## libero

in response to the original post: 

It seems like maybe 

/etc/portage/package.use 

and 

/etc/portage/package.keywords

would be a better way to manage those customizations at the time of emerging PHP5

At least, that's the way I'm doing it.  

L

----------

## theProphecy

Indeed... Actually I configured those myself shortly after writing my article... Thinking about doing a complete article for installing and maintainging a Apache, php, MySQL, ftp and cvs server. I know that most people using the Gentoo distro already knows how to do this themselves, and probably have even more effecient/higly customized ways of managing their own. So it's mainly directed towards those who are new to Gentoo/Linux, who is just in need for a developing server and don't wan't to use a heck load of time on reading many different tutorials, or whom ever else would need such an article/Howto.

----------

## dark_priest

 *erik258 wrote:*   

> Well, maybe all the pertinent info was available from the output of emerge ,but with the thousands of lines each emerge does it's pretty hard to pay attention to every single little colored asterick ; ).  Thank you sooo much for making this easier on me.  I am stoked to start learning PHP; my friends tell me there's lots of money there and i think some of it ought to be mine ; ).  
> 
> BTW, according to my computer,  The php apache module emerge and the command-line php emerge conflict with the dev-lang/php emerge .  I don't know why that would be but whatever.  Maybe that'll help someone or something.  And FYI everybody this howto is still completely relevent.
> 
> Thanks again, you rock!

 

no.it.frigging.isnt.

you tell me where in the apache config files i'm supposed to add the " -D PHP5" now...

----------

## llongi

Hmm I did a quick check and at least the Apache2+PHP5 part of this howto seems correct, it uses the new Apache layout and dev-lang/php (wich sobstitutes dev-php/php, dev-php/php-cgi and dev-php/mod_php).

Anyawy, the "-D PHP5" needs to go into /etc/conf.d/apache2's APACHE2_OPTS variable.

----------

## dark_priest

yeah, i had figured that out ... 5 hours later. but in recent change, gentoo moved the file, this tutorial does not include that change. (or at least, not last time i read it)

----------

## fortenbm

 *theProphecy wrote:*   

> You're welcome... Just hope that my post maybe helped you out a bit.. 

 

hi and thanks... your how to worked great for me too. I have apache2, php5 and HelloWorld! displaying in my browser. Now on to designing the site!!

michael

----------

## morphal

Okay, old thread, I know but in case anybody else comes across this: Learn to use your /etc/portage/package.use and package.keywords files. Do not use use USE= and ACCEPT_KEYWORDS= variables.

To answer the question just above this: The new file that contains the APACHE2_OPTS variable is /etc/apache2/httpd.conf . This change was made to bring it more in line with just about every other implementation of Apache in the world. Believe me, it's a good thing.

----------

