Last Updated: February 25, 2016
·
1.191K
· bt3gl

A Complete LAMP Server in Fedora 20

LAMP is short for Linux, Apache, MySQL, PHP. This tutorial shows how you can install an Apache2 webserver on Fedora 20 with PHP5 support (mod_php) and MySQL support.

Set Hostname

$ hostname
$ echo "HOSTNAME=<my-hostname>" >> /etc/sysconfig/network
$ hostname "<my-hostname>"

Installing MySQL/MariaDB 5

$ sudo  yum install mysql mysql-server

Create the system startup links for MySQL (so that MySQL starts automatically whenever the system boots) and start the MySQL server:

$ systemctl enable mysqld.service

or

$ systemctl enable mariadb.service

Start the service of MySQL:

$ systemctl start mysqld.service

Run:

$ mysql_secure_installation

Installing Apache2

Apache2 is available as a Fedora package, therefore we can install it like this:

$ sudo yum install httpd

Configure your system to start Apache at boot time:

$ systemctl enable httpd.service

Start Apache:

$ systemctl start httpd.service

Direct your browser to http://localhost, and you should see the Apache2 placeholder page.

Apache's default document root is /var/www/html on Fedora, and the configuration file is /etc/httpd/conf/httpd.conf. Additional configurations are stored in the /etc/httpd/conf.d/ directory.

Installing PHP5

We can install PHP5 and the Apache PHP5 module as follows:

$ sudo yum install php

We must restart Apache afterwards:

$ systemctl restart httpd.service

Testing PHP5

The document root of the default web site is /var/www/html. We will now create a small PHP file (info.php) in that directory and call it in a browser. The file will display lots of useful details about our PHP installation, such as the installed PHP version. Edit /var/www/html/info.php with the lines:

<?php
phpinfo();
?>

Now we can call that file in a browser (e.g. localhost/info.php). PHP5 is working, and it's working through the Apache 2.0 Handler, as shown in the Server API line.

If you scroll further down, you will see all modules that are already enabled in PHP5. MySQL is not listed there which means we don't have MySQL support in PHP5 yet.

Getting MySQL Support In PHP5

To get MySQL support in PHP, we can install the php-mysql package. It's a good idea to install some other PHP5 modules as well as you might need them for your applications. You can search for available PHP5 modules like this:

$ sudo yum search php

Pick the ones you need and install them like this:

$ sudo yum install php-mysqlnd php-mssql php-opcache

Now restart Apache2:

$ systemctl restart httpd.service

Reload localhost/info.php in your browser and scroll down to the modules section again. You should now find lots of new modules there, including the MySQL module.

phpMyAdmin

phpMyAdmin is a web interface through which you can manage your MySQL databases.

$ sudo yum install phpmyadmin

Now we configure phpMyAdmin. We change the Apache configuration so that phpMyAdmin allows connections not just from localhost (by commenting out everything in the <Directory /usr/share/phpMyAdmin/> and adding the line Require all granted):

$ vi /etc/httpd/conf.d/phpMyAdmin.conf

Restart Apache:

$ sudo systemctl restart httpd.service

And look at localhost/phpmyadmin/ in your browser.

Build Virtual Hosts for WebApps

To be able to deploy and test many web applications, you might create a virtual host for each of them. To do so edit /etc/hosts, adding in the end of file:

127.0.0.1    nameofapp.localhost

Then, edit /etc/httpd/conf/httpd.conf, adding in the end of the file:

 <VirtualHost *:80>
   DocumentRoot /var/www/html
   ServerName localhost
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot /var/www/html/FOLDERAPP
    ServerName nameofapp.localhost
</VirtualHost>

Restart the Apache server:

$ systemctl restart httpd.service

In the examples, instead of localhost, use nameofapp.localhost.