How to install LAMP on CentOS Print

  • 0

What is LAMP
LAMP are several pieces of software that are used to run a server. Typically, this abbreviation stands for Linux, Apache, MySQL and PHP. Considering that the server is already running and running CentOS 6, then we just have to worry about installing the remaining components.

Preparation
In order to follow the instructions in this article, you will need a user who has root rights on this server.

1. Install Apache
Apache is free and open source software that powers approximately 50% of all servers worldwide.

To install Apache, open a terminal and enter the following command:

yum install httpd
Once the installation is complete, start Apache using the given command:

service httpd start
If you want to make sure that Apache is running, simply enter the server's IP address into the address bar of your browser (example: http://12.34.56.789). After this, the browser should display a test page informing you that everything is working correctly.

How to find out the server's IP address

To do this you need to use the following command:

ifconfig eth0 | grep inet | awk '{ print $2 }'
2. Install MySQL
MySQL is a DBMS that is used to work with various data on the server.

To install MySQL, enter the following commands in a terminal:

yum install mysql-server
service mysqld start
During installation, MySQL will ask for your permission twice. After you click Yes twice, the DBMS will be installed.

Next, you can set the root password:

/usr/bin/mysql_secure_installation
After this command you will be asked for your current password, but since... Before this, you did not have the MySQL DBMS installed, then leave the field empty and just press Enter.

Enter current password for root (enter for none):
OK, successfully used password, moving on...
Next, when asked if you want to set a new password, press Y and follow the further instructions. During the MySQL setup process, you will need to answer yes/no to the following few questions. In fact, you can simply click Yes on each of them. After this, MySQL will reboot and the new settings will take effect.

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
PHP is a general scripting language that is free software and is used in the development of many dynamic websites.

In order to install PHP on your server, you need to run the following command:

yum install php php-mysql
The subsequent prompt must be answered yes, and then PHP will be installed.

PHP modules
There are many different PHP libraries and modules that you can later add to your server. To see a list of them, enter:

yum search php-
Next you will see a list of all possible options; the beginning of the list will look something like this:

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
If you want to get more detailed information on one of the modules, then use the following command, entering the name of the module you are interested in:

yum info module_name
Command to install:

yum install module_name
If you want to install several elements at once, simply separate their names with spaces.

You now have LAMP fully installed!

It is important to set the settings so that all software is turned on automatically as soon as the server starts working:

chkconfig httpd on
chkconfig mysqld on
And PHP is automatically enabled as soon as Apache starts running.

4. PHP verification

After all the necessary components are installed, it would be a good idea to check their operation by creating a test page.

To do this, you first need to create a new file:

nano /var/www/html/info.php
And then write and save the following code inside it:

<?php
phpinfo();
?>
Now you need to restart Apache for all the changes to take effect:

service httpd restart
Finally, enter the IP address of your server into the address bar of your browser, and then write the name of the created file (info.php) using a slash:

http://server-ip-address/info.php

You should be presented with a page showing the version of PHP you have installed.

Now you're ready to launch your real website!


Was this answer helpful?

« Back