HOW TO SETUP WORDPRESS ON A FRESH DEBIAN SYSTEM
##################################################
 
This should work on DEBIAN 7 and DEBIAN 6
First we install LAMP and then MYSQL and then WORDPRESS
 
LAMP gives you all of the tools necessary to make perfect websites.
 
Apache2: the web server that will be used by wordpress
Mysql: The database that wordpress will use to store its information, like all of the source code
PHP: this is a server side programming language that will in a way connect Apache2 (the clients connecting from remote browsers across the internet) with Mysql.
 
NOTE ABOUT USER ACCOUNTS
#########################
 
You will make several decisions on your usernames and password and there will be several account to keep track of its important to know where they are used etc.
 
LINUX ROOT USERNAME: root
LINUX ROOT PASSWORD: what ever this is
 
ANY OTHER LINUX USERNAME – my guide is setup so that you set everything up from root linux user, but you can set it all up from another user, just make sure to use sudo like on every command, or use “sudo -i” so that it remembers your sudo for every command (to get out of sudo -i, just type exit)
 
MYSQL ROOT USERNAME: root
MYSQL ROOT PASSWORD: 87654321
 
MYSQL WORDPRESS DATABASE NAME: wpdb
MYSQL WORDPRESS USERNAME: bossdb
MYSQL WORDPRESS PASSWORD: 12345678
 
WORDPRESS ADMIN USERNAME: what ever you choose this to be
WORDPRESS ADMIN PASSWORD: what ever you choose this to be
 
THE STEPS:
###########
 
Log in as the root linux user to your box.
 
INSTALL EVERYTHING
===================
 
# apt-get update
 
# apt-get install zip
# apt-get install unzip
 
# apt-get install nano
# apt-get install vim
 
# apt-get install apache2
# apt-get install mysql-server
This will bring up a CLI window (ncurses window – gui made out of cli) that will ask to set the root password for sql. This root user is different then your debian systems root user. This root user is the root user of your mysql database, this user can do everything on mysql (he has full privileges). I Set password to “87654321” (not really but for example sake, I hope your password is more secure)
 
# mysql_secure_installation
The app mysql_secure_installation will ask questions, say no to all of them, I just say yes to “remove test database” and yes “to reload privileges table now”
 
# apt-get install php5 php-pear
# apt-get install php5-mysql
# service apache2 restart
 
SETUP MYSQL DB FOR WORDPRESS
=============================
 
Decide on wordpress database name, it doesnt really matter but it will be there forever, i used either “wordpressdb” or “wpdb” or just “wordpress” – I will use “wpdb”. Decide on a username that will control that database, this will only be a mysql user, we can just tell wordpress to use the “root” mysql user. I used username “bossdb” for mysql, and password “12345678” (in reality pick a better password)
 
Log in to mysql (-u root tells to log in with root user, and -p tells to ask for password)
# mysql -u root -p
Enter Password: 87654321
 
Next enter the commands you see after the mysql> prompt, every command must end with a ; (if you miss it, a new line will show and just hit ; ENTER and you will complete the command). Commands in sql can be lowercase or uppercase, the variables set like ‘wpdb’ and password ‘1234578’ and usernames ‘bossdb’ are case sensitive. But notice for example: ‘CREATE DATABASE wpdb;’ I could also write ‘create database wpdb;’.
 
mysql> CREATE DATABASE wpdb;
Query OK, 1 row affected (0.00 sec) <—NOTE THIS IS OUTPUT
 
mysql> CREATE USER ‘bossdb’@’localhost’ IDENTIFIED BY ‘12345678’;
Query OK, 0 rows affected (0.00 sec) <—NOTE THIS IS OUTPUT
 
mysql> GRANT ALL PRIVILEGES ON wpdb.* TO ‘bossdb’@’localhost’;
Query OK, 0 rows affected (0.00 sec) <—NOTE THIS IS OUTPUT
 
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec) <—NOTE THIS IS OUTPUT
 
mysql> quit
 
CONFIRMING MYSQL DB FOR WORDPRESS (OPTIONAL CAN SKIP BUT I WOULDNT)
====================================================================
 
We will test by loggin in with bossdb and make sure he has the grant/priviledge that we set and that he cant do something a root user can do (make a database).
 
Now lets confirm the settings. If we check “show grants” from root, it will only show root grants for some reason (maybe Im doing that confirmation step wrong, but im going to show you how to check grants for currently logged in user, so we will log in as bossdb
 
# mysql -u bossdb -p
Enter Password: 12345678
 
mysql> show grants;
+—————————————————————————————————————+
| Grants for bossdb@localhost                                                                                   |
+—————————————————————————————————————+
| GRANT USAGE ON *.* TO ‘bossdb’@’localhost’ IDENTIFIED BY PASSWORD ‘*E1DF7F12EA92B4964436B5D1ECA7288A67E91F90’ |
| GRANT ALL PRIVILEGES ON `wpdb`.* TO ‘bossdb’@’localhost’                                                      |
+—————————————————————————————————————+
 
TEST THE ABILITY TO MAKE A NEW DATABASE (since we are not root and only set privileges to the wpdb database this next command should fail):
 
mysql> create database test123;
ERROR 1044 (42000): Access denied for user ‘bossdb’@’localhost’ to database ‘test123’ <— OUTPUT, GOOD IT SHOULD FAIL
 
NOTE: If the database test123 was made by the above command you can erase it with “drop database test123;”. You will need to look into why your bossdb account was able to make the database, it shouldnt have so many privileges (thats only for root account) So I would exit and login as root and delete the user.
 
Some extra mysql commands:
See all users (you should see a few root users, one for ipv4 localhost, one for ipv6 localhost, one for all interface etc):
select * from mysql.user;
See all databases:
show databases;
 
 
INSTALLING WORDPRESS
=====================
 
# cd ~
# wget http://wordpress.org/latest.zip
# unzip latest.zip
 
WITH SHOPT (shell options) I WILL SET (-s) THAT * INCLUDES HIDDEN FILES AS WELL (BY DEFAULT * DOESNT SELECT ANY HIDDEN FILES OR HIDDEN FOLDERS ON THE ROOT OF MENTIONED DIRECTORY – AS TO CONTRARY BELIEF * WILL STILL SELECT HIDDEN FILES AND FOLDERS WITHIN THE NONE HIDDEN SUBFOLDERS OF THE MENTIONED DIRECTORY – BUT ALL CONTENTS OF HIDDEN SUBFOLDERS WILL BE MISSED – SETTINGS DOTGLOB TO ON, WILL MAKE IT SO * SELECTS ALL REGULAR AND HIDDEN FILES, AND THUS HIDDEN SUBFOLDERS WILL ALSO GET THEIR HIDDEN FILES AND REGULAR FILES SELECTED – EVERYTHING IS SELECTED) – AFTER THE COPY I TURN OFF DOTGLOB (with -u MEANING UNSET) TO TAKE US BACK TO NORMAL:
 
# shopt -s dotglob
# cp -R ~/wordpress/* /var/www/
# shopt -u dotglob
 
# chown -R www-data:www-data /var/www/
# cd /var/www/
# cp wp-config-sample.php wp-config.php
 
WE NEED TO TELL WORDPRESS HOW TO ACCESS THE MYSQL DATABASE:
# vim wp-config.php
OR:
# nano wp-config.php
 
TO EDIT:
WITH NANO: use arrow keys to navigate and type to write
WITH VI: Hit i key to get into insert/editing mode
 
EDIT THE PART THAT THIS:
 
// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */
define(‘DB_NAME’, ‘database_name_here’);
 
/** MySQL database username */
define(‘DB_USER’, ‘username_here’);
 
/** MySQL database password */
define(‘DB_PASSWORD’, ‘password_here’);
 
 
TO MATCH WHAT YOU HAVE SET FOR YOUR:
 
// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */
define(‘DB_NAME’, ‘wpdb’);
 
/** MySQL database username */
define(‘DB_USER’, ‘bossdb’);
 
/** MySQL database password */
define(‘DB_PASSWORD’, ‘12345678’);
 
SAVE AND EXIT:
WITH VI: Hit ESCAPE first to get out of editing mode then “:wq! ENTER” Type that without the space and quotes, hit enter where it says ENTER 
WITH NANO:  Write: Control-O ENTER, Exit: Control-X ENTER
 
CONFIRM YOU SEE THE CHANGES WHEN YOU READ THE FILE WITH CAT (YOU MIGHT NEED TO SCROLL UP – EASY TRICK TO SCROLL HOLD SHIFT AND PRESS PAGEUP / PAGEDOWN TO SCROLL DOWN)
# cat wp-config.php
 
THATS IT YOUR BASICALLY DONE WITH THE LINUX SIDE OF WORDPRESS SETUP 
 
ACCESSING YOUR WORDPRESS:
==========================
 
Find out your ip address, if your using hostnames hopefully you have DNS taken care of. Hopefully the networking is taken care of, this is not an article on networking.
 
THRU SAME SUBNET
—————–
For local access (From same subnet/network) – find your ip:
# ifconfig 
 
Lets say your IP is: 192.168.0.50
 
Open a browser on a computer (like a windows computer in the same network): http://192.168.0.50/
 
You can also access from the linux computer if you have a browser and gui there: http://192.168.0.50/ or this will also work http://127.0.0.1/ or also http://localhost/
 
THRU INTERNET TO YOUR PERSONAL SERVER
—————————————-
Assume your public IP to your network/router is 50.50.50.50
If you have networking setup correctly (port 80 tcp and port 443 tcp port forwards from your router public ip to your linux server ip 192.168.0.50 in my case) and DNS (your own domain – perhaps that you bought with www.godaddy.com – that points an A record at the public IP of your router) and can access your linux box across the internet by IP (because of the portwords) and by hostname/dns (because of the dns settings that you set correctly up on your dns manager – a dns manager such as www.godaddy.com – an A record of @ that points at your public IP of 50.50.50.50 and an A record of www that also points at your public IP of 50.50.50.50 – with that http and https will work – http access will work right off the bat, but https wasnt covered in this article, to make https workd, some apache settings must be changed thru the linux side is all and also the portforward for port 443)
 
NOTE: godaddy.com is used to buy domains and set up your DNS, also can do much more then that, but I just use its basic setup. Bought the DOMAIN and I let it control my DNS.
 
THRU INTERNET WITH VPS LIKE AMAZON EC2 or RAMNODE or DIGITAL OCEAN
——————————————————————-
What you need and have already: a linux box vm/vps/ec2 that you accessed and setup the above  wordpress and lamp installation instructions with (hopefully this has a static public ip), a domain that you bought (unless you want to be accessing your wordpress by ip only)
Find out the public IP that you recieved that accesses your linux box for example: 50.50.50.50
Lets imagine your domain name is “example.com”. Then on your domain manager (example: www.godaddy.com) go to your DNS settings and add an A record that says @ goes to 50.50.50.50 (that will point your naked domain to a website, meaning when you go to http://example.com it will take you to the site you dont need a www. or anything before that) Also add another A record that says www goes to 50.50.50.50 (that way going to http://www.example.com will take you to the site as well)
Note DNS will take care of any port so http port 80 and https port 443, they are seperate entities. To make HTTPS work you will need to configure you linux box apache2 and also configure your router to portforward that 443 https port.
 
NOTE: godaddy.com is used to buy domains and set up your DNS, also can do much more then that, but I just use its basic setup. Bought the DOMAIN and I let it control my DNS.
 
SETUP WORDPRESS
================
 
Your pretty much done now.
 
After you login you will be met with a wordpress setup page. If any errors in your setup exist it will tell you, and you can fix em by googling them. But hoepfully you followed my directions to the T and then it should all work (at least on my Debian 7 fresh RAMNODE – a vps made out of fast flash – box it did work)
 
It will go thru making yet another user, the main admin user for the website administration (this is different then your mysql users or your linux users)
 
Then you can begin by working on your wordpress, go thru all of the settings, review youtube wordpress tutorials etc.
 
You can install plugins etc.
 
Good luck wordpressing.
 
WHAT TO SETUP AFTER THIS:
==========================
 
I would research IPTABLES (a software firewall for your server), and setup basic IP tables on your linux box that says only allow in port 80, 443 and port 22 all on TCP. Also allow all connections outbound  (That way you can surf the web). Also allow inbound any connections that were made outbound and came back (That way you can surf the web).
 
Also I would setup apache2 settings so that SSL works that way you have secure connections on HTTPS instead of HTTP. You can make it so that apache2 works on HTTP (port 80) and/or HTTPS (port 443)

Leave a Reply

Your email address will not be published. Required fields are marked *