Setting up a LAMP Stack (Linux, Apache, MySQL, PHP)

1. Install Apache
2. Install MySQL
3. Install PHP
4. Verify LAMP Stack

1. Install Apache

Install the package:

sudo apt-get install apache2

Fedora/CentOS/SUSE Systems

yum install httpd

And start the service:

sudo service apache2 start


sudo service httpd start


2. Install MySQL


$ sudo apt-get install mysql-server
$ sudo mysql_secure_installation
$ sudo mysql_install_db

$ sudo service mysql start


$ sudo yum install mysql-server
$ sudo service mysqld start
$ sudo /usr/bin/mysql_secure_installation

The mysql_secure_installation command runs the setup for MySQL.

This allows you to set up a root password, and a few other configuration options.

3. Install PHP


sudo apt-get install php5 libapache2-mod-php5


sudo yum install php php-mysql

4. Verify LAMP Stack

You can verify your Apache installation by visiting http://localhost in your browser.

If installed correctly, and the service is running, you will see a message saying “It works!”

lamp stack apache-it-works

To verify your PHP installation, create the following file:

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

and add this line:

<?php phpinfo(); ?>

Now navigate to http://localhost/info.php. You should see a page displaying all of the configuration information for PHP on your system.

lamp stack phpinfo

That’s it!

If you do encounter any errors, your best bet is to Google that shit!

Chances are high that question has been asked and answered on Stack Overflow.

Thanks for reading!


Syntax Highlighting by EnlighterJS

About the Author

Kimberly is currently a Test Automation Engineer for Mozilla, with a focus on automating web accessibility testing.

While she always enjoys learning new technologies, her current focus is python, and when she has free time (she doesn't), she enjoys JavaScript programming and learning about Data Analysis.

When not coding, Kimberly spends time with her three young boys, brand new baby girl, and her partner, in Durango, CO.

One Reply to “Setting up a LAMP Stack (Linux, Apache, MySQL, PHP)”

Comments are closed.