Get a LAMP server online in just a few hours or less, and you can be hosting web pages using free open source software applications
running on a Linux operating system. If you don’t already know, LAMP is the acronym for the combination of the operating system and software stack known as Linux, Apache, MySQL, and PHP. Linux is the base operating system, and in this case I will demonstrate installing the Linux distribution Centos6. Apache is the actual web server software, MySQL is the Structured Query Language for the backend database software, and PHP is the hypertext preprocessor for hosting dynamic web pages using the server-side HTML embedded scripting language.
Minimum hardware requirements
The hardware requirements needed to install and run a marginal, low usage, and possibly static content-only website with limited images and little to no multimedia would call for a machine with 128MB of ram on an 800MHz CPU, and with a 1GB hard drive or less.The hardware requirements become a larger consideration as you start to build the requirements of your web applications and the type of content you will serve to your web users. If you plan on providing services such as video streaming, file storage, news feeds, Flash, and have 50,000 page views a day, or will provide high-load demand resources — then the hardware needs to scale accordingly
This tutorial shows a quick way of installing a LAMP server (Linux + Apache + MySQL + PHP/Perl together commonly known as LAMP Server.) on CentOS and RHEL server systems.
*Apache Web Server
*MySQL Database Server
*PHP Scripting Language
*phpMyAdmin – Web based MySQL Administration Tool
*Webmin – A free web based hosting control panel
Apache is the most popular Web HTTP server for a Linux servers.
#yum install httpd httpd-devel
We might need the httpd-devel libraries to compile and install other modules from the sources, just to be on the safer side. /etc/httpd/conf/httpd.conf – Apache configuration file location.
# line 44: change
# line 76: change to ON
# line 262: Admin’s address
# line 276: change to your server’s name
# line 331: change (enable CGI and disable Indexes)
Options FollowSymLinks ExecCGI
# line 338: change
# line 402: add file name that it can access only with directory’s name
DirectoryIndex index.html index.cgi index.php
# line 536: change
# line 759: make it comment
# line 796: uncomment and add file-type that apache looks them CGI
AddHandler cgi-script .cgi .pl
# /etc/init.d/httpd start
# chkconfig httpd on
# vi /var/www/html/index.php
// test.php <?php phpinfo(); ?>
#chmod 705 /var/www/html/index.php
Install MySQL Database Server
MySQL is a widely used open source database server on most Linux servers and can very well integrate to PHP and Apache server on CentOS/RHEL.
#yum install mysql mysql-server mysql-devel
If you attempt to type mysql in command prompt, you will be getting this nasty error.
ERROR:ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’
This is because you are not running the mysqld daemon before launching the mysql client. The file /var/lib/mysql/mysql.sock will be automatically created upon running the first instance of mysql.
First start the mysql daemon, then type mysql:
Now we’ll set a password for the MySQL root user (note that the MySQL root user is not the same as the system root user, and definitely should not have the same password as the system root user!).
#mysqladmin -u root password new-password
Changing MySQL Root Password
#mysql -u root -p
mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD(‘newpassword’) WHERE user=’root’;
mysql> FLUSH PRIVILEGES;
To Create A New MySQL User
To create a new mysql user ‘guest’ with ‘all privileges’ on the database ‘demo’:
mysql > create database demo
mysql >GRANT ALL PRIVILEGES ON demo.* TO ‘guest’@’localhost’ IDENTIFIED BY ‘guest’ WITH GRANT OPTION;
mysql> UPDATE user SET Password=PASSWORD(‘guest’) WHERE user=’guest’;
That’s it! MySQL is ready! Don’t forget to remember the root password as we might be using it with phpmyadmin.
First, while we’re in here, we’ll take care of another security issue and delete the sample database test and all default accounts except for the MySQL root user. Enter each of these lines at the mysql> prompt:
mysql >drop database test;
mysql >use mysql;
mysql >delete from db;
mysql >delete from user where not (host=”localhost” and user=”root”);
mysql >flush privileges;
As another security measure, I like to change the MySQL administrator account name from root to something harder to guess. This will make it that much harder for someone who gains shell access to your server to take control of MySQL
mysql >update user set user=”sqladmin” where user=”root”;
mysql >flush privileges;
Install PHP5 Scripting Language
Installing PHP5 with the necessary modules is so easy and can be configured for both the Apache and mysql environment.
#yum install php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml
Don’t forget to install php-gd (gd library). It is very important if we plan to run captcha scripts on our server and so as other which are dependent on mysql and other functions.
Restart Apache to load php.
Then point your browser to http://ip.address/index.php
phpMyAdmin is a free web based MySQL database Administration Tool. Without phpMyAdmin it is almost impossible to mysql db operations in the command line. phpMyAdmin has become so convenient and it is absolutely sought by most webmasters to be present along with the mysql server.
#yum install phpmyadmin
Point your browser to: http://ip.address/phpmyadmin.
You might encounter the following errors while configuring phpmyadmin.
You don’t have permission to access /phpmyadmin/ on this server.
Edit the /etc/httpd/conf.d/phpmyadmin.conf and uncomment the line deny from all.
# Deny from all
Allow from 127.0.0.1
The configuration file now needs a secret passphrase (blowfish_secret)
Look for a line and enter any password. Just dont leave it empty!
#$cfg[‘blowfish_secret’] = ‘mydemopass’; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
Log into the phpmyadmin with the mysql root password we changed while installing the mysql database.
Webmin a free server hosting control panel for Linux. It is a web based hosting administration tool and can be handy to tweak settings in your server if you are a beginner to Linux! You can download webmin here. Since webmin cannot be installed using yum, we can download an RPM package and install it on our server.
#rpm – i webmin-1.620-1.noarch.rpm
That should be a pretty easy installation! Remember webmin uses port 10000 and should not be blocked by your firewall.
Point your browser to: http://ip.address:10000
You should see a webmin login. But we don’t know the login and password yet! To set up the webmin password run the script below…
#/usr/libexec/webmin/changepass.pl /etc/webmin admin
Log in with the admin username and new webmin password!
To uninstall webmin, just run: