Apache HTTP Server
(This wiki post copied from: http://bbs.archlinux.org/viewtopic.php?t=2409)
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"
- 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 now add httpd)
Or add this line to
- If you want user directories (ie: ~/public_html on the machine is accessed as http://localhost/~user/) to be available on the web, uncomment the following lines in /etc/httpd/conf/httpd.conf:
<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>
PHP is practically available out of the box now.
- Uncomment this line in
#LoadModule php5_module lib/apache/libphp5.so
- Restart Apache Server to make changes take effect (as root):
# /etc/rc.d/httpd restart
- Test PHP with a simple, but very informational script:
<html> <head> <title>PHP Test Page</title> </head> <body> <p> This is Arch Linux, running PHP. </p> <p> <?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:
Do these only if you want MySQL support
/etc/php.ini(this is in
/usr/etcon older systems) to uncomment the following line:
The following two steps should also be done for you at the first time you start up /etc/rc.d/mysql. Have a look into this file, if you're unsure.
- (optional, the script does that for you) You may need to set up a passwd and group entry for mysql:
- 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
- Run in a root terminal (you don't need the --user option and chown if you let it run as root):
# chown -R mysql:mysql /var/lib/mysql # mysql''install''db --user=mysql
If you trust the script, go on here:
- Test mysql (as root):
# /etc/rc.d/mysqld start # mysql
- 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)
Or add this line in
- To login to mysql, type (at terminal, >hostname< as used in /etc/hosts)
# mysql -u root -h >hostname< -p
- You can add minor privilegued users for your web scripts by editing the tables found in the "mysql" database. You have to restart mysql for changes to take effect.
Don't forget to check the mysql/users table. 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.
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
- Edit the configuration file to setup your needs:
Insert the according string to the PmaAbsoluteUri variable, so that it looks like follows
$cfg[['PmaAbsoluteUri']] = 'http://>hostname</phpMyAdmin/';
Fill in your mysql server's information. In PHPMyAdmin, multiple servers can be defined in the Servers array. To access your single mysql database, you have to edit the first entry; you can ignore the following ones.
On a regular system you only have to set auth_type to http. This means that phpMyAdmin directly uses the entered user and password to communicate with the mysql server, so it can't do stuff not allowed to the according mysql user.
$cfg[['Servers']][[$i]][['auth_type']] = 'http';
Be aware of that other auth methods or writing any password to this file can seriously damage your database security. Per default this file is world-readable.
- You can reach PHPMyAdmin with your webbrowser: http://localhost/phpMyAdmin/
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/