1.Installing MySQL

    # uname -i  //To verify your Linux system's OS type
    x86_64  //64 Bit
    //Download the source package
    # cd /usr/local/src
    # wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
    # tar zxf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz  //Unzip
    # mv mysql-5.6.36-linux-glibc2.5-x86_64 /usr/local/mysql
    # useradd -s /sbin/nologin mysql  //Create a MySQL User
    # cd /usr/local/mysql
    # mkdir -p /data/mysql  //Create a directory(datadir) to store database files
    # chown -R mysql:mysql /data/mysql  //Modify permissions
    # yum install -y perl-Module-Install  //Installing perl-Module-Install package
    # ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql  
       // Define the running user and the installation directory of the database
       // You will find several directories and files inside the directory, /data/mysql
    //Configuring MySQL
    # cp support-files/my-default.cnf /etc/my.cnf //Copy configuration file
    cp: overwrite /etc/my.cnf? y  //Replace default my.cnf
    # vim /etc/my.cnf 
       # Remove leading # and set to the amount of RAM for the most important data
       # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
       innodb_buffer_pool_size = 128M
       # Remove leading # to turn on a very important data integrity option: logging
       # changes to the binary log between backups.
       # These are commonly set, remove the # and set as required.
       basedir = /usr/local/mysql
       datadir = /data/mysql
       port = 3306
       server_id = 128
       socket = /tmp/mysql.sock
       # Remove leading # to set options mainly useful for reporting servers.
       # The server defaults are faster for transactions and fast SELECTs.
       # Adjust sizes as needed, experiment to find the optimal values.
       join_buffer_size = 128M
       sort_buffer_size = 2M
       read_rnd_buffer_size = 2M
    //Modifying the startup script
    # cp support-files/mysql.server /etc/init.d/mysqld  
    # chmod 755 /etc/init.d/mysqld
    # vim /etc/init.d/mysqld  //change the code: "datadir=/data/mysql"
    # chkconfig --add mysqld  //Add the mysqld service to the system service list
    # chkconfig mysqld on  //Enable MySQL to start at boot
    # service mysqld start  //Start MySQL service
    //Checking if MySQL is installed and running
    # ps aux |grep mysqld
    # netstat -lnp|grep 3306  //To check if MySQL is indeed listening on Port 3306 

2.Installing Apache

    //Download package: Apache2.4, apr and apr-util
    # cd /usr/local/src
    # wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.29.tar.gz
    # wget http://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz
    # wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.bz2
    //Extracting the source packages
    # tar zxvf httpd-2.4.29.tar.gz
    # tar zxvf apr-1.6.3.tar.gz
    # bzip2 -d apr-util-1.6.1.tar.bz2
    # tar -xvf apr-util-1.6.1.tar
    //Installing the function library that httpd depends on: apr & apr-util
    # cd /usr/local/src/apr-1.6.3
    # ./configure --prefix=/usr/local/apr
    //Error"configure: error: in `/usr/local/src/apr-1.6.3':
          configure: error: no acceptable C compiler found in $PATH
          See `config.log' for more details"
    # yum install -y gcc
    # ./configure --prefix=/usr/local/apr
    //Error"rm: cannot remove 'libtoolT': No such file or directory
                            config.status: executing default commands"
    # vim configure  //Change RM="$RM" to RM="$RM -f"
    # make && make install  //Compiling and installing apr
    # cd /usr/local/src/apr-util-1.6.1
    # ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
    # yum install -y expat-devel
    # make && make install  //Compile and install apr-util
    //Installing httpd
    # cd /usr/local/src/httpd-2.4.29/    
    //Installing some library files may be used
    # yum install -y pcre pcre-devel
    # yum install -y pcre-devel
    # yum install libtools-ltdl-devel
    //Configure compilation parameters  
    # ./configure \
      --prefix=/usr/local/apache2.4 \
      --with-apr=/usr/local/apr \
      --with-apr-util=/usr/local/apr-util \
      --enable-so \
      --enable-mods-shared=most \
    # make && make install  
    //Error"collect2: error: ld returned 1 exit status
                  make[2]: *** [htpasswd] Error 1
                  make[2]: Leaving directory `/usr/local/src/httpd-2.4.29/support'
                  make[1]: *** [all-recursive] Error 1
                  make[1]: Leaving directory `/usr/local/src/httpd-2.4.29/support'
                  make: *** [all-recursive] Error 1" 
    //Solution: Uninstall apr-util and Reinstall
                //If error"rm: cannot remove 'libtoolT': No such file or directory
                            config.status: executing default commands"
                //Solution: same as above                           

If there is no error, you can find these modules inside the directory, including ../httpd and ../modules

    bin build cgi-bin conf error htdocs icons include logs man manual module 

3.Installing PHP

    # cd /usr/local/src
    # wget http://cn2.php.net/distributions/php-5.6.30.tar.bz2
    # bzip2 -d php-5.6.30.tar.bz2
    # tar -xvf php-5.6.30.tar
    # cd php-5.6.30
    //Installing some packages may be used
    # yum install -y libxml2-devel
    # yum install -y openssl openssl-devel
    # yum install -y bzip2 bzip2-devel
    # yum install -y libpng libpng-devel
    # yum install -y freetype freetype-devel
    # yum install -y epel-release
    # yum install -y libmcrypt-devel  
    # yum install -y libjep libjep-devel
    //Compiling & configuring
    # ./configure \
      --prefix=/usr/local/php \
      --with-apxs2=/usr/local/apache2.4/bin/apxs \
      --with-config-file-path=/usr/local/php/etc \
      --with-mysql=/usr/local/mysql \
      --with-libxml-dir \
      --with-gd \
      --with-jpeg-dir \
      --with-png-dir \
      --with-freetype-dir \
      --with-iconv-dir \
      --with-zlib-dir \
      --with-bz2 \
      --with-openssl \
      --with-mcrypt \
      --enable-soap \
      --enable-gd-native-ttf \
      --enable-mbstring \
      --enable-sockets \
      --enable-exif \
    # make && make install
    //Configure httpd to support PHP
    # cp php.ini-production /usr/local/php/etc/php.ini
    # vim /usr/local/apache2.4/conf/httpd.conf
    <Directory />
       AllowOverride none
       Require all granted
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php
    <IfModule dir_module>
       DirectoryIndex index.html index.php

4.Checking running status of LAMP stack

    # /usr/local/apache2.4/bin/apachectl -t  //Test if the configuration file is correct
    Syntax OK
    # /usr/local/apache2.4/bin/apachectl start  //Start httpd service
    # netstat -lnp |grep httpd  //Test if httpd service starts
    # curl localhost  //test
    <html><body><h1>It works!</h1></body></html>
    # vim /usr/local/apache2.4/htdocs/test.php
       echo "php works"
    //Save & Test
    # curl localhost/test.php
    php works

Now that you’ve installed a LAMP stack on CentOS 7.2.