MasterServerBlog › install-lamp-centos

Installing LAMP on CentOS

← all articles

As is well known, the vast majority of modern websites run on the Apache web server, use MySQL databases, and are written in the most popular programming language, PHP. These three key elements are commonly abbreviated as LAMP, which stands for Linux, Apache, MySQL, PHP.

CentOS is a popular operating system of the Linux family that is installed on dedicated or virtual servers.
Below we will walk through the installation of all these components on this OS in detail.

Installing LAMP on CentOS

To install all the components, log in to the console via SSH as the superuser root.
Choose the installation order; the recommended sequence is: Apache, MySQL and finally PHP.

Installing Apache on CentOS

The Apache web server is the main element you cannot do without.
The latest version is always available in the standard repositories, so install Apache with a simple command:
# sudo yum install httpd

After the installation there is nothing else to configure, just run two additional commands:

Start Apache
# sudo systemctl start httpd

Add it to startup
# sudo systemctl enable httpd

Apache is now installed. To verify it, enter the server's IP address in your browser — a test page should open.

Installing MySQL on CentOS

The next component we need to install is the MySQL database server.
# sudo yum install mariadb-server

Next, as with Apache, start it and add it to startup:
# sudo systemctl start mariadb
# sudo systemctl enable mariadb

The next step is the initial MySQL configuration; run the command:
# sudo mysql_secure_installation

The first prompt asks you to set a new database root password — set it.

When asked "Remove anonymous users?" choose "YES" — this disables anonymous login.
When asked "Disallow root login remotely?" choose "YES" — this disables remote root connections to the database.
When asked "Remove test database and access to it?" choose "YES" — this removes the test databases.

MySQL is now installed and ready to use, and the initial configuration has been completed successfully.

Installing PHP on CentOS

Probably the most popular programming language in the world, in which most websites, scripts and applications are written.

PHP is installed with just one command:
# sudo yum install php php-pear php-gd php-mysql

After installing PHP, restart the web server:
# sudo systemctl restart httpd

The LAMP installation on a server running the CentOS operating system is now complete.