
The Steps
Check networking is working and hostnames are set correctly on the server:
1 2 3 4 5 6 |
cat /etc/hostname cat /etc/hosts hostname hostname <span class="hljs-operator">-f</span> ifconfig |
Update your install
1 2 3 |
<span class="hljs-built_in">sudo</span> apt-get update <span class="hljs-built_in">sudo</span> apt-get upgrade |
Install sysv-rc-conf to make looking after services easier.
1 2 3 4 |
<span class="hljs-built_in">sudo</span> apt-get install sysv-rc-conf <span class="hljs-built_in">sudo</span> sysv-rc-conf <span class="hljs-built_in">sudo</span> service ssh restart |
Install your basic LAMP server
LAMP stands for Linux (we already have the with Ubuntu) Apache MySQL and PHP – and a few other packages we’ll need later:
1 2 3 4 5 |
<span class="hljs-built_in">sudo</span> apt-get install apache2 php5 php5-mysql mysql-client mysql-server <span class="hljs-built_in">sudo</span> apt-get install build-essential <span class="hljs-built_in">sudo</span> apt-get install unzip <span class="hljs-built_in">sudo</span> a2enmod rewrite |
To enable .htaccess for sites hosted by apache, add this to the bottom of /etc/apache2/apache2.conf
1 2 3 4 |
<Directory /<span class="hljs-keyword">var</span>/www> AllowOverride All </Directory> |
Then Restart apache.
1 |
<span class="hljs-built_in">sudo</span> service apache2 restart |
You can now visit http://1.2.3.4 to make sure that apache server is working.
Test PHP is installed and working
1 2 |
<span class="hljs-built_in">sudo</span> vi /var/www/html/info.php |
1 2 3 4 |
<span class="php"><span class="hljs-preprocessor"><?php</span> phpinfo(); <span class="hljs-preprocessor">?></span></span> |
Install the NO-IP DUC
All domain names point to an IP address, and normally for a server, this is fixed. HOWEVER, you’re probably reading this as you want to try this at home and most home net connections don’t have a static IP address.
Using No-IP eliminates this problem as it lets you set up a domain name with a dynamic IP address. You need to sign up on their site first, and the directions below set up their Dynamic Update Client (DUC) on our little Ubuntu box.
1 2 3 4 5 6 7 8 |
<span class="hljs-built_in">cd</span> /usr/local/src/ <span class="hljs-built_in">sudo</span> wget http://www.no-ip.com/client/linux/noip-duc-linux.tar.gz <span class="hljs-built_in">sudo</span> tar xf noip-duc-linux.tar.gz <span class="hljs-built_in">cd</span> noip-<span class="hljs-number">2.1</span>.<span class="hljs-number">9</span>-<span class="hljs-number">1</span>/ <span class="hljs-built_in">sudo</span> make install <span class="hljs-built_in">cd</span> .. <span class="hljs-built_in">sudo</span> noip2 |
Install PhpMyAdmin
Installing PhpMyAdmin lets us manage the MySQL databases with a nice GUI via a webpage.
To install it;
1 2 |
<span class="hljs-built_in">sudo</span> apt-get install phpmyadmin |
And you can visit it at http://1.2.3.4/phpmyadmin
Install Joomla
Installing Joomla is fairly simple to do, but we need to delete the index.html file installed in the html directory by default to make sure that apache serves your Joomla site instead of the apache welcome page;
1 2 3 4 5 6 7 8 9 |
<span class="hljs-built_in">cd</span> /var/www/html/ <span class="hljs-built_in">sudo</span> rm index.html <span class="hljs-built_in">sudo</span> wget http://joomlacode.org/gf/download/frsrelease/<span class="hljs-number">19524</span>/<span class="hljs-number">159413</span>/Joomla_3.<span class="hljs-number">3.1</span>-Stable-Full_Package.zip <span class="hljs-built_in">sudo</span> unzip Joomla_3.<span class="hljs-number">3.1</span>-Stable-Full_Package.zip <span class="hljs-built_in">sudo</span> rm Joomla_3.<span class="hljs-number">3.1</span>-Stable-Full_Package.zip <span class="hljs-built_in">sudo</span> rm index.html sudp cp htaccess.txt .htaccess <span class="hljs-built_in">sudo</span> chmod -R <span class="hljs-number">777</span> * |
Now visit http://1.2.3.4 in your browser and you can install joomla (assuming you’ve set up a database and a user via PhpMyAdmin) onto your LAMP server.
Fix permissions
Once Joomla is installed, we need to reset the file permissions of the site.
1 2 3 |
sudo find . -type f -<span class="hljs-keyword">exec</span> <span class="hljs-keyword">chmod</span> <span class="hljs-number">644</span> {} \; sudo find . -type d -<span class="hljs-keyword">exec</span> <span class="hljs-keyword">chmod</span> <span class="hljs-number">755</span> {} \; |
Password protect the whole site (optional)
This is fairly straightforward – just do this and you’re sorted!
Edit the site’s .htaccess file;
1 2 |
<span class="hljs-built_in">sudo</span> vi .htaccess |
Add this to the bottom of the file:
1 2 3 4 5 |
AuthUserFile /<span class="hljs-keyword">var</span>/www/.htpasswd AuthName <span class="hljs-string">"Authorization Required"</span> AuthType Basic <span class="hljs-built_in">require</span> valid-user |
Also, create and edit /var/www/.htpasswd
1 2 |
<span class="hljs-built_in">sudo</span> vi /var/www/.htpasswd |
And insert your username as password values – it’s easiest to use an online generator to generate this code.
Install Samba
This will install samba so we have a password protected directory available to other computers;
1 2 3 4 5 6 7 |
<span class="hljs-built_in">sudo</span> apt-get install samba samba-common python-glade2 system-config-samba <span class="hljs-built_in">sudo</span> mv /etc/samba/smb.cnf /etc/samba/smb.cnf.bak <span class="hljs-built_in">cd</span> /etc/samba/ <span class="hljs-built_in">sudo</span> cp smb.conf.bak smb.conf <span class="hljs-built_in">sudo</span> vi smb.conf |
Add this to the bottom of the file – this creates the share definition named secured.
1 2 3 4 5 6 7 |
[secured] path = /samba/secured valid users = <span class="hljs-property">@smbgrp</span> guest ok = <span class="hljs-literal">no</span> writable = <span class="hljs-literal">yes</span> browsable = <span class="hljs-literal">yes</span> |
Next make the user group and add a user to that group
1 2 3 4 5 6 7 8 9 10 11 |
<span class="hljs-built_in">sudo</span> addgroup smbgrp <span class="hljs-built_in">sudo</span> adduser pcuser smbgrp <span class="hljs-built_in">sudo</span> smbpasswd <span class="hljs-operator">-a</span> pcuser <span class="hljs-built_in">sudo</span> mkdir -p /samba/secured <span class="hljs-built_in">cd</span> /samba <span class="hljs-built_in">sudo</span> chmod -R <span class="hljs-number">0770</span> secured/ <span class="hljs-built_in">sudo</span> service smbd restart <span class="hljs-built_in">sudo</span> chown -R pcuser:smbgrp secured/ <span class="hljs-built_in">cd</span> secured/ testparm |
Set up RSync to act as a backup on the LAMP server
1 2 3 4 5 6 7 8 9 |
cat /etc/services | grep rsync <span class="hljs-built_in">sudo</span> ufw allow <span class="hljs-number">873</span> <span class="hljs-built_in">sudo</span> vi /etc/default/rsync <span class="hljs-built_in">sudo</span> apt-get -y install xinetd <span class="hljs-built_in">sudo</span> vi /etc/xinetd.d/rsync <span class="hljs-built_in">sudo</span> vi /etc/rsync.conf <span class="hljs-built_in">sudo</span> mkdir /backups/sites/ <span class="hljs-built_in">sudo</span> service xinetd restart |
Boom!
You’ve just set up a pretty decent little hosting LAMP server for development purposes. You’ll need to perform some additional hardening to turn it into a production server for the wilds, but otherwise – nice work!
Please feel free to ask about anything in the comments…