How to manually install Wordpress on a LAMP server?


(Arrowsoft.IT Srls) #1

Hello Everyone!

In this article we would like to explain how to instal a wordpress on a linux server that running apache as web server, php as scripting component and MySQL as database managment service.

This kind of architectures is called LAMP.

#Before starting
This article is dedicated to all the peoples that want to install by hand a wordpress instance. So, if you are a novel server administrator, you could be stucked on the huge amount of file and directory that linux provide to you!

Also, when you talk about LAMP, we need to choose what linux distribution we want to use! There are huge amount of Linux distribution from which you can choose, but for the purpose of this article we will use debian.

No worry! With this tutorial you will install wordpress on lamp in just 5 minutes (if you have a good internet connection on your server!)

##Let’s go!
In order to install wordpress we need a linux server (a window version still exist but we only cover open source things).

You must start by login in your server and open a shell. We will use vim as text editor, because we are purist! You could use a graphical editor (like gedit or other) but if you start using vim, you will never go back! Vim is a god!

Upgrade your server

So, as first step, open console, write the followig row and then press enter!

sudo apt-get update
sudo apt-get upgrade

This two rows will update your system installing all the latest updates.

Install VIM

As second thing, we will install Vim.

sudo apt-get install vim

Ohoh! Now you have Vim on your machine! This is a good thing.

Install LAMP components

As third step, you need to install all software included in a LAMP architecture. So, you need to install APACHE (A), MySQL (M) and PHP §. You already have LINUX (L):grin:

In the console, put the following lines, one at time and press enter!

sudo apt-get install apache2

When apache is ready, try to connect with your browser to http://localhost:80. You should see the apache welcome page!

Go ahead by installing PHP runtime and the PHP module for MySQL.

sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql

After installation, go in /var/www/ and looking for index.html and remove it! Then, write the following command on the shell. I inserted [todo] action in order to allow you to use vim if you don’t know how it work. See here a command list for vim.

vim index.php
[press i]
<?php phpinfo() ?>
[press esc]
[write :w] and [press enter]
[write :q] and [press enter]

In this manner you have created a php file named index in which you request to php to put on the screen all PHP configuration dump. Check again http://localhost:80 and you will see a page like the following:

Go ahead! Now, we must install MySQL and phpMyAdmin that will help you to explore MySQL database instances without using command line.

In order to install MySQL, write the following line in your console and press enter!

sudo apt-get install mysql-server

LAMP is ready!

Now, we have a LAMP server and we need to install wordpress. As first thing go in /tmp directory with:

cd /tmp

In this directory we can download files that will be deleted at next reboot. So, download the last version of wordpress by the following command.


After download, unzip your file with:


Please note, if you do not have installed unzip on your server write the following command before trying to unzip wordpress.

sudo apt-get install unzip

Installing Wordpress Instance in an Apache directory

After unzipping the file you will have a new directory called wordpress in the /tmp. So you can write the following command:

 cd /tmp/wordpress

Now is the time to create a new website handled by apache! As first thing, create the folder in which website (wordpress instance) will be placed.

mkdir /var/www/wpsitename

cp /tmp/wordpress/* /var/www/wpsitename -r

Then, allow current user to manipulate wpsitename folder (i don’t know your username so use it instead of LUSER.

chown LUSER /var/www/wpsitename -hR
chgrp LUSER /var/www/wpsitename -hR

Now, your user is ready to to all the other things that wordpress need in order to work properly! We must create an uploads folder in the wpsitename directory (i don’t know why wordpress programmer not zip an empty folder in their zip, maybe because you can choose to move this directory in other filesystem place).

This directory is used by wordpress in order to download and install themes, plugin and in order to handle your media.

mkdir /var/www/wpsitename/uploads
sudo chmod 777 /var/www/wpsitename/uploads 

Create and install new MySQL database for wordpress

Now, you have wordpress instance installed on filesystem but you need a place in which wordpress can store link, tag, posts and other things. So, you need to connect wordpress to mysql.

In your console, you must write:

mysql -u root -p 
CREATE USER wpsitename@localhost IDENTIFIED BY 'wpsitenamepass';
GRANT ALL PRIVILEGES on wpsitename.* to wpsitename@localhost;

Link wordpress with new mysql database

Now it is time to link wordpress and mysql :slight_smile:
You need to create a copy of the wp-config-samples.php with name wp-config.php in /var/www/wpsitename.

You have to write the following command:

cp /var/www/wpsitename/wp-config-sample.php /var/www/wpsitename/wp-config.php

Now, you have to change the parameters in this file.

vim /var/www/wpsitename/wp-config.php
[press i]

Replace the following line with the correct values:

// ** Impostazioni MySQL - È possibile ottenere queste informazioni dal proprio fornitore di hosting ** //
/** Il nome del database di WordPress */
define('DB_NAME', 'DATABASE NAME'); # wpsitename

/** Nome utente del database MySQL */
define('DB_USER', 'MYSQLUSERNAME'); #wpsitename

/** Password del database MySQL */
define('DB_PASSWORD', 'MYSQLPASS'); #wpsitenamepass


 [press esc]
 [write :w and press enter] 
 [write :q and press enter]

We are almost there!

The last thing to do is to ask to apache to handle our website :slight_smile:
Apache uses /etc/apache2/sites-enabled/000-default.conf as default configuration file. We suppose that you are using a fresh LAMP server so you can write in your console:

sudo vim /etc/apache2/sites-enabled/000-default.conf

Now, you need to follow the correct way!

If you already have domain name to assign to wordpress…

If you already have a domain that want to bind to your wordpress site you need to add the following code in your apache configuration file.

<VirtualHost *:80>
        ServerName YOURDOMAIN
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/wpsitename

        ErrorLog ${APACHE_LOG_DIR}/mywperr.err
        CustomLog ${APACHE_LOG_DIR}/mywp.err combined


Then, save and quit from vim by:

[press esc]
[write :w and press enter]
[write :q and press enter]

Now, it’s time to boot your new wordpress site! On your console ask apache to restart!

sudo apachectl restart 

Then, try to connect to http://localhost:80
You will see your wordpress installation form! :slight_smile: :slight_smile:

If you don’t have domain but want to start wordpress on another port

If you don’t have yet a domain but want to start the work on your wordpress site you can ask to apache to answer on another port (not the 80) by the following line.

Open Apache configuration.

sudo vim /etc/apache2/sites-enabled/000-default.conf

And add the following line at the end of the file.

Listen 8888
<VirtualHost *:888>

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/wpsitename

        ErrorLog ${APACHE_LOG_DIR}/mywperr.err
        CustomLog ${APACHE_LOG_DIR}/mywp.err combined


Then, save and quit from vim by:

[press esc]
[write :w and press enter]
[write :q and press enter]

Now, it’s time to boot your new wordpress site! On your console ask apache to restart!

sudo apachectl restart 

Your website will appear on http://localhost:8888