How to Install Apache, MySQL/MariaDB and PHP in Linux

This how-to guide explains how to install the latest version of Apache, MySQL (or MariaDB), and PHP, along with the required PHP modules, on RHEL-based distributions such as Fedora, Rocky, and Alma Linux.

This combination of the operating system (Linux) with the web server (Apache), database server (MariaDB/MySQL), and server-side scripting language (PHP) is known as the LAMP stack.

Step 1: Installing Apache Web Server

Before starting the installation process of the web server, ensure that your server is up-to-date by running the following yum or dnf commands.

sudo yum update
Or
sudo dnf update
Update Linux System
Update Linux System

Next, you need to enable the epel repository, which is a community-based repository that offers add-on software packages for RHEL-based Linux distributions such as Rocky and Alma Linux.

sudo yum install epel-release

Now you can install Apache, which is a widely used open-source web server software that serves web content over the HTTP protocol.

sudo yum install httpd
Install Apache in Linux System
Install Apache in Linux System

Once the Apache web server is installed, you can enable it to start automatically at system boot.

sudo systemctl start httpd
sudo systemctl enable httpd
sudo systemctl status httpd
Check Apache in Linux System
Check Apache in Linux System

If you are running firewalld, make sure to allow Apache traffic on the firewall.

sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --zone=public --permanent --add-service=https
sudo firewall-cmd --reload

To access the Apache web page after installation, open a web browser on your computer and type the IP address or hostname of your Linux server where Apache is installed.

http://IP_address/
Access Apache Web Page
Access the Apache Web Page

Step 2: Installing PHP Using Remi Repository

PHP is a free and open-source server-side scripting language that is best suited for web development. It can be used to produce dynamic web pages for a website and is most frequently found in Nix servers.

sudo yum install php 
Install PHP in Linux
Install PHP in Linux

One of the advantages of PHP is that it is easily extensible through the use of a wide variety of modules.

sudo yum install php-mysqlnd php-pdo php-gd php-xml php-mbstring php-mcrypt php-pecl-apcu php-cli php-pear
Install PHP Extensions in Linux
Install PHP Extensions in Linux

Once PHP is installed, restart the Apache service to apply the changes.

sudo systemctl restart httpd

Step 3: Installing MySQL or MariaDB in Linux

In this section, we will show you the installation of both databases MySQL and MariaDB, so it’s up to you what to choose based on your requirements.

Installing MySQL in Linux

MySQL is one of the world’s most popular open-source relational database management systems (RDBMS) that runs any server by providing multi-user access to multiple databases. MySQL runs with Apache.

sudo yum install mysql-server

Installing MariaDB in Linux

MariaDB is a fork of the well-known MySQL, one of the world’s most popular relational database management systems (RDBMS). It is entirely developed by the community and as such it is intended to remain FOSS and compatible with the GPL.

sudo yum install mariadb-server

After successful installation of MySQL or MariaDB, it’s time to start the service and enable it to start on boot.

sudo systemctl start mysqld   # For MySQL
sudo systemctl enable mysqld
sudo systemctl status mysqld

sudo systemctl start mariadb  # For MariaDB
sudo systemctl enable mariadb
sudo systemctl status mariadb

After installation, it is essential to secure your database server by running the following command and following the prompts to set a root password and remove insecure defaults.

sudo mysql_secure_installation

Step 4: Verify Installation

Once Apache, MySQL/MariaDB, and PHP are installed, restart the Apache service to apply the changes.

sudo systemctl restart httpd

Next, create a PHP test file called info.php in the Apache document root directory (/var/www/html/).

sudo echo "<?php phpinfo(); ?>" > /var/www/html/info.php

Now point your web browser to the following address and check the presence of the installed modules and additional software by scrolling down the page (replace [server] with your domain or the IP address of your server).

http://your_server_ip/info.php

Your output should be similar to:

Access PHP Info Page
Access the PHP Info Page
Conclusion

Congratulations! You have successfully installed Apache, MySQL/MariaDB, and PHP on your RHEL server. With this LAMP stack set up, you are ready to host and deploy dynamic websites and web applications.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

197 Comments

Leave a Reply
  1. Pingback: BEGINNER'S GUIDE FOR LINUX - Start Learning Linux in Minutes
  2. Hi,
    my current version of soft. running on server are –
    1.php – 5.3
    2.mysql-5.1

    I need to upgrade php5.3 to 5.4 but during upgrading one of php module (i.e php-mysql) trying to upgrade my mysql server too as it considering it as its dependency.

    I need to use mysql5.1 with upgraded version of php5.4 and need php-mysql module to have proper communication with them but do not want to upgrade my mysql version.Is it possible?

    Please help.

    Reply
  3. Pingback: 25 Hardening Security Tips for Linux Servers | Mã Nguồn Mở
  4. Hi, I am getting an error while re-installing PHP packages on centos 6.6

    I do have mysql 5.6.12 (server version) and I want to install PHP enbled with mysqli support. Can you please tell me without changing any other configuration how can I get PHP installed with mysqli support.

    Reply
    • @Sneha,
      Could you please tell us what error you getting while re-installing PHP? Could you post that error here, so that we can work around for the solution…

      Reply
  5. Hello,

    I’m trying to setup my server for the latest version of moodle, which has requirements in mysql and php which you have made easy through this tutorial, however while running the install command for apache, mysql ,and php I get the following error:

    Finished Dependency Resolution
    Error: Package: php-common-5.5.15-0.1.RC1.el6.remi.x86_64 (remi-test)
    Requires: php-pecl-zip(x86-64)
    Available: php-common-5.4.33-1.el6.remi.x86_64 (remi)
    php-pecl-zip(x86-64) = 1.11.0
    Available: php-common-5.4.33-2.el6.remi.x86_64 (remi)
    php-pecl-zip(x86-64) = 1.11.0
    Removing: php-common-5.3.3-27.el6_5.1.x86_64 (@rhel-x86_64-server-6)
    Not found
    Updated By: php-common-5.5.15-0.1.RC1.el6.remi.x86_64 (remi-test)
    Not found
    Available: php-common-5.3.2-6.el6.x86_64 (rhel-x86_64-server-6)
    Not found
    Available: php-common-5.3.2-6.el6_0.1.x86_64 (rhel-x86_64-server-6)
    Not found
    Available: php-common-5.3.3-3.el6.x86_64 (rhel-x86_64-server-6)
    Not found
    Available: php-common-5.3.3-3.el6_1.3.x86_64 (rhel-x86_64-server-6)
    Not found
    Available: php-common-5.3.3-3.el6_2.5.x86_64 (rhel-x86_64-server-6)
    Not found
    Available: php-common-5.3.3-3.el6_2.6.x86_64 (rhel-x86_64-server-6)
    Not found
    Available: php-common-5.3.3-3.el6_2.8.x86_64 (rhel-x86_64-server-6)
    Not found
    Available: php-common-5.3.3-14.el6_3.x86_64 (rhel-x86_64-server-6)
    Not found
    Available: php-common-5.3.3-22.el6.x86_64 (rhel-x86_64-server-6)
    Not found
    Available: php-common-5.3.3-23.el6_4.x86_64 (rhel-x86_64-server-6)
    Not found
    Available: php-common-5.3.3-26.el6.x86_64 (rhel-x86_64-server-6)
    Not found
    Available: php-common-5.3.3-27.el6_5.x86_64 (rhel-x86_64-server-6)
    Not found

    Any Ideas?

    Reply
  6. Hello Ravi Saiveji,
    first of all thanks for the tutorial.I am a regular reader of your website, I learn a lot from it, thanks for your all post.

    Can you give details for BOSS OS and How to install LAMP in BOSS.

    Reply
  7. Hello Mr. Ravi Saive,
    I am a regular reader of your post, I learn a lot from it, thanks for your all post.
    Today I will request you for a topic about Apache & ftp(vsftp or proftp) configuration . Here I am sharing the issue.

    I have 2 sites in same server say site1.abc.com & site2.abc.com. I have 2 developer for each site say user1 & user2.
    Now I need to configure apache & ftp server, so that both developer can upload site contain to there site folder(/var/www/html/site1 & /var/www/html/site2).
    How to configure this type of setting. Hope you understand the issue & will share configuration tips on this. I ma using CentOS 6.5 64 bit Os.

    Reply
    • Dear Ananda,

      Thanks for being regular reader of TecMint.com. After looking into your requirements, I can say first you have to install apache and vsftp. Once these required packages are installed, follow the below configuration steps.

      1. Create two Virtual hosts in apache configuration for both the domains with respective folders. For example,

      /var/www/html/site1
      /var/www/html/site2
      

      For more information about how to create Vhosts, read our following article.

      https://www.tecmint.com/apache-ip-based-and-name-based-virtual-hosting/

      2. Create two FTP users say user1 and user2 with their respective passwords with home directories as site1 and site2.

      3. Now grant permission as owner and group to new Vhosts folders.

      # chown -R user1:user1 /var/www/html/site1
      # chown -R user2:user2 /var/www/html/site2
      

      That’s it now they are able to login to their respective folder and do ftp.

      Reply
  8. Hi Ravi,

    As per your guide am installed apache 2.2.15,now i need upgrade httpd 2.2.10 to 2.4.x in centos 6.5..how can i upgrade…

    Reply
    • I don’t know, actually I haven’t tested yet, but as per your requirement, will try to uprade httpd 2.4.x. Please stay tuned for the update.

      Reply
  9. Hi Ravi,

    Nice article and proper procedure.

    I complected LAMP installation on CentOS6.5 using your article. However I stucked while issuing password. After going through post section I understood where I made mistake.
    My suggestion is you may have to add a step or link to configure MYSQL

    Anyhow wonderful work.

    Reply
  10. Pingback: 25 tips hardening security linux server - idyf.net
  11. Ravi,

    Yesterday, I installed CentOS6.5, clean install, with a LAMP installation with MySQL 5.1 included (misery to upgrade with all those dependencies). This is the first website, where a procedure has been published to smoothly replace the MySQL5.1 with the MySQL5.5 version, including more recent version of PHP and Apache. I followed exactly all the steps that you described, and the result was wonderfull ! Not one error showed up and not one time I had to google to solve an unexpected problem. Thank you very much for this perfect installation procedure, you did a great job, it’s really great !
    Thanks !
    Kind regards,
    Dirk.

    Reply
  12. Ravi,
    Great tutorial. I have followed it all on a brand new CentOS 6 install, but not getting the php pdo for mysql:

    Skipped (dependency problems):

    php-mysql.x86_64 0:5.4.26-1.e16.remi

    a couple of others skipped too, but I’m not worried about them. the PDO driver for mysql is what I need. After first install, phpinfo() showed only pdo for sqlite. After a second install, it had added sqlite2, but still no pdo for mysql.
    What am I missing?
    TIA

    Reply
  13. Hi Ravi

    am fresh to this php i do not know any thing in na dout of this but i tried to do the installation i think i have screws the php in the system its linux box

    pleae if you can help me on this
    how do i clear the existing php and do a clean install

    Thanks
    Nagaraj

    Reply
  14. HI I’m trying to get LAMP configured on Red Hat Linux 5.8 running the following version of php and mysq

    [root@FBDMoodlePRD tmp]# php -v
    PHP 5.3.3 (cli) (built: Dec 5 2013 06:39:35)
    Copyright (c) 1997-2010 The PHP Group
    Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    [root@FBDMoodlePRD tmp]# mysql -V
    mysql Ver 14.14 Distrib 5.5.36, for Linux (x86_64) using readline 5.1
    [root@FBDMoodlePRD tmp]#

    l’m told I need the PDO drivers enbale for mysqli, see the php-i output below…

    [root@FBDMoodlePRD tmp]# php -i | grep PDO
    PHP Warning: Unknown: It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘UTC’ for ‘GMT/0.0/no DST’ instead in Unknown on line 0
    PDO
    PDO support => enabled
    PDO drivers => mysql, odbc, pgsql, sqlite
    PDO Driver for MySQL => enabled
    PDO_ODBC
    PDO Driver for ODBC (unixODBC) => enabled
    PDO Driver for PostgreSQL => enabled
    PDO Driver for SQLite 3.x => enabled

    I don’t know how to do it. The developer is running Moodle on the server and he says he needs it… Any ideas ? List of the current php pkg installed via yum

    yum list installed | grep php
    This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
    php-pear.noarch 1:1.4.9-8.el5 installed
    php53.x86_64 5.3.3-22.el5_10 installed
    php53-bcmath.x86_64 5.3.3-22.el5_10 installed
    php53-cli.x86_64 5.3.3-22.el5_10 installed
    php53-common.x86_64 5.3.3-22.el5_10 installed
    php53-dba.x86_64 5.3.3-22.el5_10 installed
    php53-devel.x86_64 5.3.3-22.el5_10 installed
    php53-gd.x86_64 5.3.3-22.el5_10 installed
    php53-imap.x86_64 5.3.3-22.el5_10 installed
    php53-intl.x86_64 5.3.3-22.el5_10 installed
    php53-ldap.x86_64 5.3.3-22.el5_10 installed
    php53-mbstring.x86_64 5.3.3-22.el5_10 installed
    php53-mysql.x86_64 5.3.3-22.el5_10 installed
    php53-odbc.x86_64 5.3.3-22.el5_10 installed
    php53-pdo.x86_64 5.3.3-22.el5_10 installed
    php53-pgsql.x86_64 5.3.3-22.el5_10 installed
    php53-process.x86_64 5.3.3-22.el5_10 installed
    php53-pspell.x86_64 5.3.3-22.el5_10 installed
    php53-snmp.x86_64 5.3.3-22.el5_10 installed
    php53-soap.x86_64 5.3.3-22.el5_10 installed
    php53-xml.x86_64 5.3.3-22.el5_10 installed
    php53-xmlrpc.x86_64 5.3.3-22.el5_10 installed

    Reply
    • Hi,

      I’m tried to install LAMP on RHEL5.8(32 bit) by following the steps.

      Getting the below error if I execute the below command.
      ——————————————————————-
      [root@server1 ~]# yum –enablerepo=remi,remi-test install httpd mysql mysql-server php php-common
      Loaded plugins: katello, product-id, security, subscription-manager
      Updating certificate-based repositories.
      Unable to read consumer identity
      Could not retrieve mirrorlist http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=i386 error was
      [Errno 4] IOError:
      Error: Cannot retrieve repository metadata (repomd.xml) for repository: epel. Please verify its path and try again
      ———————————————————————————-

      Reply
  15. Hi Ravi saive,

    kindly advise about the php,mysql and apache on CentOS 6.3, i already installed those are in the CentOS, and everything’s fine, event the php and mysql, they known each others, i mean those were connectted with the php script connecting the database, but unfortunatelly there are any scripts in my source could not run on the web base, it can only connect the database, but when i used the code to list the record in the database it didn’t me that codes, so could you please advise or send me the email?

    Reply
  16. Excuse me, i forget to traduce, Hi John, I need to enable gd library in Oracle linux server, I have php 5.5.8 and mysql 5.6.15 apache 2.2.3, I can use this repository?

    Reply
  17. Pingback: Tecmint's Biggest Milestones and Achievements in 2013 - Happy New Year 2014
  18. only php 5.3

    =============================================================================================================================
    Package Arch Version Repository Size
    =============================================================================================================================
    Installing:
    php-gd x86_64 5.3.3-27.el6_5 updates 107 k
    php-mbstring x86_64 5.3.3-27.el6_5 updates 455 k
    php-mcrypt x86_64 5.3.3-3.el6 epel 19 k
    php-mysql x86_64 5.3.3-27.el6_5 updates 81 k
    php-pdo x86_64 5.3.3-27.el6_5 updates 75 k
    php-pear noarch 1:1.9.4-4.el6 base 393 k
    php-pecl-apc x86_64 3.1.9-2.el6 base 96 k
    php-pecl-memcache x86_64 3.0.5-4.el6 base 60 k
    php-pecl-memcached x86_64 1.0.0-1.el6 epel 28 k
    php-pecl-mongo x86_64 1.4.4-1.el6 epel 123 k
    php-pgsql x86_64 5.3.3-27.el6_5 updates 70 k
    php-xml x86_64 5.3.3-27.el6_5 updates 103 k
    Installing for dependencies:
    libmcrypt x86_64 2.5.8-9.el6 epel 96 k
    libmemcached x86_64 0.31-1.1.el6 base 80 k
    postgresql-libs x86_64 8.4.18-1.el6_4 base 201 k

    Transaction Summary

    Reply
  19. I have a doubt in Cron jobs. Can we execute a Cron job before system shutdown? I want to execute a Cronjob/script in fedora 18 before it shuts down. Kindly reply me….

    Reply
  20. i cudn’t enable mbstring on my php tried all the methods..please to help ! i have installed = apache – 2.2.25 , php 5.3.27,mysql 5.5.34.
    Its a strugge to enable any extension here.

    Reply
  21. Hi,

    First, thank you so much for this great tutorial. I only have some questions here :)

    I already remove my old version of php,mysql and apache before install and doing this procedure but when I checked the version of my newly installed php,mysql and apache I found out that my php version is still not the same with this tutorial have.

    MY current PHP version: (update from 5.2.1 but not the with the tutorial)

    —PHP 5.4.21 (cli) (built: Oct 27 2013 12:42:05)
    Copyright (c) 1997-2013 The PHP Group
    Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

    —MY Current Apache Version: (Still the same)
    Server version: Apache/2.2.3
    Server built:Oct 16 2013 12:18:29

    —My Current MYSQL Version:(updated)
    Server version:5.5.34 MySQL Community Server (GPL) by Remi
    Protocol version:10

    Hope we can fix this issue :)

    Thanks again!

    Reply
      • Thanks for the reply, My CentOS version is 5.9 and I think this version is indicated on this tutorial?

        I also tried 6.4 but I don’t feel this vesion ;) so I’m staying with the old 5.9 :)

        Just to share, I’m upgrading because I want to setup a new drupal website server.

        MY current drupal site contains this versions:

        CentOS 5.8
        PHP 5.3.3
        MySQL 14.12 Distib 5.0.9
        Server Version: 5.0.95
        Apache 2.2.3
        Drupal 7.14

        my plan is

        Going to 5.9 ( not 6.x )
        Drupal 7.23
        and your PHP,MYSQL and Apache version

        do you think I need to upgrade these versions just to run a new drupal site or just leave it?

        I also read some articles saying that the version of php 5.3.3 is a buggy version.. and they recommend to upgrade to 5.3.27 version but that article is way back last year..

        i know this is Off topic but I’m hopping for your suggestions :)

        Thanks!

        Reply
        • No need of up-gradation of OS and packages, you can deploy latest version of Drupal on the current configuration of your server.

          Reply
  22. Hi Ravi,

    I’m running RHEL 6.3 and followed your recipe for upgrading PHP and MySQL.

    I’m getting the same issue as others above with the following when trying to install ‘mysql-server’ package:

    Error: Package: mysql-server-5.5.34-1.el6.remi.x86_64 (remi)
    Requires: libz.so.1(ZLIB_1.2.0)(64bit)

    It appears that the ‘libz.so’ already installed is newer than 1.2.0:

    yum whatprovides *libz.so*

    zlib-1.2.3-27.el6.x86_64 : The zlib compression and decompression library
    Repo : installed
    Matched from:
    Filename : /lib64/libz.so.1.2.3
    Other : libz.so.1()(64bit)
    Filename : /lib64/libz.so.1

    zlib-devel-1.2.3-27.el6.x86_64 : Header files and libraries for Zlib development
    Repo : installed
    Matched from:
    Filename : /usr/lib64/libz.so

    Will removing this package as you recommend mean the required one is installed (downgraded) as a dependency?

    I really don’t wish to start a wild goose-chase tracking down dependencies and downgraded versions…

    Thanks for any help!
    – Richard

    Reply
  23. Need to upgrade PHP to 5.4 or above. Server don’t have internet connection. How do I do it? Thanks a lot..

    Centos with Apache ENV.

    Reply
  24. i got this error:-
    Error: Package: mysql-server-5.5.34-1.el6.remi.i686 (remi)
    Requires: perl-DBI
    Error: Package: mysql-server-5.5.34-1.el6.remi.i686 (remi)
    Requires: perl-DBD-MySQL
    Error: Package: mysql-server-5.5.34-1.el6.remi.i686 (remi)
    Requires: perl(DBI)
    Error: Package: mysql-server-5.5.34-1.el6.remi.i686 (remi)
    Requires: libz.so.1(ZLIB_1.2.0)
    You could try using –skip-broken to work around the problem
    You could try running: rpm -Va –nofiles –nodigest
    [secpod@localhost httpd-2.2.9]$ chkconfig –levels 235 mysqld on
    error reading information on service mysqld: No such file or directory

    Reply
      • I’m using rhel 6-base and I tried this
        yum remove perl-DBI
        Loaded plugins: product-id, refresh-packagekit, subscription-manager
        Updating Red Hat repositories.
        INFO:rhsm-app.repolib:repos updated: 0
        Setting up Remove Process
        No Match for argument: perl-DBI
        No Packages marked for removal

        Reply
  25. Hi Ravi,
    I need to install phpmyadmin. Currently I am having-
    # mysql -V
    mysql Ver 14.14 Distrib 5.1.61, for redhat-linux-gnu (i386) using readline 5.1
    #httpd -v
    Server version: Apache/2.2.15 (Unix)
    Server built: Feb 7 2012 09:50:15
    # php -v
    PHP 5.5.4 (cli) (built: Sep 19 2013 14:43:01)
    Copyright (c) 1997-2013 The PHP Group
    Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
    When I run
    # yum –enablerepo=remi,remi-test install httpd mysql mysql-server php php-common
    I am getting-
    Error: Package: mysql-server-5.5.34-1.el6.remi.i686 (remi)
    Requires: libz.so.1(ZLIB_1.2.0)
    You could try using –skip-broken to work around the problem
    You could try running: rpm -Va –nofiles –nodigest
    Can you suggest me what could be the reason or how shall I install phpmyadmin?

    Reply
  26. Pingback: 13 Apache Web Server Security and Hardening Tips
  27. I have installed mysql and mysql-server on fedora 19 successfully but when I am trying to
    start service /etc/init.d/mysqld start its showing
    /etc/init.d/mysqld: command not found
    why its happening could you please let me know

    Reply
    • In latest Fedora release, they’ve introduced systemctl to enable, start and stop services. Like this way.

      # systemctl enable httpd.service
      # systemctl enable mysqld.service
      # systemctl start httpd.service
      # systemctl start mysqld.service
      
      Reply
  28. Ravi,

    Thanks for the great info. Installed all on my Centos 5.8 box. My php is I-386 version.

    A few small problems…

    First, I’m getting this error in PhpMyAdmin:

    Your PHP MySQL library version mysqlnd 5.0.11-dev – 20120503 – $Id: 40933630edef551dfaca71298a83fad8d03d62d4 $ differs from your MySQL server version 5.5.33. This may cause unpredictable behavior.

    Next, I need to enable the cURL extension.

    Any help would be greatly appreciated .

    Reply
  29. Hi,

    Very useful article. Followed the steps and installed without any issues.

    Just want to know If we need to install the individual packages of this Apache, Mysql and Php for those who do not have Internet connection. Just assume for a standalone workstation.

    Could you please guide how to download the individual packages and configure them in centos.

    Thanks..

    Reply
    • Hi Bala…

      Follow the below procedure to download all pkgs and install them into stand alone machine.

      – First install yum-downloadonly pkg

      # yum install yum-downloadonly -y

      – Next create a dir for repsective pkgs Ex: /PHP-5.5.0-Modules

      Now just fire the below command

      # yum –enablerepo=remi,remi-test install php-mysql php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml php-pecl-apc php-cli php-pear php-pdo –downloadonly –downloaddir=/PHP-5.5.0-Modules

      Thats it… All pkgs will get downlaod here and u can install them into anywhere u want.

      Reply
  30. Thank you very much for the tutorial… very good work… My problem is, I want to set up phpmyadmin 4.0.5 but version 2.3.11 is established. please help

    Reply
  31. I went through everything twice and when i dial up the server in a browser it doesn’t show the page, “this page cant be displayed”

    using Centos 6.4 on xen center VM

    Reply
  32. Hey, nice tutorial. I’m running Fedoa 17, 64 bit.
    I tried installing PHP 5.5 with this tutorial but it seems to install php 5.4
    I checked the contents of the directory where it is pulling from and it seems 5.5 is not listed.
    Any ideas?

    Reply
    • I think in Fedora 17, 5.5 version not supported. If you looking for updated version of PHP, then you need to upgrade your system.

      Reply
  33. great tutorial except for one thing, and not your fault. I have CentOS 6.4 on a 64 bit system and when I installed the REMI repository from http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm, it contained mysql 5.1.6 not 5.5 and php 5.3.3. As for the process, it went seamlessly … just not the results I was expecting. Thought I’d mention it for anyone else with a 64 bit system. Or maybe I did something wrong, wouldn’t be the first time.

    Reply
    • Did you added both Remi and Epel repositories? Can you post the output of the said command. So, we could find out why it showing 5.1.6 instead of 5.5.

      # yum --enablerepo=remi,remi-test list httpd mysql mysql-server php php-common
      
      Reply
      • I don’t know what I did wrong but I did a fresh install of CentOS on a different machine and followed your instructions again and this time it worked. I did notice that there were some errors regarding PHP not being able to initialize modules and also an error about the libc libraries are not 100% compatible. Would that have something to do with the MySQL plugin libdbi-dbd-mysql-0.8.3-5.1.el6.x86_64.rpm not being the latest version?

        Reply
  34. Hello, I have centos 6.3 (64bit)
    I am getting this error, could you help me.
    Loaded plugins: security
    base | 1.9 kB 00:00
    base/primary | 2.2 MB 00:00
    base 6339/6339
    epel/metalink | 12 kB 00:00
    epel | 4.2 kB 00:00
    epel/primary_db | 5.4 MB 00:08
    extras | 1.3 kB 00:00
    extras/primary | 6.6 kB 00:00
    extras 17/17
    openlogic | 1.3 kB 00:00
    openlogic/primary | 272 kB 00:00
    openlogic 20/20
    updates | 1.3 kB 00:00
    updates/primary | 497 kB 00:00
    updates 1170/1170
    Setting up Install Process
    Resolving Dependencies
    –> Running transaction check
    —> Package httpd.x86_64 0:2.2.15-15.el6.centos.1 will be installed
    –> Processing Dependency: httpd-tools = 2.2.15-15.el6.centos.1 for package: httpd-2.2.15-15.el6.centos.1.x86_64
    –> Processing Dependency: apr-util-ldap for package: httpd-2.2.15-15.el6.centos.1.x86_64
    –> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.2.15-15.el6.centos.1.x86_64
    –> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.2.15-15.el6.centos.1.x86_64
    —> Package mysql.x86_64 0:5.5.32-1.el6.remi will be installed
    –> Processing Dependency: real-mysql-libs(x86-64) = 5.5.32-1.el6.remi for package: mysql-5.5.32-1.el6.remi.x86_64
    —> Package mysql-server.x86_64 0:5.5.32-1.el6.remi will be installed
    –> Processing Dependency: perl-DBD-MySQL for package: mysql-server-5.5.32-1.el6.remi.x86_64
    –> Processing Dependency: libz.so.1(ZLIB_1.2.0)(64bit) for package: mysql-server-5.5.32-1.el6.remi.x86_64
    —> Package php.x86_64 0:5.5.1-1.el6.remi will be installed
    –> Processing Dependency: php-cli(x86-64) = 5.5.1-1.el6.remi for package: php-5.5.1-1.el6.remi.x86_64
    —> Package php-common.x86_64 0:5.5.1-1.el6.remi will be installed
    –> Processing Dependency: php-pecl-jsonc(x86-64) for package: php-common-5.5.1-1.el6.remi.x86_64
    –> Running transaction check
    —> Package apr.x86_64 0:1.3.9-5.el6_2 will be installed
    —> Package apr-util.x86_64 0:1.3.9-3.el6_0.1 will be installed
    —> Package apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1 will be installed
    —> Package httpd-tools.x86_64 0:2.2.15-15.el6.centos.1 will be installed
    —> Package mysql-libs.x86_64 0:5.5.32-1.el6.remi will be installed
    —> Package mysql-server.x86_64 0:5.5.32-1.el6.remi will be installed
    –> Processing Dependency: libz.so.1(ZLIB_1.2.0)(64bit) for package: mysql-server-5.5.32-1.el6.remi.x86_64
    —> Package perl-DBD-MySQL.x86_64 0:4.013-3.el6 will be installed
    –> Processing Dependency: libmysqlclient.so.16(libmysqlclient_16)(64bit) for package: perl-DBD-MySQL-4.013-3.el6.x86_64
    –> Processing Dependency: libmysqlclient.so.16()(64bit) for package: perl-DBD-MySQL-4.013-3.el6.x86_64
    —> Package php-cli.x86_64 0:5.5.1-1.el6.remi will be installed
    —> Package php-pecl-jsonc.x86_64 0:1.3.1-2.el6.remi.1 will be installed
    –> Processing Dependency: /usr/bin/pecl for package: php-pecl-jsonc-1.3.1-2.el6.remi.1.x86_64
    –> Processing Dependency: /usr/bin/pecl for package: php-pecl-jsonc-1.3.1-2.el6.remi.1.x86_64
    –> Running transaction check
    —> Package compat-mysql51.x86_64 0:5.1.54-1.el6.remi will be installed
    —> Package mysql-server.x86_64 0:5.5.32-1.el6.remi will be installed
    –> Processing Dependency: libz.so.1(ZLIB_1.2.0)(64bit) for package: mysql-server-5.5.32-1.el6.remi.x86_64
    —> Package php-pear.noarch 1:1.9.4-20.el6.remi will be installed
    –> Processing Dependency: php-xml for package: 1:php-pear-1.9.4-20.el6.remi.noarch
    –> Processing Dependency: php-posix for package: 1:php-pear-1.9.4-20.el6.remi.noarch
    –> Running transaction check
    —> Package mysql-server.x86_64 0:5.5.32-1.el6.remi will be installed
    –> Processing Dependency: libz.so.1(ZLIB_1.2.0)(64bit) for package: mysql-server-5.5.32-1.el6.remi.x86_64
    —> Package php-process.x86_64 0:5.5.1-1.el6.remi will be installed
    —> Package php-xml.x86_64 0:5.5.1-1.el6.remi will be installed
    –> Finished Dependency Resolution
    Error: Package: mysql-server-5.5.32-1.el6.remi.x86_64 (remi)
    Requires: libz.so.1(ZLIB_1.2.0)(64bit)
    You could try using –skip-broken to work around the problem
    You could try running: rpm -Va –nofiles –nodigest

    Reply
  35. Just a quick correction: if are having problems with mysqli, please use the following command:

    yum –enablerepo=remi,remi-test install php-mysql

    Do not forget to use the remi repo, other wise it will install an old version (php .5.1).

    I did this for CentOS 5.X.

    Reply
  36. Hello!

    Can you help me? I couldn’t installa My sql On RHEL 5.8 X86_64

    Loaded plugins: katello, security
    Unable to read consumer identity
    Setting up Install Process
    Resolving Dependencies
    –> Running transaction check
    —> Package mysql.x86_64 0:5.5.32-1.el5.remi set to be updated
    –> Processing Dependency: real-mysql-libs = 5.5.32-1.el5.remi for package: mysql
    —> Package mysql-server.x86_64 0:5.5.32-1.el5.remi set to be updated
    –> Processing Dependency: perl-DBI for package: mysql-server
    –> Processing Dependency: perl-DBD-MySQL for package: mysql-server
    –> Processing Dependency: perl(DBI) for package: mysql-server
    –> Running transaction check
    —> Package mysql-libs.x86_64 0:5.5.32-1.el5.remi set to be updated
    —> Package mysql-server.x86_64 0:5.5.32-1.el5.remi set to be updated
    –> Processing Dependency: perl-DBI for package: mysql-server
    –> Processing Dependency: perl-DBD-MySQL for package: mysql-server
    –> Processing Dependency: perl(DBI) for package: mysql-server
    –> Finished Dependency Resolution
    mysql-server-5.5.32-1.el5.remi.x86_64 from remi has depsolving problems
    –> Missing Dependency: perl-DBD-MySQL is needed by package mysql-server-5.5.32-1.el5.remi.x86_64 (remi)
    mysql-server-5.5.32-1.el5.remi.x86_64 from remi has depsolving problems
    –> Missing Dependency: perl(DBI) is needed by package mysql-server-5.5.32-1.el5.remi.x86_64 (remi)
    mysql-server-5.5.32-1.el5.remi.x86_64 from remi has depsolving problems
    –> Missing Dependency: perl-DBI is needed by package mysql-server-5.5.32-1.el5.remi.x86_64 (remi)
    Error: Missing Dependency: perl(DBI) is needed by package mysql-server-5.5.32-1.el5.remi.x86_64 (remi)
    Error: Missing Dependency: perl-DBI is needed by package mysql-server-5.5.32-1.el5.remi.x86_64 (remi)
    Error: Missing Dependency: perl-DBD-MySQL is needed by package mysql-server-5.5.32-1.el5.remi.x86_64 (remi)
    You could try using –skip-broken to work around the problem
    You could try running: package-cleanup –problems
    package-cleanup –dupes
    rpm -Va –nofiles –nodigest
    The program package-cleanup is found in the yum-utils package.

    Reply
    • To get rid of such dependency errors, remove the Perl-DB package.

      # yum remove perl-DB perl-DBD-MySQL
      

      And then try to install again, hope it will work.

      Reply
  37. Hello Ravi, first of all i hat a lot of help through this great how to.

    But as stated a comment above i also have the issue of MySQL Daemon failed to start.

    Where exactly can i find the my.conf file to check if configuration is correct.

    Reply
    • I fixed the problem, but cant seem to get the FTP working, It givis me error that i do not have the right permissions.

      Reply
  38. Thanks for your post..

    I got an error while i start the mysql…

    “MySQL Daemon failed to start.
    Starting mysqld: [FAILED]”

    Can you explain how can i start mysql…

    Reply
  39. Pingback: 25 Hardening Security Tips for Linux Servers | ..::Last Bits::..
  40. Pingback: 25 Hardening Security Tips for Linux Servers
  41. Pingback: Creating Your Own Webserver and Hosting A Website from Your Linux Box
  42. Hi here i got the info abt how to install…can u please post something like how it work…The details are below.

    I have install install linux,apache,mysql and php. But now i can’t know how its work together. Means how php website is conecting to mysql database and how it host on apache web server.

    Reply
      • What should I do in order to install both in different locations but not in default directories like if I want to install under /apps?

        And If I want to have two different versions of apache for testing purpose before deleting older one in different directories then will there be any difference in installation procedure?

        Reply
        • Yes! use yum to install first version of Apache in default location and compile the second version using source.

          Reply
  43. Thanks. My doubt is should I delete older version and install latest version or is there any update option for both apache and PHP. If so pls let me know.

    Reply
    • Yes! you must delete older versions before compiling new versions. Till now there are no official updates from repositories.

      Reply
  44. I want to upgrade Apache from 2.4.3 to 2.4.4 and PHP from 5.4.6 to 5.4.14 in RHEL. Can I get steps to accomplish this.

    Thanks

    Reply
  45. Need help in solving “Your PHP installation appears to be missing the MySQL extension which is required by WordPress”.
    OS RedHat Linux 6 Ent. 64bit x86

    Reply
  46. Php is not beeing parsed. What can i do? using Centos 6.2

    I installed virtualmin, then i followed the steps on this page.
    php-cli works fine do

    Reply
    • for some reason, i find the following lines in httpd.conf
      RemoveHandler .php
      RemoveHandler .php5
      php_admin_value engine Off

      after removing, php works fine.

      Reply
  47. Error: mysql55-libs conflicts with mysql-libs-5.1.67-1.el6_3.x86_64
    Error: Package: php54w-mysql-5.4.13-1.w6.x86_64 (@webtatic)
    Requires: libmysqlclient.so.18(libmysqlclient_18)(64bit)
    Removing: mysql55-libs-5.5.29-1.w6.x86_64 (@webtatic)
    libmysqlclient.so.18(libmysqlclient_18)(64bit)
    Updated By: mysql55-libs-5.5.30-1.ius.el5.x86_64 (ius)
    Not found
    Available: mysql55-libs-5.5.28-1.w6.x86_64 (webtatic)
    libmysqlclient.so.18(libmysqlclient_18)(64bit)
    You could try using –skip-broken to work around the problem
    You could try running: rpm -Va –nofiles –nodigest

    Reply
      • I want to access to of my projects simultaneously in the same machine .How can I setup virtual hosts or is their any other ways to that.

        Reply
        • You can create as many as virtual hosts same way as shown below. Just add the following lines to your httpd.conf file.

          NameVirtualHost *:80
          
          <VirtualHost *:80>
              ServerAdmin [email protected]
              DocumentRoot "/var/www/html/tecmint"
              ServerName tecmint.com
              ServerAlias www.tecmint.com
              ErrorLog "logs/tecmint/error_log"
              CustomLog "logs/tecmint/access_log" common
          </VirtualHost>
          
          <VirtualHost *:80>
              ServerAdmin [email protected]
              DocumentRoot "/var/www/html/tecmint1"
              ServerName tecmint1.com
              ServerAlias www.tecmint1.com
              ErrorLog "logs/tecmint1/error_log"
              CustomLog "logs/tecmint1/access_log" common
          </VirtualHost>
          
          Reply
          • I am getting [FAILED] when I restart my httpd. I want to run two projects on my local machine I dont know whether it can be done using by virtual hosts are not.

      • The requested URL /conf/myadmin was not found on this server.
        Apache Server at 82.165.24.94 Port 80

        PHP 5.4.12 (cli) (built: Feb 21 2013 20:17:01)
        Copyright (c) 1997-2013 The PHP Group
        Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

        my each step is right but not proper open my phpmyadmin..what the solution

        Reply
  48. Pingback: How to Install Varnish Cache (Web Accelerator) in RHEL/CentOS/Fedora and Ubuntu/Debian
  49. first of all thanks for the tutorial.

    the linke for the libmcrypt is dead :

    Error Downloading Packages:
    libmcrypt-2.5.7-5.el5.i386: failure: libmcrypt-2.5.7-5.el5.i386.rpm from epel: [Errno 256] No more mirrors to try.

    please fix it.

    Thanks

    Reply
  50. i wont to start apache but …

    [root@hotel526 ~]# /etc/init.d/httpd start
    Starting httpd: Syntax error on line 206 of /var/www/vhosts/shikolajme.com/conf/13605257930.90124700_httpd.include:
    Wrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper cannot be accessed: (2)No such file or directory
    [FAILED]

    Reply
    • I think you messed up your PHP installation with Plesk under your CentOS system. To fix such errors do this.

      # ln -s /usr/bin/sw-engine-cgi /var/www/cgi-bin/cgi_wrapper/cgi_wrapper
      

      If you don’t have wrappers installed, then install using yum command as show.

      # yum install sw-engine-cgi
      

      That’s it. let me know.

      Reply
  51. The easiest method to update PHP from older version 5.1.x to 5.3.x & the method is called “NASHOT’s Method”.

    ================== START ===============================
    NASHOT’s Method:

    Step 1) Go to GUI mode(X-Windows preferably Gnome desktop) & then “Add/Remove Software section(Package Manager).

    Step 2) Click on Search TAB & enter the search string as php & set the radio button to “Installed Packages” & Hit the Search Button.

    Step 3) Search result will show existing php modules with Ticked check-boxes at the beginning. It’s something like this:
    [/] php-5.1.x…..
    [/] php-common-5.1.x……
    [/] php-cli-5.1.x……
    [/] php-ldap-5.1.x……
    Etc…Etc…

    Step 4) Now Un-Tick the Check-Boxes from all resulted lines & then Click on Apply Button. This will remove existing PHP version Modules.

    Step 5) Inside the “Package Manager” click on Search Tab & enter the search string as php53 & set the radio button to “All Packages” & Hit Search Button.

    Step 6) Search shows many Result lines related to new PHP version 5.3.x with Un-Ticked Check-Box before each line.

    Step 7) Now Tick the Check-Boxes from all resulted lines & then Click on Apply Button.

    Now “Package Manager” will begins to check for Dependancy Modules for Selected PHP Modules & Downloads the new PHP 5.3.x package modules & then installs Automatically.

    Now Restart your system & check the version of the installed PHP Version by using “php -v” command & result should be PHP 5.3.x

    Please NOTE: If your installation halts at “Checking Dependancy”, then check for selection of “PHP53-odbc64-5.3.x…..”. Actually there are 2 odbc packages & each meant for 32bit & 64bit version of OS. So select only ONE odbc package which is compatible with your OS.

    =================== END ==============================

    Reply
    • First replace old php version using.

      # yum remove php php-common php-devel
      

      Then install latest version as described in the article.

      Reply
    • Set the following variable in your php.ini file, If you don’t have access to the php.ini, you can add it to .htaccess file.

      short_open_tag=On
      

      Restart your Apache server.

      Reply
  52. Hey Ravi,
    I am new to linux, Thanks for the steps i followed the steps but while checking the phpinfo i am getting php code of the file,
    Linux version – Redhat enterprise linux 5.4
    While checking with the command php -v its giving me 5.2.17 version not the installed one, do i need to uninstall previous version first?

    Please let me know if you need any other information to help me

    Reply
  53. well i am using cent os 6.3 32 bit there is a problem when iam trying to install the php module
    Error: Package: mysql-server-5.1.61-4.el6.i686 (tejas-barot-wine)
    Requires: mysql = 5.1.61-4.el6
    Installed: mysql-5.5.29-1.el6.remi.i686 (@remi)
    mysql = 5.5.29-1.el6.remi
    Available: mysql-5.1.61-4.el6.i686 (tejas-barot-wine)
    mysql = 5.1.61-4.el6
    You could try using –skip-broken to work around the problem
    You could try running: rpm -Va –nofiles –nodigest
    what i wl do ?

    Reply
  54. indeed Impressive repository and post KB to convert fresh linux distro into productive web server in few minutes !

    It rocks flawless.

    Thanks Ravi.

    Reply
  55. Thank you so much for creating this tutorial. I am having to install various content management systems on a RedHat 6 server for testing. After installing PHP, mysql and Apache before starting the install of the systems, discovered that one of them needed php mbstring enabled. I found other search results but I realized a reinstall of PHP was needed and this tutorial efficiently helped me exactly do that.

    Your site is now going to be among those I look directly for help and look at daily with my other tech resources.

    Thanks,

    James

    Reply
  56. FYI – it isn’t mentioned because it is assumed a fresh install, but it also works with an upgrade. You just need to remember to run “mysql_upgrade” from the command line after the upgrade to fix the privileges and performance_schema.

    Reply
    • @Gary

      If it is fresh MySQL installation, then password would be blank.. or you can set password using following command.

      mysqladmin -u root password NEWPASSWORD
      

      Or to change MySQL password use.

      mysqladmin -u root -p'oldpassword' password 'newpass'
      
      Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.