Category Archives: wordpress

How To Create a SSL Certificate on Apache for Ubuntu 12.04

About SSL Certificates

A SSL certificate is a way to encrypt a site’s information and create a more secure connection. Additionally, the certificate can show the virtual private server’s identification information to site visitors. Certificate Authorities can issue SSL certificates that verify the server’s details while a self-signed certificate has no 3rd party corroboration.

Set Up

The steps in this tutorial require the user to have root privileges on the VPS. You can see how to set that up here in steps 3 and 4.

Additionally, you need to have apache already installed and running on your virtual server.
If this is not the case, you can download it with this command:

sudo apt-get install apache2


Step One—Activate the SSL Module


The next step is to enable SSL on the droplet.
sudo a2enmod ssl
Follow up by restarting Apache.
sudo service apache2 restart
Step Two—Create a New Directory
We need to create a new directory where we will store the server key and certificate
sudo mkdir /etc/apache2/ssl

Step Three—Create a Self Signed SSL Certificate


When we request a new certificate, we can specify how long the certificate should remain valid by changing the 365 to the number of days we prefer. As it stands this certificate will expire after one year.
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt
With this command, we will be both creating the self-signed SSL certificate and the server key that protects it, and placing both of them into the new directory.

This command will prompt terminal to display a lists of fields that need to be filled in.

The most important line is "Common Name". Enter your official domain name here or, if you don't have one yet, your site's IP address.
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:New York
Locality Name (eg, city) []:NYC
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Awesome Inc
Organizational Unit Name (eg, section) []:Dept of Merriment
Common Name (e.g. server FQDN or YOUR name) []:example.com                  
Email Address []:webmaster@awesomeinc.com

Step Four—Set Up the Certificate


Now we have all of the required components of the finished certificate.The next thing to do is to set up the virtual hosts to display the new certificate. 

Open up the SSL config file:
 nano /etc/apache2/sites-available/default-ssl
Within the section that begins with <VirtualHost _default_:443>, quickly make the following changes.

Add a line with your server name right below the Server Admin email:
 ServerName example.com:443
Replace example.com with your DNS approved domain name or server IP address (it should be the same as the common name on the certificate).

Find the following three lines, and make sure that they match the extensions below:
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key
Save and Exit out of the file.

Step Five—Activate the New Virtual Host


Before the website that will come on the 443 port can be activated, we need to enable that Virtual Host:
sudo a2ensite default-ssl
You are all set. Restarting your Apache server will reload it with all of your changes in place.
sudo service apache2 reload
In your browser, type https://youraddress, and you will be able to see the new certificate.

Robots.txt

Web site owners use the /robots.txt file to give instructions about their site to web robots; this is called The Robots Exclusion Protocol.

It works likes this: a robot wants to vists a Web site URL, say http://www.example.com/welcome.html. Before it does so, it firsts checks for http://www.example.com/robots.txt, and finds:

User-agent: *
Disallow: /

The “User-agent: *” means this section applies to all robots. The “Disallow: /” tells the robot that it should not visit any pages on the site.

There are two important considerations when using /robots.txt:

  • robots can ignore your /robots.txt. Especially malware robots that scan the web for security vulnerabilities, and email address harvesters used by spammers will pay no attention.
  • the /robots.txt file is a publicly available file. Anyone can see what sections of your server you don’t want robots to use.

So don’t try to use /robots.txt to hide information.

How to create a /robots.txt file

Where to put it

The short answer: in the top-level directory of your web server.

The longer answer:

When a robot looks for the “/robots.txt” file for URL, it strips the path component from the URL (everything from the first single slash), and puts “/robots.txt” in its place.

For example, for “http://www.example.com/shop/index.html, it will remove the “/shop/index.html“, and replace it with “/robots.txt“, and will end up with “http://www.example.com/robots.txt”.

So, as a web site owner you need to put it in the right place on your web server for that resulting URL to work. Usually that is the same place where you put your web site’s main “index.html” welcome page. Where exactly that is, and how to put the file there, depends on your web server software.

Remember to use all lower case for the filename: “robots.txt“, not “Robots.TXT.

What to put in it

The “/robots.txt” file is a text file, with one or more records. Usually contains a single record looking like this:

To exclude all robots from the entire server
User-agent: *
Disallow: /
To allow all robots complete access
User-agent: *
Disallow:

(or just create an empty “/robots.txt” file, or don’t use one at all)

To exclude all robots from part of the server
User-agent: *
Disallow: /cgi-bin/
Disallow: /tmp/
Disallow: /junk/
To exclude a single robot
User-agent: BadBot
Disallow: /
To allow a single robot
User-agent: Google
Disallow:

User-agent: *
Disallow: /
To exclude all files except one

This is currently a bit awkward, as there is no “Allow” field. The easy way is to put all files to be disallowed into a separate directory, say “stuff”, and leave the one file in the level above this directory:

User-agent: *
Disallow: /~joy/stuff/

Alternatively you can explicitly disallow all disallowed pages:

User-agent: *
Disallow: /~joy/junk.html
Disallow: /~joy/foo.html
Disallow: /~joy/bar.html.

WordPress Installation on Ubuntu Linux with Apache and MySQL

This article describes an installation of WordPress on a Ubuntu Linux system using Apache web-server and MySQL database. WordPress is an CMS ( Content Management System ), mostly used as a blog publishing web application. WordPress is written in PHP language and uses MySQL database to store data.

Preliminary notes about the system used for this WordPress installation:

  • Ubuntu Linux 10.04 – Worpress 3.1 ( Reinhardt )
  • Kernel 2.6.32-21-generic #32-Ubuntu SMP
  • mysql Ver 14.14 Distrib 5.1.41
  • Apache/2.2.14 (Ubuntu)
  • PHP 5

1. Step 1: Prerequisites installation

# apt-get install php5-mysql mysql-server

2. Step 2: Download and Decompress WordPress

We start by downloading a latest version of WordPress and decompressing it into /var/www/wordpress .

# cd /var/www
# wget http://wordpress.org/latest.zip
# unzip latest.zip

At this point all files should be within /var/www/wordpress directory.

3. Step 3: Apache Configuration

In this step we will create a new apache site called wordpress, enable it and disable default apache website.

# cd /etc/apache2/sites-available
# sed 's/www/www\/wordpress/g' default > wordpress
# a2ensite wordpress
# a2dissite default

Restart apache to apply all changes:

# /etc/init.d/apache2 restart

4. Step 4: Creating WordPress database

Next, we will need to create a MySQL database to be used with our WordPress installation:

  • Username: wordpress
  • Password: wordpress
  • Database name: wordpress
# mysql -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 39
Server version: 5.1.41-3ubuntu12.10 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE DATABASE wordpress;
Query OK, 1 row affected (0.00 sec)

mysql> CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'wordpress';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON wordpress.* to wordpress@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

5. Step 5: Creating wp-config.php

To continue a WordPress installation we need to create a wp-config.php file to accommodate all WordPress configuration needs. Use following lines to insert database name, database user and password into wp-config.php file.

# cd /var/www/wordpress/
# cp wp-config-sample.php wp-config.php
# sed -i 's/database_name_here/wordpress/' wp-config.php
# sed -i 's/username_here/wordpress/' wp-config.php
# sed -i 's/password_here/wordpress/' wp-config.php
# chmod 600 wp-config.php

OR use text editor of your choice to supply wp-config.php with correct information:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wordpress');

/** MySQL database password */
define('DB_PASSWORD', 'wordpress');

/** MySQL hostname */
define('DB_HOST', 'localhost');

Ensure that apache have access to wordpress installation files. If this is your local system make sure that www-data owns of all files:

# chown -R www-data.www-data /var/www/wordpress

NOTE: Although localhost as a MySQL hostname within wp-config.php file is a most common option, you may need to change this value according to your webhost needs.

Here are some possible MySQL host values:

Hosting Company MySQL hostname
1and1 db12345678
AN Hosting localhost
A Small Orange localhost
BlueHost localhost
DreamHost mysql.example.com
GoDaddy h41mysql52.secureserver.net
HostGator localhost
HostICan localhost
ICDSoft localhost:/tmp/mysql5.sock
LaughingSquid localhost
MediaTemple GridServer internal-db.s44441.gridserver.com
NearlyFreeSpeech.Net username.db
one.com localhost
pair Networks dbnnnx.pair.com
Rackspace Cloud mysql50-01.wc1.dfw1.stabletransit.com
Yahoo mysql
Hosts with cPanel localhost
Hosts with Plesk localhost
Hosts with DirectAdmin localhost
Tophost.it sql.your-domain-name.it

Optional ( recommended ) step:

Create slathash for wordpress. Visit https://api.wordpress.org/secret-key/1.1/salt/ and copy all lines into your wp-config.php file replacing current non-set values.

6. Step 6: Install WordPress

At this stage everything should be ready to install WordPress on your ubuntu Linux system. Open your browser and point it to your webserver’s IP / hostname . Follow WordPress installer instructions to finish WordPress installation.

7. Troubleshooting

WordPress blank page problem:

If you have created wp-config.php file and navigated to your WordPress installation page using your browser you may see a blank page. This is mostly a result of wp-config.php misconfiguration. Check all data you have filled in to your wp-config.php as well as check actual permissions of this file.

If worst comes to worst you may attempt to continue WordPress installation without wp-config.php where WordPress installer will offer you creation of new wp-config.php file.