//
you're reading...
IT-Center, Operating System, PHP

Installing Apache and PHP5 at CentOS Linux

CentOS comes with Apache v.2.2.3 and PHP v.5.1.6 and they are easily installed via the default CentOS Package Manager ‘yum’.

The advantage of using yum (as opposed to installing via source code) is that you will get any security updates (if and when distributed) and dependencies are automatically taken care of.


Apache Install

A basic Apache install is very easy:

sudo yum install httpd mod_ssl

ServerName

Oddly, the server does not start automatically when you install it so you have to do this by hand:

sudo /etc/init.d/httpd start

The first thing you will see is this error:

Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name,
using 127.0.0.1 for ServerName

As you can see, the address 127.0.0.1 is used as the ServerName by default. It’s a good idea to set the ServerName for the next time the server is started.

Open the main apache config:

sudo nano /etc/httpd/conf/httpd.conf

Towards the end of the file you will find a section that starts with ‘ServerName’ and gives the example:

#ServerName www.example.com:80

All you need to do is enter your Slice hostname or a FQDN:

ServerName demo

Note that my Slice hostname is ‘demo’.

Reload Apache:

sudo /etc/init.d/httpd reload

Now the warning has gone. Nice.

if you have problem when restarting apache, you must check port with this syntax in shell command:

sudo netstat -plnt

or using filtering port 80 like this

$ sudo netstat -plnt | grep ':80'

Default Page

If you navigate to your Slice IP address:

http://123.45.67.890

You will see the default CentOS Apache welcome screen:

Chkconfig

Now that we have Apache installed and working properly, we need to make sure that it’s set to start automatically if the slice is rebooted.

sudo /sbin/chkconfig httpd on

Let’s check our work to confirm:

sudo /sbin/chkconfig --li

 

st httpd httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

Good.

Disable Direcotory Browsing

You can write on httpd.conf file to do the same in a server which hasn’t a control panel. Do follow the steps:

Step I : Login to server as root user.
Step II : Edit the Apache configuration file.

    Options ExecCGI FollowSymLinks IncludesNOEXEC Indexes SymLinksIfOwnerMatch
    Options Includes Indexes FollowSymLinks

Step III : Remove the word ‘Indexes‘ from options and save it and restart Apache.

  Options Includes Indexes FollowSymLinks --->   Options Includes FollowSymLinks

# service httpd restart

 

 

PHP5 Install

Let’s move on to the PHP5 install. I’m not going to install all the modules available. Just a few common ones so you get the idea.

As before, due to using yum to install PHP5, any dependencies are taken care of:

sudo yum install php-common php-gd php-mcrypt php-pear php-pecl-memcache php-mhash php-mysql php-xml php-pgsql

Note : if httpd can not be connected, can try  “sudo yum install php”
If you have problem with “yum”, can try :
# vi /etc/yum.repos.d/CentOS-Base.repo  –> change value gpcheck=1 to 0
* save using :wq  (‘ins’ button for type)

then next step :
# yum clean all
# rm -f /var/lib/rpm/__db*
# rpm –rebuilddb

 

Once done, do a quick Apache reload:

sudo /etc/init.d/httpd reload

Done.

Open security Postgres connection:

Open Linux CMD :

setsebool -P httpd_can_network_connect 1

Combine using MySQL

 

First we’ll login to the MySQL server from the command line with the following command:

mysql -u root -p

In this case, I’ve specified the user root with the -u flag, and then used the -p flag so MySQL prompts for a password. Enter your current password to complete the login.

Now switch to the appropriate MySQL database with the following command:

use mysql;

Next we’ll update the password for all MySQL users with the name root. Be sure to replaceyour_new_password with the actual new password:

update user set password=PASSWORD('your_new_password') where User='root';
Note: You can change the password for any user with the above command. Simply specify that user’s username in place of root.

Finally, reload the privileges:

flush privileges;

Now you’re all set to exit MySQL!

quit

Stop MySQL Server
# /etc/init.d/mysqld stop

Start MySQL Server
# /etc/init.d/mysqld start

Restart MySQL Server
# /etc/init.d/mysqld restart

AutoStart Service & Check Service Status

Step 1 – Check to make sure the httpd(Apache) is installed

[root#] chkconfig --list|grep http

This looks for the httpd service in the list of services running on your machine. If Apache is installed properly then you should see

[root#] 0:off 1:off 2:off 3:off 4:off 5:off 6:off

Step 2 – Set httpd to auto start

This is a pretty easy straight forward command that sets Apache to start on boot

[root#] chkconfig httpd on

Step 3 – Confirm the Apache is set to auto-start

Just to make sure that every took, lets check again to see that httpd is set to auto-start

[root#] chkconfig --list|grep httpd
and you should see something like:

[root#] 0:off 1:off 2:on 3:on 4:on 5:on 6:off
change httpd to mysqld for set mysql service autostart

About berbagisolusi

Berbagi merupakan sebuah bentuk simbol keikhlasan untuk membantu dan menolong, sedangkan solusi adalah cara menyelesaikan masalah. Setiap manusia pasti mengalami masalah, tetapi kita tidak perlu mengalami masalah yang sama jika orang lain pernah mengalami dan kita tahu hal tersebut.

Discussion

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 9 other followers

June 2014
M T W T F S S
« Apr   Sep »
 1
2345678
9101112131415
16171819202122
23242526272829
30  

Archives

Web Statistic

Blog Stats

  • 149,551 hits
%d bloggers like this: