What will be covered in this post is the creation of a server on your Ubuntu 9.10 Machine , hosting of a html or PHP website accessible through a free domain redirection to your IP address which will later become automated to update the redirection with your ever changing dynamic IP assignments from your ISP. This is done by Installing Apache2 webserver with PHP5 and MySQL, additional software such as inadyn will also be installed. Installation of a website will not be covered, this tutorial has been tested using WordPress and MetaWiki. As usual use only if you have advanced knowledge of Linux.
Step One: MySQL 5
To begin open a terminal.
Type:
sudo apt-get install mysql-server mysql-client
You will be asked to provide a password for the MySQL root user – this password is valid for the user root@localhost as well as root@example.com.
New password for the MySQL “root” user: EnterYourPassword
Repeat password for the MySQL “root” user: EnterYourPassword
Step Two: Installing Apache2
Back in the Terminal type:
sudo apt-get install apache
Now direct your browser to “http://localhost” and you should see the Apache2 placeholder page (It works!)
Apache’s default document root is “/var/www” on Ubuntu and the configuration file is “/etc/apache2/apache2.conf”
Step Three: Installing PHP5
Install PHP5 and the Apache PHP5 module as follows:
sudo apt-get install php5 libapache2-mod-php5
Restart Apache afterwards:
sudo /etc/init.d/apache2 restart
Step Four: Testing PHP5 / Details About Your PHP5 Installation
The document root of the default web site is “/var/www/” we will now create a small PHP file called “info.php” in that directory and access it in a browser. The file will display details about your PHP installation such as the installed PHP version and modules.
sudo pico /var/www/info.php
Now type this into the file and save then exit.
<?php
phpinfo();
?>
(Exit and save by pressing control + x, then type “y” and hit enter)
To access this in your browser type: http://localhost/info.php
If you see the status page then PHP5 is working and it’s working through theApache 2.0 Handler, as shown in the Server API line. If you scroll further down, you will see all modules that are already enabled in PHP5. MySQL is not listed there which means we don’t have MySQL support in PHP5 yet.
Step Five: Getting MySQL Support In PHP5
To do this install the php5-mysql package. It’s a good idea to install some other PHP5 modules as well as you might need them for your applications. You can search for available PHP5 modules like this:
sudo aptitude search php5
Pick the ones you need and install them by typing:
aptitude install php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-json
Now restart Apache2:
sudo /etc/init.d/apache2 restart
Reload http://localhost/info.php in your browser and scroll down to see the modules section. You will now find your new modules including the standard MySQL modules.
Step Six: phpMyAdmin
PhpMyAdmin is a web interface in which you can manage your MySQL databases. It’s a good idea to install it:
sudo apt-get install phpmyadmin
Select the following:
Web server to reconfigure automatically: apache2
Configure database for phpmyadmin with dbconfig-common?: No
When this is complete enter this into a terminal:
sudo ln -s /usr/share/phpmyadmin/ /var/www
Step Seven: Configuring a Database in phpMyAdmin
Please note that depending on the type of site you choose to install your database may need a custom and different configuration then follows.
To access phpMyAdmin type “http://localhost/phpmyadmin/” into your browser.
Login username will be “root” and password is the one created during step one.
Enter a name for your database in field under “Create new database”
Hit Create and select the privileges tab on the same window
Select add new user at the bottom of this tab and choose a user name, password and only fill out those fields hitting “Go” in the bottom right to create the user. These are now your credentials for your first database in phpmyadmin.
Step Eight: Installing your Website
Now that you have a database you can install your website, this can be done many different ways for different sites but most PHP sites are the same. Extract the downloaded PHP zip for your WordPress site to the “/var/www/” folder, go to a browser and type “http://localhost/install.php”. This will prompt your through the sites install. If your receive any errors feel free to post it in the comments and I will try and help.
Step Nine: Configuring a Redirection (dyndns.com)
The service we will be using is dyndns.com and their free Dynamic DNS. If you haven’t already, go to there site and register your free account. This service is very stright forward in setting up a free domain to redirect to your external IP address so anyone accessing your site will not need to know your current IP address as it’s always changing.
Step Ten: The Final Step
Assuming that your server and website is up and running and you have dyndns.com redirecting to your external IP address, you will want to configure one last thing to ensure dyndns.com stays up to date with your dynamically changing IP. This will happen if you disconnect and reconnect or if your ISP assigns you a new one.
Be advised that the following is not to be used on a multi-user computer as it will expose your password to those users for the dyndns.com service.
We need to install a package called inadyn, type the following in a terminal:
sudo apt-get install inadyn
Now that we have a service installed we need to create the config file with some instructions.
Type the following in a terminal:
sudo pico /etc/inadyn.conf
Add the following to our empty inadyn.conf file:
# Basic configuration file for inadyn
#
# /etc/inadyn.conf
update_period_sec 600 # Check for a new IP every 600 seconds
username YourUserName
password YourPassword
dyndns_system dyndns@dyndns.org
alias EnterYour.DyndnsDomain.com
Replace the username & password sections as well enter your domain that we created with dyndns.
After you have placed those lines with replaced sections hit control+X, then type “Y” Hit “Enter”.
This will save your configuration file and we can move on to the last step.
Adding a script to your startup applications.
Startup Applications is located in the following menu tree:
System>Preferences>Startup Applications
Hit the add button and enter the following:
Name: CheckIP
Command: inadyn –username YourUserName –password YourPassword –update_period_sec 600 –alias EnterYour.DyndnsDomain.com
Comment: I left this blank
Hit Save and your done, you now have a service which will at startup check your external IP every 10 minutes and if your IP is changed it will automatically update your dyndns domain name with the proper IP so your site will continue to function and be accessible even with a dynamic IP from your ISP.