Linux Mint - Free and powerful

Sunday, 26 January 2014

6. Creating a Linux Mint Power Server - LAMP and Wordpress


LAMP - Linux, Apache, MySQL, PHP and Wordpress

Wordpress is a powerful and flexible web publishing system. Here is how to install a multi site system on your new linux Mint server.

Accessing your new server remotely

You can use screen take over software such as VNC but you can also use the command line access using SSH. It is always preferable to have multiple ways to access a server in case one method fails.

Here is how to setup and use SSH

Install the ssh server

sudo apt-get install openssh-server

Access the ssh server remotely

ssh root@youripaddressordns

This will (should) now be displayed.

The authenticity of host '6.55.5.20 (6.55.5.20)' can't be established.
ECDSA key fingerprint is 79:95:46:1a::37:11:8e:8:54:36:38:bb:3c:fa:c0.
Are you sure you want to continue connecting (yes/no)?

Type in yes.
If you did not see this screen then you have messed up. Check your router and make sure port 22 is being forwarded to the correct internal ip address. Check that your ip address is correct. Check that there are no firewall blocks. If you are running on virtual software then check the host for access to port 22. 

Now add a new user.

adduser wpadmin
Adding user `wpdadmin' ...
Adding new group `wpadmin' (1006) ...
Adding new user `wpadmin' (1006) with group `wpadmin' ...
Creating home directory `/home/wpadmin' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Changing the user information for wpadmin
Enter the new value, or press ENTER for the default
Full Name []: wpaddin
Room Number []: 1
Work Phone []: 1
Home Phone []: 1
Other []: 1
Is the information correct? [Y/n] y

Root privileges for the new user.

All the commands run with sudo will be stored to the file ‘/var/log/secure' which can be reviewed later if needed. 

sudo visudo

Look for this line:

# User privilege specification
root ALL=(ALL:ALL) ALL
add:
wpadmin ALL=(ALL:ALL) ALL

Secure SSH by moving to a new port.

nano /etc/ssh/sshd_config

Change:

Port 25000
PermitRootLogin no

Also consider the following:

PasswordAuthentication no
AllowTcpForwarding no
X11Forwarding no
AllowUsers one two
LogLevel VERBOSE
Banner /etc/issue.net
(find a scary one here and embellish with NSA or DoD text: http://seclists.org/basics/2002/Dec/575)
sudo restart ssh

Now use:

ssh -p 25000 wpadmin@youripaddressordns

Network configuration

Multiple virtual IP Addresses.

This particular server is running several virtual machines, 4 Domino servers, 20 or so Wordpress sites and a number of other web services. It is crucial to have multiple ip addresses defined.

Check your config using:


ifconfig -a | grep eth

sudo lshw -class network

cat /etc/udev/rules.d/70-persistent-net.rules

sudo apt-get install ethtool

sudo ethtool eth0

Lots of information here to get your head around.

It is very easy using the Network Manager applet to define a static address and and static aliases. However, this does not always work properly with all applications. Domino has no issue with this configuration but virtualbox will do silly stuff and you will not know why. Any support call to a vendor will fall on deaf ears as it "suppose to work"

It is better, for a server type config, to disable the network manager and go with a manual config.

Disable Network Manager and create a static network config

Obvious warning:- Playing with your network config while remotely connected is like cutting off the branch you are sitting on with a chainsaw. You will fall, get hurt and end up on youtube. Ok, you may loose connection and if you are doing this on a Friday night your weekend will be rather crappy.   

Backup what you have: (Always backup what you have OK)

sudo cp /etc/NetworkManager/NetworkManager.conf /etc/NetworkManager/NetworkManager.conf.bak

sudo gedit /etc/NetworkManager/NetworkManager.conf

Change managed=false to managed=true

Customise interfaces

sudo cp /etc/network/interfaces /etc/network/interfaces.bak

sudo gedit /etc/network/interfaces

Here is an example:

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.19.50
netmask 255.255.255.0
network 192.168.19.0
broadcast 192.168.19.255
gateway 192.168.19.1
dns-nameservers 8.8.8.8 192.168.19.1 192.168.19.40
auto eth0:0
iface eth0:0 inet static
address 192.168.19.51
netmask 255.255.255.0
gateway 192.168.19.1
auto eth0:1
iface eth0:1 inet static
address 192.168.19.52
netmask 255.255.255.0
gateway 192.168.19.1

* in bold: resolv.conf no longer work as expected. It will be overridden. Add the dns-nameservers field to the interfaces file to ensure resolv.conf is correct. (from resolv.conf - "DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN")
This is one of the few times in Linux you will need to restart the server. You need this to "disengage" Network manager. To make changes after Network Manager is disabled you need to issue this command: 
sudo /etc/init.d/networking restart

or

sudo service networking restart

Managing the Hosts file

sudo cp /etc/hosts /etc/hosts.bak
sudo gedit /etc/hosts

For example:

127.0.0.1       localhost.localdomain   localhost
192.168.19.100 mint-computername.domainname.com  mint-computername

LAMP - Linux, Apache, MySQL, PHP

Install the Apache Web Server.

sudo apt-get update
sudo apt-get install apache2

To check your apache issue type your ip address into a browser window. Remember your firewall has to be open on port 80 for this to work. Here is one way of finding your ip address.

ifconfig eth0 | grep inet | awk '{ print $2 }'

use the output to type the following into a browser.
http://9.67.6.4

Your browser will have a message saying "It Works!"
Do not move forward until this works properly.

Install the MySQL database

sudo apt-get install mysql-server php5-mysql

Activate MySQL

sudo mysql_install_db

Secure MySQL

sudo /usr/bin/mysql_secure_installation

Install PHP (Hypertext Preprocessor).

sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt

Move index.php to the start of the directory index.

sudo nano /etc/apache2/mods-enabled/dir.conf

        DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm

Install a few modules of your choice

apt-cache search php5-

sudo apt-get install php5-mysql
sudo apt-get install php5-json
sudo apt-get install php5-exactimage

Create a quick info page for PHP

sudo nano /var/www/info.php

Add this:

phpinfo();
?>

Restart Apache

sudo service apache2 restart

Check the info page

http://9.67.6.4/info.php

Install PHPmyadmin

sudo apt-get install phpmyadmin php5-mcrypt

gksudo gedit /etc/php5/apache2/php.ini

add:

extension=mysql.so

sudo gedit /etc/apache2/apache2.conf

Include /etc/phpmyadmin/apache.conf

Install a multi site Wordpress installation

Multi site use http 1.1 to pass domain names to the correct wordpress installation. If you use an ip address this will not work.

Download the latest Wordpress files.

cd
wget http://wordpress.org/latest.tar.gz

Unzip and decompress:

tar xzvf latest.tar.gz

Create Site Databases and Users

mysql -u root -p

CREATE DATABASE Database1;
CREATE DATABASE Database2;

CREATE USER User1@localhost;
CREATE USER User2@localhost;

SET PASSWORD FOR User1@localhost= PASSWORD("Password1");
SET PASSWORD FOR User2@localhost= PASSWORD("Password2");

GRANT ALL PRIVILEGES ON Database1.* TO User1@localhost IDENTIFIED BY 'Password1';
GRANT ALL PRIVILEGES ON Database2.* TO User2@localhost IDENTIFIED BY 'Password2';

FLUSH PRIVILEGES;

exit

Now create the site directories

cd /var/www

sudo mkdir Site1
sudo mkdir Site2

Copy the sample config file

cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php

Copy the downloaded files

sudo rsync -avP ~/wordpress/ /var/www/Site1/
sudo rsync -avP ~/wordpress/ /var/www/Site2/

Set permissions 

sudo chown www-data:www-data -R /var/www/*
sudo usermod -a -G www-data wpadmin

Edit the config

cd /var/www/Site1
sudo nano wp-config.php


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

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

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

Apache Virtual Host Configuration

cd /etc/apache2/sites-available

sudo cp default.conf Site1.conf
sudo cp default.conf Site2.conf

sudo nano Site1.conf

ServerAdmin email_address
ServerName site1.com
ServerAlias www.site1.com
DocumentRoot /var/www/Site1
Options FollowSymLinks
AllowOverride all
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all

Repeat for site 2.

Install additional files

sudo apt-get install php5-gd

Activate the configuration

sudo a2ensite Site1
sudo a2ensite Site2

Restart apache

sudo service apache2 reload

This concludes - Creating a Linux Mint Power Server - 6 - LAMP and Wordpress 

0 comments :

Post a Comment

Thank you for taking the time to comment. Your opinion is important and of value and we appreciate the positive feedback! If you are "Negative Nancy" then please do us, and humanity, a favor, and piss off.

Total Pageviews

Google+ Followers

Pages

Blog Archive

Popular Posts

Recent Comments

Rays Twitter feed

Ads

Web sites come and go and information is lost and therefore some pages are archived. @rayd123. Powered by Blogger.