First, I followed these old directions as a starting point for installing Apache and php. But I found that the extra repositories were already added, Apache was already installed and after installing php5, libapach2-mod-php5 was already install, so all I really had to was:
I test php functionality by creating a quick test file:
# apt-get install php5
# vi /var/www/test.phpAnd pointing my browser at http://localhost/test.php and seeing "Hello World".
# cat /var/www/test.php
On thing I noticed is that I was getting the following error when restarting:
# apache2ctl restartI fixed this by adding a ServerName directive to the Apache configuration (I actually don't think it matters what name you give):
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
# vi /etc/apache2/apache2.confNow, to install the virtual host so that I can test using code in my home directory. There are a number of sites out there if you google "apache vhost" and I didn't find any particularly good, so here is what I did.
# grep ServerName /etc/apache2/apache2.conf
ServerName localhost
For the sake of these directions, I'm going to use the name vhost.example.com and I'm going to put the name into /etc/hosts. This will allow me to see things exactly as they will appear on the live web site.
First I edit /etc/hosts and add an entry for the vhost:
# vi /etc/hostsNow it's time to edit the apache configuration:
# tail -1 /etc/hosts
127.0.0.1 vhost.example.com
Depending on what you need to do, you may not need the
# vi /etc/apache2/sites-available/myvhost.conf
# cat /etc/apache2/sites-available/myvhost.conf
NameVirtualHost vhost.example.com
<VirtualHost vhost.example.com>
DocumentRoot "/path/to/vhost/directory"
</VirtualHost>
<Directory /path/to/vhost/directory>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Now enable the vhost:
# a2ensite myvhost.confOne last snag, probably particular to how I handled my php, but I had the following .htaccess file in my vhost root:
Enabling site myvhost.conf.
Run '/etc/init.d/apache2 reload' to activate new configuration!# apache2ctl restart
AddHandler php-html .htmlWhich caused the following error whenever I tried to access the directory:
Action php-html /php/process.php
Invalid command 'Action', perhaps misspelled or defined by a module not included in the server configurationTo fix this, I enabled the actions module:
# a2enmod actionsNow, just restart Apache:
Enabling module actions.
Run '/etc/init.d/apache2 restart' to activate new configuration!
# apache2ctl restartAnd point my browser at http://vhost.example.com and everything worked.
Update 2/21/09: If you want to be able to run 'php' from the command-line, you should also install the php5-cli package (kudos):
# apt-get install php5-cli
No comments:
Post a Comment