Category Archives: mysql

How To Install MediaWiki on Ubuntu 12.04

About MediaWiki

MediaWiki is a free open source wiki program that allows users to create their own personal wiki sites. Originally built for Wikpedia, MediaWiki is written in PHP and uses a backend database, like MySQL, to store its data.

Setup


The steps in this tutorial require the user to have root privileges.  
Before working with MediaWiki, you need to have LAMP installed on your server. If you don’t have the Linux, Apache, MySQL, PHP stack on your server, you can find the tutorial for setting it up http://mohammedwaseem.in/install-lamp-ubuntu/  .

Once you have the user and required software on the virtual private server, you can start installing MediaWiki!

Install Media Wiki

Because the apt-get package of MediaWiki is very out of date, MediaWiki should be installed from source. We can start off by downloading the latest version:

curl -O http://releases.wikimedia.org/mediawiki//1.19/mediawiki-1.19.9.tar.gz
After downloading tar, untar it.
tar -xvzf mediawiki-1.19.9.tar.gz

Move the contents of the MediaWiki directory to a a more convenient location:
sudo mv mediawiki-1.19.9 /etc/mediawiki
Create a symbolic link between the MediaWiki directory and Apache’s document root:
sudo ln -s /etc/mediawiki/ /var/www
And finish up by restarting apache.
sudo service apache2 restart

Create a MySQL User and Database


Although this step is not required for a successful installation of MediaWiki, it is definitely a recommended measure for added security. 

During the installation process, you will be asked to supply either a database and associated user for a MediaWiki database or your MySQL root password. MediaWiki uses this information to create the required wiki database and tables.

Setting up a dedicated database can be done very quickly and removes the need for sharing the MySQL root information and the associated security risks. We can go ahead and set up the database now:

Log into MySQL on your server:

mysql -u root -p


Once you are logged in, create your MediaWiki database. The default name that MediaWiki has in their configuration form is my_wiki, but you can name it whatever you prefer:

create database my_wiki;


Additionally, you will need to provide a user for the new database with the permissions that MediaWiki requires (replace the username and password below with details of your choice):

grant index, create, select, insert, update, delete, alter, lock tables on my_wiki.* to 'wikiuser'@'localhost' identified by 'password';


Finish up by implementing the changes and quitting MySQL:

FLUSH PRIVILEGES;
exit;


The next part of the installation needs to be completed through the onscreen instructions located at [domain]/mediawiki/index.php

Set Up MediaWiki


Go through and fill out the Media Wiki Site configuration in the browser. 

When you reach the “MySQL settings” section of the setup page, leave the Database Host as localhost and then enter in the MySQL database name and username and password, if you configured them in the previous step.

If you did not set up a new user for MediaWiki, write in root for the username and the root password in the password field.

You can leave the “MySQL specific options” section as is.

Once you have finished walking through the the configuration, keep pressing continue until you reach the page that says, “Complete!” 

Complete!

The LocalSettings.php file should start downloading automatically. Make sure that you have downloaded the file before closing out of the page. LocalSettings.php is auto-generated—if you do not have the Local Settings file, you will have to generate it once again by going through all of the MediaWiki setup steps.

Once the file downloads, you should upload it to /etc/mediawiki, or whichever directory contains MediaWiki’s “index.php” file on your virtual server. 

You can copy the LocalSettings.php file from your computer to the server, with SCP (Secure Copy), an SSH-based way of transferring files:

cp /path/to/LocalSettings.php /etc/mediawiki


After the file is uploaded, you will be able to access your personal wiki at[domain]/mediawiki.


	

How to Install LAMP on Ubuntu

The following tutorial presumes you understand what a LAMP Server is, how to work a website from the back end and how to install software using either the Software Centre or the Terminal. It also expect experience running other Basic Terminal Commands.

There is also an excellent article on Digital Ocean that may be of more relevance if you are working on a remote or public facing server.

Install Apache

To install Apache you must install the Metapackageapache2. This can be done by searching for and installing in the Software Centre, or by running the following command.

Install MySQL

To install MySQL you must install the Metapackagemysql-server. This can be done by searching for and installing in the Software Centre, or by running the following command.

Install PHP

To install PHP you must install the Metapackagesphp5 and libapache2-mod-php5. This can be done by searching for and installing in the Software Centre, or by running the following command.

Check Apache

Open a web browser and navigate to http://localhost/. You should see a message saying It works!

Restart Server

Your server should restart Apache automatically after the installation of both MySQL and PHP. If it doesn’t, execute this command.

Check PHP

You can check your PHP by executing any PHP file from within /var/www/. Alternatively you can execute the following command, which will make PHP run the code without the need for creating a file .

Congratulations, you have just Installed a Ubuntu LAMP Server!

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.

Installing Apache and PHP from source

I’ve just been through the process of installing the latest versions (as of this writing) of Apache 2.4.2 and PHP 5.4.5 from source on a new Debian 6 virtual machine for the first time.

I had some small issues along the way and thought I’d do a short post on the process I went through to get it working and resolve various errors which may help someone out. First we will install Apache, followed by PHP.

Prerequisites

Before starting you will need make, gcc and g++ installed.

apt-get install make gcc g++
I also had the latest version of MySQL installed (5.5.25a), as I wanted to use this later on. The latest version was downloaded from the Dotdeb repository

Installing Apache 2.4.2 from source

Apache was then downloaded from http://httpd.apache.org/download using wget on one of the mirrors in my country and then extracted.

wget http://apache.mirror.uber.com.au//httpd/httpd-2.4.2.tar.gz
tar xf httpd-2.4.2.tar.gz
cd httpd-2.4.2/
./configure –enable-so

Configuring Apache Portable Runtime library …
checking for APR… no
configure: error: APR not found. Please read the documentation.
–enable-so is needed later on for PHP.

At this point I downloaded APR 1.4.6 from apr.apache.org/download using wget and then extracted it.

cd ..
wget http://apache.mirror.uber.com.au//apr/apr-1.4.6.tar.gz
tar xf apr-1.4.6.tar.gz
cd apr-1.4.6/
./configure
make
make install
Apache will also need APR-util installed, which can be downloaded from the apr.apache.org/download page too. When you run configure you will have to specify where the apr config is, you should see this location in the output from make install after finishing apr above.

cd ..
wget http://apache.mirror.uber.com.au//apr/apr-util-1.4.1.tar.gz
tar xf apr-util-1.4.1.tar.gz
cd apr-util-1.4.1/
./configure –with-apr=/usr/local/apr/bin/apr-1-config
make
make install
Now that’s complete we can try Apache again.

cd ../httpd-2.4.2/
./configure –enable-so

checking for pcre-config… false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
pcre-8.30.tar.gz was then downloaded from http://pcre.org and for something different, I uploaded it to the server with SFTP to the root directory.

cd ..
tar xf pcre-8.30.tar.gz
cd pcre-8.30/
./configure
make
make install
Now to try Apache again…

cd ../httpd-2.4.2/
./configure –enable-so
make
make install
That’s it, Apache should now be ready to go, let’s move into the default installation and start it up.

cd /usr/local/apache2/bin/
./apachectl start
/usr/local/apache2/bin/httpd: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
ldconfig
./apachectl start
./apachectl -v
Server version: Apache/2.4.2 (Unix)
Server built: Jul 26 2012 20:51:23
That error relating to the shared libraries was resolved by running ldconfig, see the man page on that for more information.

Browsing to the IP address in my web browser now brings up the Apache default page. As ServerSignature is enabled by default, using Firebug for FireFox I can see “Apache/2.4.2 (Unix)” as the Server header in the response headers, confirming the new install of Apache has served my page.

Installing PHP 5.4.5 from source

PHP was downloaded from http://au.php.net/get/php-5.4.5.tar.gz/from/a/mirror and then uploaded to the root directory on the server using SFTP.

I’m configuring PHP with apxs, this wasn’t working for me unless Apache was configured with –enable-so. I was after MySQL support, feel free to leave –with-mysql off.

cd /root
tar xf php-5.4.5.tar.gz
cd php-5.4.5/
./configure –with-apxs2=/usr/local/apache2/bin/apxs –with-mysql=mysqlnd

configure: error: xml2-config not found. Please check your libxml2 installation.
apt-get install libxml2-dev
./configure –with-apxs2=/usr/local/apache2/bin/apxs –with-mysql=mysqlnd
make
make install
php -v
PHP 5.4.5 (cli) (built: Jul 26 2012 21:18:58)
Configuration

Once you have both Apache and PHP installed and running there is a bit of configuration to do so that Apache knows how to use PHP. I created a phpinfo file here /usr/local/apache2/htdocs/phpinfo.php and it will not display in a browser prior to configuration.

First off, let’s copy the library file over to Apache.

cp /root/php-5.4.5/libs/libphp5.so /usr/local/apache2/modules/
Next you will want to edit the Apache configuration file in /usr/local/apache2/conf/httpd.conf and add the following lines into it.

AddType text/html .php
AddHandler php5-script .php
This line should already be in there, referring to the .so file that was previously copied.

LoadModule php5_module modules/libphp5.so
You probably want to edit DirectoryIndex index.html and include index.php after this.

Once complete, restart Apache.

cd /usr/local/apache2/bin/
./apachectl restart