Prerequisites: Have Arch Linux installed and updated, set hostname, have a domain pointed to your Linode IP address as well as DNS records for any sub domains you want to use. (basically follow the getting started guide:
http://library.linode.com/getting-started)
NOTE: Some people will make the claim that lighttpd has a memory leak and thus should not be used. This was true a *long* time ago. The current release uses very few system resources and is a great lightweight web server.Now onto the Web server installation
First you need to
install the required packages:
Code:
pacman -S perl php php-cgi mysql fcgi openssl lighttpd
Now cd to /etc/lighttpd ,
create the conf.d directory and
download my ready made
lighttpd.conf and mimetypes file:
Code:
cd /etc/lighttpd
mkdir conf.d
wget http://p.linode.com/?dl=7329 lighttpd.conf
wget http://p.linode.com/?dl=7330 conf.d/mimetypes.conf
Open lighttpd.conf with your favorite editor and change the settings to match your system, specifically change example.com to your own domain
Now we need to create the user, group and directories mentioned in the config file.
Relevant sections:
Code:
server.username = "http"
server.groupname = "http"
server.errorlog = "/var/log/lighttpd/error.log"
accesslog.filename = "/var/log/lighttpd/access.log"
...
server.document-root = "/srv/http"
simple-vhost.server-root = "/srv/vhosts/"
simple-vhost.default-host = "example.com"
simple-vhost.document-root = "public"
NOTE: The document root and vhost root are different for security reasons. If you have a password protected directory at dev.example.com/private, and the server root and vhost root are the same, it would be possible for someone to gain access to your password protected directory doing this: http://example.com/dev.example.com/privateFirst we'll
create the http user and group:
Code:
groupadd http
useradd http
For more information on users and groups see: https://wiki.archlinux.org/index.php/Users_and_GroupsThen
make the /var/log/lighttpd and /var/run/lighttpd directories, and change their owner:group to http
Code:
mkdir /var/log/lighttpd
mkdir /var/run/lighttpd
chown -R http:http /var/log/lighttpd
chown -R http:http /var/run/lighttpd
Create the /srv/http and /srv/vhosts directoriesCode:
mkdir /srv/http
mkdir /srv/vhosts
Add some directories for your virtual hosts. Make sure each host has DNS records. In the case of test.example.com you could have a cname record pointing to example.com
Code:
mkdir /srv/vhosts/example.com
mkdir /srv/vhosts/example.com/public
mkdir /srv/vhosts/example.com/media
mkdir /srv/vhosts/test.example.com
mkdir /srv/vhosts/test.example.com/public
Now we need to
tell php where your hosts are.
Open php.ini with your favorite text editor. In my case its vim:
Code:
vim /etc/php/php.ini
You need to add /srv/vhosts to the open_basedir line:
Code:
open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/
changes to:
open_basedir = /srv/http/:/srv/vhosts/:/home/:/tmp/:/usr/share/pear/
Lets
add some test files:
Code:
touch /srv/vhosts/test.example.com/test.html
touch /srv/vhosts/test.example.com/test.shtml
touch /srv/vhosts/test.example.com/test.php
touch /srv/vhosts/test.example.com/test.pl
test.html:
Code:
<html>
<head>
<title>Test Page</title>
</head>
<body>
<h2>Test Page</h2>
<p>HTML test page is working!</p>
</body>
</html>
test.shtml:
Code:
<html>
<head>
<title>Test Page</title>
</head>
<body>
<h2>Test Page for SSI</h2>
<p>Server Time is: <!--#echo var="DATE_LOCAL" --></p>
<p>Your IP: <!--#echo var="REMOTE_ADDR" --></p>
</body>
</html>
test.php:
Code:
<?php
phpinfo();
?>
test.pl (you may need to make it executable with chmod +x test.pl):
Code:
#!/usr/bin/perl
print "Content-Type: text/html\n\n";
print "<HTML><head><title>Test Page</title></head>\n";
print ("<body><h2>Test Page</h2>\n");
print "<p>Perl test page is working!</p></body></html>";
exit (1);
Now its time to
start lighttpd:
Code:
systemctl start lighttpd
You can check the server status with:
Code:
systemctl status lighttpd
If everything looks good, set lighttpd to start at boot:
Code:
systemctl enable lighttpd
Debugging:Check your configuration file with:
Code:
lighttpd -D -f /etc/lighttpd/lighttpd.conf
Lighttpd keeps it's error.log in /var/log/lighttpd/error.log so you can check there for errors. "systemctl status lighttpd" will also show any errors if lighttpd does not run.
You can use strace to find other issues. "systemctl status lighttpd" will list the processes that lighttpd opens along with their pid's so if you wanted to strace php you would do:
Code:
strace -p <pid of /usr/sbin/php-cgi> -fF -e trace=file
Permissions:You should check your server permissions to make sure the files you want to serve are world readable and scripts can be executed from your web directories. I like to set directories as permissions 755 and files as 644
755 permissions:
owner: read, write, execute
group: read, execute
everyone: read, execute
644 permissions:
owner: read, write
group: read
everyone: read
To change all the directories in vhosts to 755 and files to 644 do:
NOTE: only do this if you know what you are doingCode:
find /srv/vhosts -type d -exec chmod 755 {} \;
find /srv/http -type f -exec chmod 644 {} \;Start the mysql daemon:Code:
systemctl start mysqld
Run secure installation:Code:
mysql_secure_installation
Restart mysqld:Code:
systemctl restart mysqld
Adding a Database
Open mysql console:
Code:
mysql -u root -p
In this example I added a database called test_db with user test_user and password testpswd:
Code:
CREATE SCHEMA `test_db` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
CREATE USER 'test_user'@'localhost' IDENTIFIED BY 'testpswd';
GRANT ALL ON `test_db`.* TO `test_user`@`localhost`;
exit
Import a database into your test_db
Code:
mysql -u test_user -p testpswd test_db < ~/database.sql
EXTRAS:
User web directories
If you would like to give your users their own web directories, you can uncomment the following from your lighttpd.conf:
Code:
## User Directories will show up as example.com/~user ##
userdir.path = "public"
userdir.include-user = ("user1",
"user2 )
Change user1 and user2 to the users you want to give web directories to. You will need to create a public folder in each user's home:
Code:
mkdir /home/user1/public
mkdir /home/user2/public
Make sure those directories are owned by the user in question and have 755 permissions on the public directory. You should restart lighttpd, and then be able to navigate to http://example.com/~user1 and http://example.com/~user2
FIN
Let me know if I missed something 