Tuesday, September 9, 2014

How to configure LAMP and Wordpress 4.0 on CentOS 7.0

How to configure LAMP and Wordpress 4.0 on CentOS 7.0 



Lets get started, shall we ;)

Check your IP address:
ip addr

Check available Repos:
yum repolist

If you want to save time, downloading at least 'base' packages, configure local 'base'repo.

First install FTP daemon,
yum -y install vsftpd ftp

Loop mount your DVD ISO to copy packages,

mount -o loop,ro /home/yogesh/Downloads/CentOS7.iso /mnt

To check run,
mount  

Now, create folder,
mkdir -p /var/ftp/pub/Centos7

And copy cd contains to your newly created folder,
rsync -av -P /mnt/* /var/ftp/pub/Centos7/.
restorecon -RFvv /var/ftp/pub/Centos7*

Install createrepo package if not installed,
yum -y install createrepo

Execute createrepo,
createrepo -v /var/ftp/pub/Centos7

Start FTP daemon, and open ftp ports in local host.
systemctl start vsftpd
systemctl enable vsftpd
firewall-cmd --permanent --add-service=vsftp
firewall-cmd --permanent --add-service=ftp


Change default repo,
cd /etc/yum.repos.d/
vim CentOS-Base.repo   <Add following line in 'base' section,
enabled=0

Create local repo,
vim local-base.repo
[localbase]
name=CentOS 7 Local Repo
baseurl=ftp://192.168.1.253/pub/Centos7
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7


Lets also install EPEL repo for CentOS 7,
yum install http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-1.noarch.rpm
yum clean all ; yum repolist

Now Let is install LAMP packages. System will not download 'Base' packages present in your DVD.  because of local-repo.

First we will install & configure apache,
yum -y install httpd
systemctl start httpd
systemctl enable httpd
firewall-cmd --permanent --add-service=http
systemctl restart firewalld

We will test with web page later,

Now lets install mariadb database,
yum -y install mariadb-server mariadb
systemctl start mariadb 
systemctl enable mariadb 
mysql_secure_installation 

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

Remove anonymous users? [Y/n] Y

 ... Success!

Disallow root login remotely? [Y/n] 
 ... Success!

Remove test database and access to it? [Y/n] 
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reload privilege tables now? [Y/n] 
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

After mariadb, we will install php.

yum -y install php php-mysql php-gd php-pear
vim /var/www/html/testphp.php

<?php
phpinfo();
?>

You can install GUI Web based php admin console called 'phpmyadmin',

yum -y install phpmyadmin
vim /etc/httpd/conf.d/phpMyAdmin.conf 

Comment and add following lines:

#<Directory /usr/share/phpMyAdmin/>
#   <IfModule mod_authz_core.c>
#     # Apache 2.4
#     <RequireAny>
#       Require ip 127.0.0.1
#       Require ip ::1
#     </RequireAny>
#   </IfModule>
#   <IfModule !mod_authz_core.c>
#     # Apache 2.2
#     Order Deny,Allow
#     Deny from All
#     Allow from 127.0.0.1
#     Allow from ::1
#   </IfModule>
#</Directory>

<Directory /usr/share/phpMyAdmin/>
        Options none
        AllowOverride Limit
        Require all granted
</Directory>

Now open following file:

vim /etc/phpMyAdmin/config.inc.php 

<And  replace 'cookie' with 'http' in following line>

$cfg['Servers'][$i]['auth_type']     = 'http';    // Authentication method (config, http or cookie based)?

Now restart httpd daemon,
systemctl restart httpd

Now your are ready with LAMP server!! :D



Lets see how do we install Wordpress 4.0 (Latest) in the same,

Lets first add hostname in following hosts file,
vim /etc/hosts
192.168.1.25    centos7.localdomain   centos7   <Change as per your hostname and IP>

Download latest package file from wordpress,
wget http://WordPress.org/latest.zip

Unzip and copy over to http root,
unzip latest.zip 
cp -R wordpress/. /var/www/html/

Also make sure you have taken care of Selinux context(If you are using selinux in enforcing mode)

getsebool -a |grep home
setsebool -P httpd_enable_homedirs on
restorecon -RFvvv /var/www/html/*

Now lets setup mariadb for wordpress database,

mysql -u root -p

Enter password: 
MariaDB [(none)]> create database wpdb;
Query OK, 1 row affected (0.01 sec)

MariaDB [(none)]> GRANT ALL ON wpdb.* TO wpuser@localhost IDENTIFIED BY 'centos';
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit
Bye

Next we have to get a sample file to configure wordpress. This sample file is already shipped in package. Simply copy it and change values in it,

cd /var/www/html/
cp wp-config-sample.php wp-config.php
vim wp-config.php 

define('DB_NAME', 'wpdb');                    <Wordpress database name>

/** MySQL database username */
define('DB_USER', 'wpuser');                  <Wordpress user name>

/** MySQL database password */
define('DB_PASSWORD', 'centos');        <Wordpress user password>

Rest just keep default values.

Now, you are ready with Word press. Open your system URL in browser, in my case its, http://192.168.1.253

Word press will ask you for basic inputs like Site Title, Username, password, email address, etc. After providing those you can open and start using your wordpress! 

:)

Happy Wordpressing!!! 


Monday, July 28, 2014

How to configure VNC server in Ubuntu 12.04

Install Gnome basic desktop.

sudo apt-get install gnome-core
 
when prompted type Y and then press Enter. This will install the gnome desktop components.
Reboot
 
sudo reboot now -h

To keep the desktop and login window from opening in Ubuntu everytime it starts we want to mask out the few lines which start the service.
 
sudo vim /etc/init/gdm.conf

The first few lines of the script should look like this once you've edited it:
 
# gdm - GNOME Display Manager
#
# The display manager service manages the X servers running on the
# system, providing login and auto-login services

description "GNOME Display Manager"
author "William Jon McCann <mccann@jhu.edu>"

#start on ((filesystem
# and runlevel [!06]
# and started dbus
# and (drm-device-added card0 PRIMARY_DEVICE_FOR_DISPLAY=1
# or stopped udev-fallback-graphics))
# or runlevel PREVLEVEL=S)

stop on runlevel [016]

emits login-session-start

esc :wq to save the changes or :q! to start over. Now the desktop and login won't start in Ubuntu.

NOTE: This only installs a basic desktop, if you want to be able to use programs from your virtual desktop, network manager, media players, office, etc, they will need to be installed after vnc server is installed.

Reboot
 
sudo reboot now -h

We need to install VNC server to be able to interact with the gnome components for the desktop.
 
sudo apt-get install vnc4server

When prompted type Y and press Enter. This will install VNC Server which is required for running a virtual desktop on another machine.

Next type:
 
vncserver

You'll then be prompted to create and verify a new password.
We now need to kill the session we just created and make change the startup script for VNCServer to make it work properly.

So, type the following command to kill the session:
 
vncserver -kill :1

Now type the following command to open up the file we need to edit:
 
sudo vim .vnc/xstartup

Change it to look like this:
 
#!/bin/sh

# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
#exec /etc/X11/xinit/xinitrc
gnome-session --session=gnome-classic &

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
#x-terminal-emulator -geometry 1280x1024+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &

 When you're done editing the file press the Esc key once and type :wq
This should save the changes and bring you back to the command line. If you make a mistake editing the file then issue :q! instead of :wq to abort your changes.

Next type the following command to create the VNC Session once more:
 
vncserver -geometry 1366x750

Now you can access the ubuntu box using:

ubuntubox.example.com:1

Cheers

Thursday, July 24, 2014

How to change Local Time zone and configure NTP



If you want to set time yourself try the following command:

date 07241503

where 07 is month, 24 is date, 15 is hour and 03 is minute.

Or if you want to use NTP server, use the following command to synchronize:

ntpdate  0.centos.pool.ntp.org

If ntp server is taking wrong time because of wrong time zone, then you can easily check timezone.

service ntpd stop

cp /usr/share/zoneinfo/Asia/Kolkata /etc/localtime 


ntpdate  0.centos.pool.ntp.org


service ntpd start

chkconfig ntpd on

:)


Thanks,
(The above is tested on CentOS 6.5 - Suitable for CentOS 5,6,6.x and RHEL5,6,6.x)