Tag Archives: vps

Setting up a VPS to host your own server

Here are some simple instructions to get you started on setting up a virtual private server (VPS), so that you can host your own website. This website, for example, is setup on a VPS. This solution is more flexible, in my opinion, then purchasing “hosting” space, since you have full control over the server (for example, you may need to edit some php settings that hosted spaces don’t always let you do). Also, you can serve as many different websites as you want, and setup any server you like (I use it for VPN, mail, etc). You have to know some Linux though…

    1. Purchase a VPS. I have gotten some good deals on LowEndBox.com; they often have deals going on. You should choose a server with at least 1GB of RAM. KVM might be slightly better than openVZ, but you probably won’t note the difference. If you can, choose one that gives you a tun/tap interface (most do); this is useful if you ever want to setup a VPN (so that your ISP won’t spy on you!)
    2. When you setup your VPS, choose Ubuntu 12.04 or 14.04 64 bit (if you can, otherwise, the most recent version of Ubuntu).
    3. Login to your server and configure it. The VPS provider will have probably given you instructions to login as ‘root’. Once you have logged in by ssh, you should create your own user:
      adduser uname

      and add that user to the sudo group:

      sudo usermod -a -G sudo uname

Disable ssh for the root user (since that is an easy to guess username). Edit the file /etc/ssh/sshd_config and make sure you have the following line:

PermitRootLogon no

(typically just a matter of un-commenting the relevant line)
You should also install a LAMP stack (Linux, Apache, MYSQL, PHP) (google ‘Ubuntu LAMP stack’). As a minimum, install the apache web server, so that you can easily test your server with a browser.

sudo apt-get install apache
  1. Setup a DNS server. If you want to have a website with a domain name, rather than just an IP address. I typically by a domain name from GoDaddy. Once you own a domain name, you need to setup a DNS server (which tells other computers that your domain name points to a specific IP. I use freedns.afraid.org. You can get a free account, then add the domain that you own. If you then go to “sub-domains”, you can setup the IP address of your main domain and any subdomains that you want to setup under it (e.g. www.). Once you have setup the DNS on afraid.org, you need to go back to GoDaddy to manage your domain name and change its “domain name servers”, where you should set them to, for example, ns1.afraid.org, ns2.afraid.org, ns3.afraid.org, ns4.afraid.org (use all four). It might take several hours for GoDaddy and afraid.org to sync up, but when they do, your domain name is equivalent to the IP address (whether by ssh or html in your browser).

Setting up a wordpress site

This website has good instructions! Here they are for Ubuntu, augmented with some small modifications:

  1.  Install a LAMP stack on your server (apache, mysql, php)
  2. Download the latest wordpress (say into your home directory)
    wget http://wordpress.org/latest.tar.gz
    tar -xvzf latest.tar.gz
    cp wordpress/wp-config-sample.php wordpress/wp-config.php
    
  3. Create a database and configure it
    mysql -u root -p #to start mysql
    CREATE DATABASE DatabaseName;
    CREATE USER User@localhost;
    SET PASSWORD FOR User@localhost= PASSWORD("ThePassword");//choose a different password!
    GRANT ALL PRIVILEGES ON DatabaseName.* TO User@localhost IDENTIFIED BY 'ThePassword';
    FLUSH PRIVILEGES;
    exit;
    
  4. Create the directories for the website<
    sudo mkdir /var/www/website #where website is, e.g. ryanmartinphd.com
    sudo cp -r wordpress/* /var/www/website/.
    cd /var/www
    sudo chown www-data:www-data * -R #www-data owns the direcctory
    sudo usermod -a -G www-data linux_user_name #not strictly necessary
    sudo vi /var/www/website/wp-config.php #edit this to set the database parameters (next step)
    
  5. Configure wordpress for the database.In the wp-config.php file, make sure to edit these to the same value you did when setting up the database in mysql:
    define('DB_NAME', 'DatabaseName');
    define('DB_USER', 'User');
    define('DB_PASSWORD', 'ThePassword');
    
  6. Configure a virtual host on apache. Start with the default virtual server:
    cd /etc/apache2/sites-available
    sudo cp default website
    sudo vi website
    

    Now edit the following lines:

    <VirtualHost *:80>
    	ServerAdmin your_email_address
    	ServerName website.com
    	ServerAlias www.website.com
    	
    	DocumentRoot /var/www/website
    	<Directory />
    		Options FollowSymLinks
    		AllowOverride None
    	</Directory>
    	<Directory /var/www/website>
    		Options Indexes FollowSymLinks MultiViews
    		AllowOverride All
    		Order allow,deny
    		allow from all
    	</Directory>

    Now, enable the site, install an additional php module, enable mod_rewrite, and restart apache:

    sudo a2ensite website
    sudo apt-get install php5-gd
    sudo a2enmod rewrite
    sude service apache2 restart
    
  7. Launch the wordpress site by navigating to it. This will let you create the first user and should automatically setup everything
  8. Edit /etc/php5/apache2/php.ini to change the max_post_size, and max_upload variables to something bigger than their defaults (e.g. 100M).