Below are steps to install the LAMP stack on a Fedora Linux server – Apache HTTP Server, MySQL (database software) and PHP (or Perl or Python) in about 15 minutes.
Things to know
- Commands below are executed as root (or prefixed with sudo).
- The steps have been tested on Fedora 14, Fedora 15, and Fedora 16 successfully.
- Instead of localhost for the steps below, you may have to substitute your server’s IP address (e.g. 192.168.2.31).
- If you are using another Linux distribution (e.g. Ubuntu, OpenSUSE), the install command executions and file locations may differ, but setup will be similar.
- If you already have the packages installed, your package manager will tell you and you can skip the installation step.
- Install commands below will install the latest stable releases.
Getting Ready with a Clean Slate (Optional)
If you want to start with a clean install, you can remove existing installations of the components of the LAMP stack first.
# yum erase httpd mysql mysql-server php php-mysql phpmyadmin
Be careful if you do execute this command and find some components are already installed and yum asks you if you want to uninstall them. For example, some KDE distributions install MySQL with KDE packages like Akonadi, so you can leave MySQL there.
Install all Apache Web Server, MySQL, PHP, and phpMyAdmin
With this command, you can install all the packages at once.
# yum install httpd mysql mysql-server php php-mysql phpmyadmin
Apache – Starting and Configuring Apache (HTTPD)
Configure Apache to start automatically (Optional):
# /sbin/chkconfig httpd on
To start the server process immediately:
# /etc/rc.d/init.d/httpd start
Check Apache is running
Open up a browser on your server and go to the web address:
You should see a web page saying that Apache is running assuming your default Apache site (
/var/www/html/) is empty.
Get Started on a Website
If you want to get started with a website in Apache, you can find the root of the web server at
/var/www/html/ and configuration files at
Instructions on how to use iptables or system-config-firewall-tui to ensure port 80 is accessible from remote computers.
MySQL – Starting and Configuring MySQL
Start MySQL first if it isn’t already started. If you skip this step, a common error encountered is “Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock” or /tmp/mysql.sock.
# /etc/rc.d/init.d/mysqld start
Some Fedora installations may already have MySQL running for KDE packages like Kontact, Kmail, and Akonadi, so MySQL may already be started.
Check MySQL is running
# mysqladmin version status
Set mysql root password
Go into the mysql command line to set the root password.
mysql -u root
Set the password of the root user in mysql at the mysql prompt. Do not forget to end your mysql command with a semicolon:
mysql> SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘yourpassword’);
If it is successful, this message appears:
Query OK, 0 rows affected (0.00 sec)
Exit the mysql prompt
PHP – Check PHP works with Apache and MySQL
Create the following file in the Apache default site.
# echo “<?php phpinfo(); ?>” > /var/www/html/index.php
Go the address below. You should see a page describing PHP’s configuration and status:
To see the MySQL section, go to:
If the steps above succeeded, you can delete your test file with:
# rm -f /var/www/html/index.php
Configure server start up (Optional)
To start MySQL and Apache every time the server starts up, execute the following:
# chkconfig –levels 235 httpd on
# chkconfig –levels 235 mysqld on
phpMyAdmin – Configure Apache and phpMyAdmin
If you want to allow phpmyadmin connection from other locations other than localhost, then modify the following file. This setting is not recommended if you want to restrict who can access phpMyAdmin, but is common for server installations.
Comment out these lines in the file:
deny from all
allow from 127.0.0.1
allow from ::1
So the lines looks like:
# order deny,allow
# deny from all
# allow from 127.0.0.1
# allow from ::1
# /etc/rc.d/init.d/httpd restart
Check everything is working!
Now you are all set Apache, MySQL, and PHP are setup and you have phpmyadmin to help you administer the MySQL server. Access phpmyadmin at http://localhost/phpmyadmin. Use your MySQL root credentials you configured during the MySQL set up to log in. If you can log into the phpmyadmin application, everything works – Congratulations!
Helpful links for installing LAMP
Turn on the LAMP in your life.