Wiki / tutorial:stack:apache_php_mysql

 

Installing a basic LAMP server is incredibly easy thanks for each OS's relevant package manager. Remember if you want the very latest versions of these applications, you'll need to compile them from source.

CentOS (CentOS/Fedora/etc)

Apache

Use the following command to install Apache (httpd):

yum install httpd

PHP

Again, using yum to install PHP:

yum install php php-cli php-mysql

Note, there may be other PHP libraries you wish to install (search by yum search php*)

MySQL

yum again:

yum install mysql-server mysql-common

Starting the servers

Both will be installed as a service, so to start/restart/etc either, all you need do is:

service <httpd or mysql> <start, restart, stop>

A quick method:

service httpd start; service mysql start

Debian (Ubuntu/Debian/etc)

Apache

Use this command to install Apache:

apt-get install apache2

Make sure the Apache log directory is owned by www-data:

chown www-data:www-data /var/log/apache2

Create an empty config file:

touch /etc/apache2/httpd.conf

PHP

Run this command to install the PHP packages needed to work with Apache:

apt-get install libapache2-mod-php5 php5-cli php5-common php5-cgi

Apache should automatically bind itself to run PHP when it encounters .php files.

MySQL

This is the command to install the MySQL server, client and PHP’s MySQL libraries:

apt-get install mysql-client mysql-common mysql-server php5-mysql

Testing the server

Go to your document root(/var/www) and create a PHP file called ‘info.php’ and put this code inside it:

<?php
phpinfo();
Starting the servers

First, start the MySQL database server:

/etc/init.d/mysql start

Then, start the Apache Web Server:

/etc/init.d/apache2 start

Then go to

http://yourhostname_or_ip/info.php

If you see a page looking like this, Apache and PHP are working.