When the time comes, businesses of sizes will require the whole LAMP stack. LAMP or Linux Apache MySQL PHP stack will become compulsory for a front-end site development, website application, back-end website, etc. If you are a professional developer, you are then well-aware of PHP and its importance in working with database and website servers. But if you are already working with one of the PHP developers, it will be a lot easier for you to use it. 

You might be an outstanding PHP developer, but that does not mean that you have the knowledge to install PHP, Apache, and MySQL. You might also not know how to get them configured so that they can work with no hassle. But you can surely learn how to install MySQL, PHP, and Apache. After that, you can find out how to configure all of them with PHP. 

To learn and understand this particular process through the operating system of Linux on both the Red-Hat and Ubuntu-based platforms, this guide will help you. But if Linux is not the tool you desire, you must modify the process to work perfectly with both Windows and macOS. 

So, let’s begin the discussion, shall we??

Installing Apache, MySQL, and PHP

There are some ways through which you can get the installation work done. You are free to install the pieces separately or get them done together or in a group. Let’s have a look at the installation process in detail. 


First, you will do it on the Ubuntu platform. Keep one thing in mind: You will install PHP to work perfectly with MySQL and Apache. 

So, you must begin your work by logging into the Ubuntu server and then install Apache with this particular command: 

sudo apt-get install apache2- y

Once the installation work is done, you need to install MySQL into the server with this command: 

sudo apt-get mysql-server-y

These two commands might pick up other dependencies during the installation process. So, when it’s completed, you must secure the database server with the help of this command: 


Now, all you need to do is install the PHP along with all its necessary bits. Doing so will enable you to connect both MySQL and Apache with the command:

 sudo apt-get install php libapache2-mod-php php-mysql -y

You have finally installed MySQL, PHP, and Apache on the Ubuntu server and the software, which is compulsory for all of them to work perfectly together. You can make the work easier for yourself by installing them all together with this single command:

 sudo apt-get install lamp-server^ -y

When everything has been installed, you have to make sure that both MySQL and Apache are enabled and have started through these commands:

  • sudo systemctl start apache2
  • sudo systemctl enable apache2
  • sudo systemctl start mysql
  • sudo systemctl enable mysql


When you conduct the installation work on the Red-Hat distribution, such as the CentOS 8 Stream, the commands will differ significantly compared with Ubuntu. So, if you have to install Apache, the command will be:

 sudo dnf install httpd -y

To install the MySQL server, the command will be:

 sudo dnf install mysql-server -y

Now, you have to secure the database installation through this command:

 sudo mysql_secure_installation

Once you have secured the MySQL database, you have to enable both MySQL and Apache. For that, the command is: 

  •  sudo systemctl start httpd
  • sudo systemctl enable httpd
  • sudo systemctl start mysql
  • sudo systemctl enable mysql

Lastly, you have to install the PHP and its bits. But before that, you have to enable a repository, and it’s the EPEL repository and command is:

sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

Add the Remi repository with this command

 sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm

When you run this particular command and receive a certificate error, you have to disable the certificate checks temporarily. To do so, use this command:

 sudo nano /etc/yum.conf

After doing so, add this right at the bottom of the file:


Once you have completed that work, you need to save and close the file. After that, run the command mentioned above again to add the Remi repository.

Lastly, you have to issue all these commands below to install the PHP and numerous components. The command is:

sudo dnf -y install php php-{cli,fpm,mysqlnd,zip,devel,gd,mbstring,curl,xml,pear,bcmath,json}

Once the PHP installation work is done, you need to remove the sslverify=false” from the yum.conf file. 

CentOS does not have an equivalent when it comes to installing the lamp-server^. For such reasons, you have to install everything one at a time. 

Configuring PHP

Remember, PHP is always configured within the php.ini file, no matter the type of operating system you are using. You just have to know one thing: where that file [php.ini] is precisely located. For instance, within the CentOS 8 Stream, you will find that file in /etc. If you wish to edit the php.ini file on CentOS 8 Stream, you have to provide this particular command: 

 sudo nano /etc/php.in

If you are using the Windows Operating System, that particular path will be:

C:\Program Files\PHP\X\php.in [Here, “X” stands out as the release number]

 Under the MacOS Operating System, the path will be:

 sudo nano /etc/php/7.4/apache2/php.ini

The php.ini is pretty massive, and according to PHP 7.4, the file stands out to be 1673 lines long. For such reasons, there are many configuration options you have to go through. But the configuration options that you wish to edit will depend entirely on your requirements. However, some options are usually changed or edited within the php.ini file. These options are:

  • max_execution_time = 30- The maximum time a particular script can run before getting terminated. 
  • memory_limit = 128M The maximum amount of memory, which a script can consume. allow_url_fopen = On- Aides in opening the URL, such as files.
  • upload_max_filesize = 2M- The maximum size of a particular, which can easily be uploaded to a web server.
  • session.gc_maxlifetime = 1440- How much can a user be idle right before a session expires.
  • post_max_size = 8M- Maximum value, which a post variable must hold.
  • allow_url_fopen = On – Helps in opening the URL objects

This list of command settings is utilized with PHP in conjunction with MySQL and Apache. You might encounter some other settings, which you have to alter so that all the things get to work smoothly. But that will ultimately depend on the software you have installed for LAMP along with your requirements. 

When you are provided all the things in place, you can test out your PHP by making an info.php file through this command:

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

Within that particular file, you have to provide this content:




After that, you must save the file and close it. Now, point the browser to: http://SERVER/info.php [Here, “SERVER” stands out as the IP Address]. You will come across a page, which has listed all the information about the PHP installation.

Final Thoughts

Here it is, the installation and configuration process of PHP for MySQL and Apache. Once you have it running, you can easily hand it over to the PHP developers within your agency.