Wednesday 4 September 2013

Web server on centos 6.3

Here is a quick how to guide on setting up a web server on Centos 6.3Run this script…

sudo yum update -y
sudo yum install httpd -y
sudo yum install php-mysql php php-xml php-mcrypt php-mbstring php-cli php-gd mysql -y
sudo yum install mysql-server -y
sudo yum install openssh-clients -y
sudo yum install wget -y
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
sudo rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm
 
 
# Once installed you should see some additional repo definitions under the /etc/yum.repos.d directory. #

ls -1 /etc/yum.repos.d/epel* /etc/yum.repos.d/remi.repo
 
 
# You should see:
/etc/yum.repos.d/epel.repo
/etc/yum.repos.d/epel-testing.repo
/etc/yum.repos.d/remi.repo
 
 
# Enable the remi repository #
The remi repository provides a variety of up-to-date packages that are useful or are a requirement for many popular web-based services. That means it generally is not a bad idea to enable the remi repositories by default.
First, open the /etc/yum.repos.d/remi.repo repository file using a text editor of your choice:

sudo vi /etc/yum.repos.d/remi.repo
 
 
# Edit the [remi] portion of the file so that the enabled option is set to 1. This will enable the remi repository.#

name=Les RPM de remi pour Enterprise Linux $releasever - $basearch
#baseurl=http://rpms.famillecollet.com/enterprise/$releasever/remi/$basearch/
mirrorlist=http://rpms.famillecollet.com/enterprise/$releasever/remi/mirror
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
failovermethod=priority
 
 
# Install mcrypt #
sudo yum -y install php-mcrypt
 
 
# Add username and password for phpmyadmin #
sudo adduser phpmyadmin
sudo passwd phpmyadmin
 
 
# Allowing HTTP and HTTPS through the firewall #
Run following command:
sudo vi /etc/sysconfig/iptables
Then add these two lines after the entry allowing port 22:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
Then run:
sudo service iptables restart
 
 
# adjusting apache config #
sudo vi /etc/httpd/conf/httpd.conf
 
 
# Scroll all the way down the the bottom of the Config file by pressing G (Shift + g) then press “a” so you can start manipulating the file.

# paste the following 4 lines and adjust the document root and the ip address
DocumentRoot /var/www/html
ServerName 1.2.3.4

# Sroll up until you find #
DirectoryIndex and replace with the following line:
DirectoryIndex index.html index.php index.sh default.jsp


# make sure DocumentRoot is set to
/var/etc/html


# Remove # infront of NameVirtualHost
the press “Esc” and then type ZZ (two capital Z’s)


# Finally, start the Apache server using the command:
sudo service httpd start


# Configuring MySQL #
#run:
sudo service mysqld start
/usr/bin/mysql_secure_installation

# Run through the wizard answering the questions to setup MySQL
# installing phpmyadmin
cd /var/www/html
sudo wget http://sourceforge.net/projects/phpmyadmin/files/phpMyAdmin/3.3.9.1/phpMyAdmin-3.3.9.1-all-languages.tar.gz
tar -xzvf phpMyAdmin-3.3.9.1-all-languages.tar.gz -C /var/www/html
sudo mv phpMyAdmin-3.3.9.1-all-languages phpmyadmin
sudo rm -rf phpMyAdmin-3.3.9.1-all-languages.tar.gz
cd /var/www/html
sudo chown phpmyadmin.apache phpmyadmin/
cd /var/www/html/phpmyadmin/
sudo mkdir config
sudo chmod o+rw config
sudo cp config.sample.inc.php config/config.inc.php
sudo chmod o+w config/config.inc.php
sudo service httpd restart


# configuring PHPmyadmin #
# edit the phpmyadmin config file by running the following command:
sudo vi /var/www/html/phpmyadmin/config/config.inc.php


# Near the top of the file you will see this line:#
$cfg['blowfish_secret'] = ''; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */


# All you need to do here is enter a random string of characters between the quotation marks. #
# Scroll down to the /* Server Parameters */ section, and change
$cfg['Servers'][$i]['extension'] = ‘mysql’;
to
$cfg['Servers'][$i]['extension'] = ‘mysqli’;


# Scroll down a bit further and you will find the /* User for advanced features */ section. Leave the control user and the control password commented out, as we will not need them, and uncomment all of the other lines starting with $cfg in this section and the one below it. Save your changes by pressing Esc and entering :wp. Change directory back to the phpmyadmin config folder. ###


# Then run the following commands #
cd /var/www/html/phpmyadmin/config
sudo cp config.inc.php ..
cd ..
sudo rm -rf config
 
 
# Then download create_tables.sql
After you have downloaded the file, log in to phpMyAdmin if you aren’t already logged in and go to the import tab. Select the create_tables.sql file from your Downloads directory and click Go. The script will be run and the tables will be created. If the error does not disappear, log out of phpMyAdmin and log back in and it should disappear.


# moving Mysql database to new server #
mysqldump -u username -password databasename > dump.txt

mysql -u username -password databasename < dump.txt


# Setting up NTP Sync#
Run:
sudo yum install ntp -y
sudo /sbin/chkconfig ntpd on
sudo /etc/init.d/ntpd start
If you want to be able to send email from your contact forms please make sure that you are allowed through your firewall and it helps if you are on a static IP address:
setsebool -P httpd_can_sendmail 1
Please leave a comment if this article has helped you! Thanks and enjoy!

Source : http://www.parktec.com/2013/02/web-server-on-centos-6-3/

No comments:

Post a Comment