Install Apache, MariaDB and PHP-FPM (LAMP Stack) on Fedora 24
Fedora 24 was released on June 21, 2016. In this tutorial, we are going to look at how to install Apache, MariaDB and PHP-FPM (LAMP stack) on Fedora 24.
Step 1: Install Apache HTTP Server
Enter this command to install Apache HTTP server.
sudo dnf install httpd -y
By default, Apache will not automatically start when it’s installed on Fedora. So let’s start it with systemctl.
sudo systemctl start httpd
And It’s also a good idea to enable Apache to automatically start when Fedora 24 is rebooted.
sudo systemctl enable httpd
Now let’s check its status.
systemctl status httpd
Output:
● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2016-06-22 22:33:33 EDT; 3min 24s ago Main PID: 3944 (httpd) Status: "Total requests: 0; Idle/Busy workers 100/0;Requests/sec: 0; Bytes served/sec: 0 B/sec" Tasks: 11 (limit: 512)
We can see that Apache is is running and the service is enabled.
Check Apache version.
httpd -v
output:
Server version: Apache/2.4.18 (Fedora) Server built: Feb 4 2016 03:01:27
Now in your browser’s address bar, type the IP address of Fedora. You should see the Fedora test Web page which means Apache Web server is running correctly.
If you are installing LAMP on your local Fedora 24 box, just type 127.0.0.1
or localhost
in the browser address bar.
If you can’t see the above page, then you may need to adjust your firewall settings to allow remote client to visit your web page.
sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https
Restart firewall
sudo firewall-cmd --reload
Now visit your web server and you should see the Fedora test page.
Finally, we need to make apache (Apache user) as the owner of web root directory.
sudo chown apache /var/www/html/ -R
With Apache, your Fedora server can host static html files, but in order to serve a dynamic website such as a WordPress site, we need to install MariaDB and PHP.
LAMP Step 2: Install MariaDB
MariaDB is a drop-in replacement for MySQL. It is developed by former members of MySQL team who concerned that Oracle might turn MySQL into a closed-source product. Many Linux distributions and companies have migrated to MariaDB. So we’re going to install MariaDB instead of MySQL.
sudo dnf install mariadb-server mariadb
After it’s installed, we need to start it and enable it to start on system boot.
sudo systemctl start mariadb sudo systemctl enable mariadb
Check status:
systemctl status mariadb
outputs:
● mariadb.service - MariaDB 10.1 database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2016-06-22 23:15:14 EDT; 5s ago Process: 7504 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS) Process: 7434 ExecStartPre=/usr/libexec/mysql-prepare-db-dir %n (code=exited, status=0/SUCCESS) Process: 7404 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS) Main PID: 7470 (mysqld) Status: "Taking your SQL requests now..." Tasks: 25 (limit: 512) CGroup: /system.slice/mariadb.service └─7470 /usr/libexec/mysqld --basedir=/usr
Check version:
[xiao@fedora ~]$ mysql --version mysql Ver 15.1 Distrib 10.1.14-MariaDB, for Linux (i686) using EditLine wrapper
Now run the post installation security script.
sudo mysql_secure_installation
When it asks you to enter MariaDB root password, press enter because you have not set the root password yet. Then enter y
to set the root password for MariaDB server.
After that, you can just press Enter to answer all the remaining questions. This will remove anonymous user, disable remote root login and remove test database. This step is a basic requirement for MariaDB database security.
Step 3: Install PHP
Enter the following command to install PHP and PHP modules.
sudo dnf install php php-cli php-mysql php-common -y
Once done, we need to restart Apache in order to process PHP code.
sudo systemctl restart httpd
Step 4: Test PHP
Create a test.php
file in the document root.
sudo nano /var/www/html/test.php
Paste the following PHP code into the file.
<?php phpinfo(); ?>
Save and close the file. Now in the browser address bar, enter server-ip-address/test.php
. Replacesever-ip-address
with your actual IP. You should see your server’s PHP information. This means PHP processing is fine.
Apache PHP Module vs PHP-FPM
There are now basically two ways to run PHP code with Apache web server: Apache PHP module and PHP-FPM. The above configuration uses the Apache PHP module to handle PHP code (You can see that the sever API is Apache 2.0 handler from php info).
In order to use PHP-FPM to run PHP code, we need to enable the Apache mod_proxy_fcgi
module. Fortunately it’s enabled by default as you can see with this command
apachectl -M
You can find the following line from the output which means mod_proxy_fcgi
module is enabled.
proxy_fcgi_module (shared)
Now install php-fpm.
sudo dnf install php-fpm
Start and enable php-fpm service.
sudo systemctl start php-fpm sudo systemctl enable php-fpm
Then edit the virtual host configuration file. This tutorial use the default virtual host as an example.
sudo nano /etc/httpd/conf/httpd.conf
Paste the following line at the end of this file.
ProxyPassMatch ^/(.*\.php(/.*)?)$ unix:/run/php-fpm/www.sock|fcgi://localhost/var/www/html/
Save and close the file. Then restart Apache.
sudo systemctl restart httpd
Now if you check the test.php
file in your browser, you will find that Server API is FPM/FastCGI which means Apache web server will pass PHP requests to PHP-FPM.
For your server’s security, you should delete test.php
file now.
Congrats! You have successfully installed Apache, MariaDB and PHP-FPM (LAMP stack) on Fedora 24.
Questions or suggestions are always welcome. If you found this post useful, 🙂 please share it with your friends on social media! Stay tuned for more Linux tutorials.