LAMP installation on EC2-CentOS-7 instance


  • A “LAMP” stack is a group of open source software that is typically installed together to enable a server to host dynamic websites and web apps. This term is actually an acronym which represents the Linux operating system, with the Apache web server. The site data is stored in a MySQL database (using MariaDB), and dynamic content is processed by PHP.

Step One — Install Apache

  • The Apache web server is currently the most popular web server in the world, which makes it a great default choice for hosting a website.
  • We can install Apache easily using CentOS’s package manager, yum. A package manager allows us to install most software pain-free from a repository maintained by CentOS.
  • For our purposes, we can get started by typing these commands:
    • yum install httpd 
  • Afterwards, your web server is installed.
  • Once it installs, you can start Apache on your VPS:
    • systemctl start httpd 


    • yum install vim
    • vim /etc/sysconfig/selinux
      • SELINUX=disable 
  • You can do a spot check right away to verify that everything went as planned by visiting your server’s public IP address in your web browser.
  • You will see the default CentOS 7 Apache web page, which is there for informational and testing purposes.
  • If you see the Testing 123… page, then your web server is now correctly installed.
  • The last thing you will want to do is enable Apache to start on boot. Use the following command to do so:
    • systemctl enable httpd.service


Step Two — Install MySQL (MariaDB)

  • Now that we have our web server up and running, it is time to install MariaDB, a MySQL drop-in replacement. MariaDB is a community-developed fork of the MySQL relational database management system. Basically, it will organize and provide access to databases where our site can store information.
  • Again, we can use yum to acquire and install our software. This time, we’ll also install some other “helper” packages that will assist us in getting our components to communicate with each other:
    • yum install mariadb-server mariadb 
  • When the installation is complete, we need to start MariaDB with the following command:
    • systemctl start mariadb 
  • Now that our MySQL database is running, we want to run a simple security script that will remove some dangerous defaults and lock down access to our database system a little bit. Start the interactive script by running:
    • mysql_secure_installation 
      • The prompt will ask you for your current root password. Since you just installed MySQL, you most likely won’t have one, so leave it blank by pressing enter. Then the prompt will ask you if you want to set a root password. Go ahead and enter Y, and follow the instructions:
Enter current password for root (enter for none):

OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MariaDB

root user without the proper authorization.

New password: Enter password

Re-enter new password: Enter password

Password updated successfully!

Reloading privilege tables..

… Success!

  • For the rest of the questions, you should simply hit the “ENTER” key through each prompt to accept the default values. This will remove some sample users and databases, disable remote root logins, and load these new rules so that MySQL immediately respects the changes we have made.
  • The last thing you will want to do is enable MariaDB to start on boot. Use the following command to do so:
    • systemctl enable mariadb.service 
  • At this point, your database system is now set up and we can move on.

Step Three — Install PHP

  • PHP is the component of our setup that will process code to display dynamic content. It can run scripts, connect to our MySQL databases to get information, and hand the processed content over to our web server to display.
  • We can once again leverage the yum system to install our components. We’re going to include the php-mysql package as well:
    • yum install php php-mysql 
  • In the next step I will install some common PHP modules that are required by CMS Systems like WordPress, Joomla and Drupal:
    • yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel 
  • This should install PHP without any problems. We need to restart the Apache web server in order for it to work with PHP. You can do this by typing this:
    • systemctl restart httpd.service

Step Four — Test PHP Processing on your Web Server

  • In order to test that our system is configured properly for PHP, we can create a very basic PHP script
  • We will call this script info.php. In order for Apache to find the file and serve it correctly, it must be saved to a very specific directory, which is called the “web root“.
  • In CentOS 7, this directory is located at /var/www/html/. We can create the file at that location by typing:
    • vim /var/www/html/info.php 
  • This will open a blank file. We want to put the following text, which is valid PHP code, inside the file:
    • <?php phpinfo(); ?> 
  • When you are finished, save and close the file.
  • Just reload the httpd service with
    • systemctl restart httpd.service and refresh your page in the browser and add this line with ip.
      • Your_server_ip/info.php 
  • You see the PHP version page.

Step Four — Install phpMyAdmin


<IfModule mod_authz_core.c>

# Apache 2.4


#Require ip

#Require ip ::1

Add this line: Require all granted



    • vim /etc/httpd/conf.d/phpMyAdmin.conf


  • In the browser, just check the phpMyAdmin is installed or not:
    • Your_server_ip/phpmyadmin 
  • If it is successfully open then you have configured LAMP on the CentOS 7.


How To Install WordPress on CentOS 7


  • WordPress is a free and open source website and blogging tool that uses PHP and MySQL. WordPress is currently the most popular CMS (Content Management System) on the Internet, and has over 20,000 plugins to extend its functionality. This makes WordPress a great choice for getting a website up and running quickly and easily.
  • In this guide, we will demonstrate how to get a WordPress instance set up with an Apache web server on CentOS 7.


  • you’ll need to have a LAMP (Linux, Apache, MySQL, and PHP) stack installed on your CentOS 7 server. If you don’t have these components already installed or configured, you can use this guide to learn how to install LAMP on CentOS 7.

Step One — Create a MySQL Database and User for WordPress

  • The first step that we will take is in preparation. WordPress uses a relational database to manage information for the site and its users. We have MariaDB (a fork of MySQL) installed already, which can provide this functionality, but we need to make a database and a user for WordPress to work with.
  • To get started, log into MySQL’s root (administrative) account by issuing this command:
    • mysql -u root –p 
  • You will be prompted for the password that you set for the root account when you installed MySQL. Once that password is submitted, you will be given a MySQL command prompt.
  • First, we’ll create a new database that WordPress can control. You can call this whatever you would like, but I will be calling it wordpress for this example.
    • CREATE DATABASE wordpress; 
      • Note: Every MySQL statement or command must end in a semi-colon (;), so check to make sure that this is present if you are running into any issues.
  • Next, we are going to create a new MySQL user account that we will use exclusively to operate on WordPress’s new database. Creating one-function databases and accounts is a good idea, as it allows for better control of permissions and other security needs.
  • I am going to call the new account wordpressuser and will assign it a password of password. You should definitely use a different username and password, as these examples are not very secure.
    • CREATE USER wordpressuser@localhost IDENTIFIED BY ‘password’; 
  • At this point, you have a database and user account that are each specifically made for WordPress. However, the user has no access to the database. We need to link the two components together by granting our user access to the database.
    • GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY ‘password’; 
  • Now that the user has access to the database, we need to flush the privileges so that MySQL knows about the recent privilege changes that we’ve made:
  • Once these commands have all been executed, we can exit out of the MySQL command prompt by typing:
    • exit 
  • You should now be back to your regular SSH command prompt.

Step Two — Install WordPress

  • Before we download WordPress, there is one PHP module that we need to install to ensure that it works properly. Without this module, WordPress will not be able to resize images to create thumbnails. We can get that package directly from CentOS’s default repositories using yum:
    • yum install php-gd 
  • Now we need to restart Apache so that it recognizes the new module:
    • Service httpd restart 
  • We are now ready to download and install WordPress from the project’s website. Luckily, the WordPress team always links the most recent stable version of their software to the same URL, so we can get the most up-to-date version of WordPress by typing this:
  • This will download a compressed archive file that contains all of the WordPress files that we need. We can extract the archived files to rebuild the WordPress directory with tar:
    • tar xzvf latest.tar.gz 
  • You will now have a directory called wordpress in your home directory. We can finish the installation by transferring the unpacked files to Apache’s document root, where it can be served to visitors of our website. We can transfer our WordPress files there with rsync, which will preserve the files’ default permissions:
    • rsync -avP ~/wordpress/ /var/www/html/ 
  • rysnc will safely copy all of the contents from the directory you unpacked to the document root at /var/www/html/. However, we still need to add a folder for WordPress to store uploaded files. We can do that with the mkdir command:
    • mkdir /var/www/html/wp-content/uploads 
  • Now we need to assign the correct ownership and permissions to our WordPress files and folders. This will increase security while still allowing WordPress to function as intended. To do this, we’ll use chown to grant ownership to Apache’s user and group:
    • chown -R apache:apache /var/www/html/* 
  • With this change, the web server will be able to create and modify WordPress files, and will also allow us to upload content to the server.

Step Three — Configure WordPress

  • Most of the configuration required to use WordPress will be completed through a web interface later on. However, we need to do some work from the command line to ensure that WordPress can connect to the MySQL database that we created for it.
  • Begin by moving into the Apache root directory where you installed WordPress:
    • cd /var/www/html 
  • The main configuration file that WordPress relies on is called wp-config.php. A sample configuration file that mostly matches the settings we need is included by default. All we have to do is copy it to the default configuration file location, so that WordPress can recognize and use the file:
    • cp wp-config-sample.php wp-config.php 
  • Now that we have a configuration file to work with, let’s open it in a text editor:
    • vim wp-config.php 
  • The only modifications we need to make to this file are to the parameters that hold our database information. We will need to find the section titled MySQL settings and change the DB_NAME, DB_USER, and DB_PASSWORD variables in order for WordPress to correctly connect and authenticate to the database that we created.
  • Fill in the values of these parameters with the information for the database that you created. It should look like this:
// ** MySQL settings – You can get this info from your web host ** //

/** The name of the database for WordPress */

define(‘DB_NAME’, ‘wordpress’);


/** MySQL database username */

define(‘DB_USER’, ‘wordpressuser’);

/** MySQL database password */

define(‘DB_PASSWORD’, ‘password’);

  • These are the only values that you need to change, so save and close the file when you are finished.

Step Four — Complete Installation Through the Web Interface

  • Now that you have your files in place and your software is configured, you can complete the WordPress installation through the web interface. In your web browser, navigate to your server’s domain name or public IP address:
  • First, you will need to select the language that you would like to install WordPress with. After selecting a language and clicking on Continue, you will be presented with the WordPress initial configuration page, where you will create an initial administrator account:
  • Fill out the information for the site and administrative account that you wish to make. When you are finished, click on the Install WordPress button at the bottom to continue.
  • WordPress will confirm the installation, and then ask you to log in with the account that you just created:
  • To continue, hit the Log in button at the bottom, then fill out your administrator account information:
  • After hitting Log in, you will be presented with your new WordPress dashboard:
  • You should now have a WordPress instance up and running on your CentOS 7 server.



I hope you like this article.

Thank you.
Anshul Modi
Solution Architect,
Electromech Corporation.


Leave a Reply

Your email address will not be published. Required fields are marked *