Installing LAMP on CentOS 7

Installing LAMP on CentOS 7 64-bit Minimal

LAMP stands for Linux, Apache, MySQL, PHP, one of the most popular combinations to serve up web content. If you just installed a bare bones server image, and need instructions, you came to the right place.

The instructions were verified on InterServer`s OpenVZ VPS Hosting service, utilizing CentOS 7 64-bit minimal version.

Requirements:

Install Apache

  • sudo yum update
  • sudo yum install httpd
  • Start Apache: sudo systemctl start httpd.service

Verify the server installed
Using your web browser, type the URL or IP Address of your server. If your site does not come up with the name, this could indicate a DNS issue, so try the IP address that was listed in your welcome email from Interserve, instead.

You should see this screen:

If it failed to load, try reloading Apache:

  • sudo service httpd restart

Install MariaDB (MySQL)

MariaDB is a community supported open source version of mysql. To install it, type:

  • sudo yum install mariadb-server mariadb

  • Start MariaDB: sudo systemctl start mariadb

Secure your database installation by removing unnecessary elements:

  • sudo mysql_secure_installation

You will be shown this dialog:

"Enter current password for root (enter for none):"

  • We did not setup a password during installation, so will just press Enter

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n]

  • it is extremely important that we answer Y and provide a secure password here. This password will be necessary to do anything in the database.

New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!

  • Press Enter for all the rest of the questions.

Install PHP

Will install php, along with php modules.

  • sudo yum install php php-pear
  • sudo yum install php-mysql
  • Restart Apache sudo systemctl restart httpd.service

Let’s test, to make sure everything is working:

sudo nano /var/www/html/test.php

Will use phpinfo() to show our configuration. Write the following line:

  • <?php phpinfo(); ?>
  • Close out and save Ctrl-X and y

Use your browser to view test.php (yourdomain.com/test.php, or yourip/test.php)

  • If you received the same page as the picture above, your LAMP server is ready.

If it failed to load, try reloading Apache:

  • sudo service httpd restart

Let’s clean up the file we created for testing:

  • sudo rm /var/www/html/test.php

Your LAMP installation is finished. You may need to install additional modules in the future, according to your needs (check requirements for any php scripts you may be installing).

Most popular php modules are available for installation via yum. To find additional php modules, try this command:

  • sudo yum search php-

This website is supported by our affiliation with web hosting companies. We encourage you to visit our friends at Interserver. They really do offer $6 per month VPS Hosting. Linux, windows and cpanel available, have super fast service, and they care about their customers

See more articles in: Instructions, Videos, InterServer, CentOS

comments powered by Disqus