Apache HTTP Server
Apache, PHP, and MySQL
This document describes how to set up the Apache web server on an Arch Linux system. It also tells how to optionally install PHP and MySQL and integrate these in the Apache server.
# pacman -Sy # pacman -S apache # pacman -S php # pacman -S mysql
If you like, you can install just apache, apache and php, or all three. This document assumes you will install all three, but if you wish, you can stop after any of the sections.
- Add line to
/etc/hosts(If the file doesn't exist, create it)
127.0.0.1 localhost.localdomain localhost
Note: if you want a different hostname, append it to the end:
127.0.0.1 localhost.localdomain localhost myhostname
If you set a hostname in step one, the hostame variable should be the same. otherwise localhost:
# # Networking # HOSTNAME="localhost"
- Comment one module in Apache configuration
# nano /etc/httpd/conf/httpd.conf
LoadModule unique_id_module modules/mod_unique_id.so
#LoadModule unique_id_module modules/mod_unique_id.so
- Run in terminal (as root):
# /etc/rc.d/httpd start
- Apache should now be running. Test by visiting
http://localhost/in a web browser. It displays a simple Arch Linux home page.
/etc/rc.conf(to start Apache at boot):
DAEMONS=(... some daemons ... httpd)
Or add this line to
- If you want user directories (ie:
~/public_htmlon the machine is accessed as
http://localhost/~user/) to be available on the web, uncomment the following lines in
<Directory /home/*/public_html> AllowOverride FileInfo AuthConfig Limit Indexes Options MultiViews Indexes SymLinksIfOwnerMatch ExecCGI <Limit GET POST OPTIONS PROPFIND> Order allow,deny Allow from all </Limit> <LimitExcept GET POST OPTIONS PROPFIND> Order deny,allow Deny from all </LimitExcept> </Directory>
You have to take into account that your home directory permissions must be set properly so that apache can get there. Your home directory and
~/public_html/ must be executable for others ("rest of the world"). This seems to be enough:
$ chmod o+x ~ $ chmod o+x ~/public_html
There may be some other, more secure ways of setting the permissions by creating a special group and allowing only apache and you enter there... You know how paranoic you are :)
Configure PHP4 & PHP5
PHP is practically available out of the box now.
- Uncomment this line in
#LoadModule php5_module lib/apache/libphp5.so
- then, for PHP4, simply substitute 4 for 5
LoadModule php4_module lib/apache/libphp4.so
- For PHP5 file handlers are already set up
<IfModule mod_php5.c> DirectoryIndex index.php index.html AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps </IfModule> DirectoryIndex index.html index.html.var
- However, for PHP4 support you need to make the following changes
#<IfModule mod_php5.c> DirectoryIndex index.php index.html index.html.var AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps #</IfModule> #DirectoryIndex index.html index.html.var
- Whether you use PHP4 or PHP5 remember to add a file handler for .phtml if you need it
DirectoryIndex index.php index.phtml index.html
- Restart Apache Server to make changes take effect (as root):
# /etc/rc.d/httpd restart
- Test PHP with a simple, but very informative script:
<html> <head> <title>PHP Test Page</title> </head> <body> This is Arch Linux, running PHP. <?php phpinfo(); ?> </p> </body> </html>
Save this file as
test.php and copy to
/home/httpd/html/ or to
~/public_html if you permitted such a configuration. Also remember to make it executable (
chmod a+x test.php).
- Test PHP:
Setup MySQL support
Do these only if you want MySQL support
/etc/php.ini(this is in
/usr/etcon older systems) to uncomment the following line (By removing
- To configure your system either run
/etc/rc.d/mysqld startas root OR complete the following steps manually:
- Add a mysql named group
# groupadd -g 89 mysql
- Add the mysql user
# useradd -u 89 -g mysql -d /var/lib/mysql -s /bin/false mysql
- chown the MYSQL root just in case - it may not exist yet
# chown -R mysql:mysql /var/lib/mysql
- Install the dbase. If you only want run mysql as root you don't need the --user option and chown
# mysql_install_db --datadir=/var/lib/mysql --user=mysql # chown -R mysql:mysql /var/lib/mysql
/etc/rc.d/mysqld startto start mysql as an Arch daemon.
- Test mysql (as root):
- Create root password for mysql (at terminal, as root):
# mysqladmin -u root password 'roots_password'
mysqldto the list of daemons in
/etc/rc.conf(as for httpd above)
- To login to mysql, type (at terminal, hostname as used in
# mysql -u root -h hostname -p
- You can add minor privilegued users for your web scripts by editing the tables found in the
mysqldatabase. You have to restart mysql for changes to take effect.
Don't forget to check the
mysql/userstable. If there's a second entry for root and your hostname left with no password set, everybody from your host probably could gain full access.
Perhaps see next section for these jobs.
- You can get the "error no. 2013: Lost Connection to mysql server during query" message instantly whenever you tried to connect to the mysql daemon by TCP/IP. This is the TCP wrappers system (tcpd), which uses the hosts_access(5) system to allow or disallow connections.
- If you're running into this problem, be sure to add this to your /etc/hosts.allow file:
# mysqld : ALL : ALLOW # mysqld-max : ALL : ALLOW # and similar for the other MySQL daemons.
- Notes: The examples above are the simplest case, telling tcpd to allow connections from anywhere. You may wish to use a more appropriate choice of permissible sources instead of ALL. Just make sure that localhost and the IP address (numeric or DNS) of the interface by which you connect are specified.
- You might also need to edit
/etc/my.cnfand change the line that says:
If you or your users want to use PHPMyAdmin to access the database, you might like to go on:
- Install the package
# pacman -S phpmyadmin
- phpMyAdmin has changed, the following applies now:
- Create configuration directory:
# cd /home/httpd/html/phpMyAdmin/ # mkdir config # chmod o+rw config
- Create a configuration file, visit:
- As a minimum add a new server in the "Servers" section. Use "cookie" for authentication to enable web-based cookie authentication (user/password authentication).
- Save the configuration file through the web based interface in the "Configuration" section.
- Move configuration file to phpMyAdmin dir for usage:
# mv config/config.inc.php config.inc.php
- You can reach PHPMyAdmin with your webbrowser: http://localhost/phpMyAdmin/
OLD CONFIGURATION INSTRUCTIONS
Note: You need to edit the
.htaccess file in
/home/httpd/html/phpMyAdmin/ and add the line
allow from all or
allow from 127.0.0.1 or you won't be able to browse http://localhost/phpMyAdmin/