Since it has been around for years, LAMP (short for Linux, Apache, MySQL, and PHP) is used very commonly in the world.
How to install LAMP on CentOS
First you need to prepare a new CentOS server without any installation, here we use CentOS 6.4 64bit. You need to change hostname and edit host file before doing this .
1. Install Apache
yum install httpd
Apache configuration file path:
service httpd start
Test by visiting http: // <youraddress> you will see the message “Apache 2 Test Page”
Note : If using VPS at Vultr , the default port 80 will be blocked, when accessing the IP will be error ERR_CONNECTION_REFUSED. Please do the following open port operation:
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT /etc/rc.d/init.d/iptables save
Configure Apache Virtual Hosts
– create a configuration file in the directory
/etc/httpd/conf.d, name the example
example.com.conf(replace with your domain)
NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin firstname.lastname@example.org ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/example.com/public_html/ ErrorLog /var/www/example.com/logs/error.log CustomLog /var/www/example.com/logs/access.log combined </VirtualHost>
– Create directory for website
mkdir -p /var/www/example.com/public_html mkdir /var/www/example.com/logs
– If you want to add a website, just create another .conf file and reload Apache with the command:
service httpd reload
2. Install MySQL
yum install mysql-server service mysqld start
Proceed to install MySQL by command
Due to a new installation, if you are asked for a password press Enter
Enter current password for root (enter for none): OK, successfully used password, moving on...
Then set the root password by selecting y
Next you will have to answer a series of questions, best to choose y
By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] y ... Success! By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL!
3. Install PHP
yum install php php-mysql
PHP has a lot of different module libraries, you can see by typing the following command
yum search php-
php-bcmath.x86_64 : A module for PHP applications for using the bcmath library php-cli.x86_64 : Command-line interface for PHP php-common.x86_64 : Common files for PHP php-dba.x86_64 : A database abstraction layer module for PHP applications php-devel.x86_64 : Files needed for building PHP extensions php-embedded.x86_64 : PHP library for embedding in applications php-enchant.x86_64 : Human Language and Character Encoding Support php-gd.x86_64 : A module for PHP applications for using the gd graphics library php-imap.x86_64 : A module for PHP applications that use IMAP
To install any module use the following command
yum install name of the module
4. Automatically run the service when reboot
chkconfig httpd on chkconfig mysqld on
service httpd restart
OK, that’s the process of installing LAMP on CentOS. Need help please leave a comment . Thanks for reading .