(Last Updated On: November 4, 2018)

In this blog post, we will look at how to install and configure a LAMP Stack on Fedora 29 / Fedora 28. LAMP Stack is a collection of open-source tools that are used to host web applications. The LAMP stack acronym comprises of:

  • L – Linux host system – Can be VM or physical, or a container
  • A – Apache HTTP Server
  • – MySQL / MariaDB database
  • P – PHP Programming language

To have a functional LAMP stack, you’ll need to install and configure each component one by one. The steps to install and configure LAMP Stack on Fedora 29 / Fedora 28 should be straightforward.

Step 1: Install Fedora 29 / Fedora 28

The recent release of Fedora as of the writing of this article is Fedora 29. We have an installation guide which should work for the Physical server, a Virtual Machine and for Vagrant Box deployments:

How to install Fedora 29 on Physical Server / VirtualBox & Vagrant

Step 2: Install basic packages / set SELinux to Permissive

Install the basic packages like vim, curl, wget, telnet

sudo dnf -y update
sudo dnf -y install vim bash-completion curl wget telnet

If this is your first time to hear about SELinux, I advise you put it in Permissive mode or completely disable it. Check SELinux status by running:

# sestatus 
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Memory protection checking:     actual (secure)
Max kernel policy version:      31

The default mode is enforcing. To put it in Permissive mode, execute:

sudo setenforce 0
sudo sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config

To completely disable it:

sudo sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config

Confirm persistent status configured

$ cat /etc/selinux/config | grep SELINUX=
# SELINUX= can take one of these three values:

Step 3: Install Apache httpd  server

Once you have Fedora OS installed and updated, proceed to install Apache httpd server.

sudo dnf -y install httpd

Configure httpd basic settings:

Edit the configuration file /etc/httpd/conf/httpd.conf and set:

ServerAdmin [email protected]
ServerName  example.com
ServerTokens Prod

You can optionally set Keepalive

KeepAlive On

Enable and start httpd service

sudo systemctl start httpd
sudo systemctl enable httpd

If you have firewalld running, allow  http and https services.

sudo firewall-cmd --add-service={http,https} --permanent
sudo firewall-cmd --reload

Step 4: Install PHP & Extensions

Install PHP and configure httpd to support execution of PHP scripts. Fedora 29 ships with PHP 7.2 in its repositories.

sudo dnf -y install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-29.noarch.rpm
sudo dnf -y install https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-29.noarch.rpm

Install PHP & common extensions:

sudo dnf -y install php php-cli php-php-gettext php-mbstring php-mcrypt php-mysqlnd php-pear php-curl php-gd php-xml php-bcmath php-zip

Here is the sample output.

Last metadata expiration check: 0:06:38 ago on Sun 04 Nov 2018 07:32:04 AM UTC.
Dependencies resolved.
 Package                                      Arch                        Version                                  Repository                    Size
 php                                          x86_64                      7.2.11-1.fc29                            updates                      2.9 M
 php-bcmath                                   x86_64                      7.2.11-1.fc29                            updates                       44 k
 php-gd                                       x86_64                      7.2.11-1.fc29                            updates                       49 k
 php-mbstring                                 x86_64                      7.2.11-1.fc29                            updates                      466 k
 php-pecl-zip                                 x86_64                      1.15.4-1.fc29                            updates                       52 k
 php-pear                                     noarch                      1:1.10.6-1.fc29                          fedora                       348 k
Installing dependencies:
 gd                                           x86_64                      2.2.5-7.fc29                             updates                      128 k
 jbigkit-libs                                 x86_64                      2.1-15.fc29                              updates                       49 k
 libX11                                       x86_64                      1.6.7-1.fc29                             updates                      593 k
 libX11-common                                noarch                      1.6.7-1.fc29                             updates                      155 k
 libtiff                                      x86_64                      4.0.9-13.fc29                            updates                      165 k
 php-cli                                      x86_64                      7.2.11-1.fc29                            updates                      4.4 M
 php-common                                   x86_64                      7.2.11-1.fc29                            updates                      1.0 M
 php-process                                  x86_64                      7.2.11-1.fc29                            updates                       48 k
 php-xml                                      x86_64                      7.2.11-1.fc29                            updates                      166 k
 dejavu-fonts-common                          noarch                      2.35-7.fc29                              fedora                        65 k
 dejavu-sans-fonts                            noarch                      2.35-7.fc29                              fedora                       1.5 M
 fontconfig                                   x86_64                      2.13.1-1.fc29                            fedora                       235 k
 fontpackages-filesystem                      noarch                      1.44-22.fc29                             fedora                       7.7 k
 libXau                                       x86_64                      1.0.8-14.fc29                            fedora                        29 k
 libXpm                                       x86_64                      3.5.12-8.fc29                            fedora                        56 k
 libimagequant                                x86_64                      2.12.1-2.fc29                            fedora                        63 k
 libjpeg-turbo                                x86_64                      2.0.0-1.fc29                             fedora                       158 k
 libwebp                                      x86_64                      1.0.0-2.fc29                             fedora                       270 k
 libxcb                                       x86_64                      1.13.1-1.fc29                            fedora                       201 k
 libxslt                                      x86_64                      1.1.32-3.fc29                            fedora                       243 k
 libzip                                       x86_64                      1.5.1-2.fc29                             fedora                        57 k
 nginx-filesystem                             noarch                      1:1.12.1-14.fc29                         fedora                       9.6 k
 oniguruma                                    x86_64                      6.9.0-2.fc29                             fedora                       184 k
 php-fedora-autoloader                        noarch                      1.0.0-4.fc29                             fedora                        13 k
Installing weak dependencies:
 php-fpm                                      x86_64                      7.2.11-1.fc29                            updates                      1.5 M

Transaction Summary
Install  31 Packages

Total download size: 15 M
Installed size: 61 M
Is this ok [y/N]: y

Confirm your installed PHP version:

$ php -v
PHP 7.2.11 (cli) (built: Oct 9 2018 15:09:36) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

Loaded extensions can be viewed by passing -m option to the phpcommand

$ php -m

Set PHP timezone on the file /etc/php.ini

date.timezone = Africa/Nairobi

See a complete List of Supported Timezones.

Step 4: Install MySQL / MariaDB Database

For installation of MySQL on Fedora 29 / Fedora 28, use our guide:

How to install MySQL 8.0 on Fedora 29 / Fedora 28

Fedora upstream repositories have MariaDB 10.3 which can be installed using the dnfcommand.

sudo dnf install mariadb-server

After the installation, set the character set

sudo vim /etc/my.cnf.d/mariadb-server.cnf

Set your character set under [mysqld] section


Then start the mariadb service and enable it to start on boot

sudo systemctl start mariadb
sudo systemctl enable mariadb

Perform MariaDB initial settings like setting up a root password, disabling remote root login e.t.c:

$ mysql_secure_installation 


In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

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 authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
Answer questions like below:
  • Enter current password for root (enter for none): <Enter>
  • Set root password? [Y/n] y
  • Remove anonymous users? [Y/n] y
  • Remove test database and access to it? [Y/n] y
  • Reload privilege tables now? [Y/n] y

Test login

$ mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.3.10-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> select version();
| version()       |
| 10.3.10-MariaDB |
1 row in set (0.001 sec)

Create and drop test database

MariaDB [(none)]> CREATE DATABASE test_db;
Query OK, 1 row affected (0.001 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON test_db.* TO 'test_user'@'localhost' IDENTIFIED BY "StrongPassword";
Query OK, 0 rows affected (0.002 sec)

Query OK, 0 rows affected (0.001 sec)

To drop the database and user, use

MariaDB [(none)]> DROP DATABASE test_db;
Query OK, 0 rows affected (0.003 sec)

MariaDB [(none)]> DROP USER 'test_user'@'localhost';
Query OK, 0 rows affected (0.001 sec)

We have confirmed that our Database server is working fine. To allow for remote connections, allow port 3306 on the firewall

sudo firewall-cmd --add-service=mysql --permanent 
sudo firewall-cmd --reload

You can also limit access from trusted networks

sudo firewall-cmd --permanent --add-rich-rule 'rule family="ipv4" \
service name="mysql" source address="" accept'

Step 5: Test your Lamp Stack Installation

As a test for our Lamp stack installation on Fedora 29 / Fedora 28, create a PHP test page

sudo vim /var/www/html/phpinfo.php


// Show all information, defaults to INFO_ALL

Reload httpd service and open page on your browser.

sudo systemctl reload httpd

Open added PHP info page http://[serverIP]/phpinfo.php

That’s all. You have successfully installed LAMP stack on your Fedora 29 & Fedora 28 server or Desktop Workstation. Other Fedora Articles available are:

How to install PostgreSQL 11 on Fedora 29 / Fedora 28

How to use Fedora Modular Repository

How to Install PHP 7.3 on CentOS 7 / Fedora