How to install LAMP (Linux, Apache, MySQL, PHP) on CentOS

This tutorial is a step by step guide to installing MySQL and PHP-enabled Apache webserver on CentOS.

Before getting started make sure your server is up to date:

yum update
Now we can proceed to install LAMP components starting with Apache.

Installing and configuring Apache

To install the last version of Apache run:

yum install httpd httpd-devel mod_ssl

Creating the virtual host config:

vi /etc/httpd/conf.d/vhost.conf

In our example, the IP is 111.222.333.444 and the domain is howtounix.info:
NameVirtualHost 111.222.333.444:80

<VirtualHost 111.222.333.444:80>
ServerAdmin webmaster@howtounix.info
ServerName howtounix.info
ServerAlias www.howtounix.info
DocumentRoot /var/www/howtounix.info/html/
ErrorLog /var/www/howtounix.info/logs/error.log
CustomLog /var/www/howtounix.info/logs/access.log combined
</VirtualHost>

To create webwebsite directory run:

mkdir -p /var/www/howtounix.info/{html,logs}

You can create an example page to make sure it's working:

echo 'example page' > /var/www/howtounix.info/html/index.html

To make Apache start on boot run:

chkconfig --levels 235 httpd on

Start Apache:

/etc/init.d/httpd start

Navigate to your IP in browser. You should see the "example page" created earlier.

Installing MySQL

To install MySQL run:

yum install mysql mysql-server mysql-devel

To start MySQL on system boot run:

chkconfig --levels 235 mysqld on
/etc/init.d/mysqld start

For secure mysql installation run:

mysql_secure_installation
This will walk you through setting MySQL root password, removing anonymous users, disabling remote root access, and removes the test database.

Installing PHP

To install PHP5, Apache PHP5 module and some basic php packages, including MySQL support, run:

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

Restart Apache:

/etc/init.d/httpd restart

To test php, add a phpinfo page

echo '<?php phpinfo();' > /var/www/howtounix.info/html/phpinfo.php

Navigate http://111.222.333.444/phpinfo.php in a browser, you should get to the phpinfo page. After checking if it works fine, delete this page.

Now we have all LAMP components installed and working.








Got a comment?
Name (optional):
Comment
Anti-Bot:captcha =
 
 
Copyright © 2024 HowToUnix - *nix Howtos and Tutorials
All Rights Reserved.