How do I install a LAMP stack to my server?


Browse by products and services

  • Applies to: DV Developer
    • Difficulty: Medium
    • Time Needed: 30 minutes
    • Tools Required: Root access, SSH
  • Applies to: (ve) Server
    • Difficulty: Medium
    • Time Needed: 30 minutes
    • Tools Required: Root access, SSH

READ ME FIRST

This article is provided as a courtesy and is intended as a general guide. Installing, configuring, and troubleshooting third-party applications is unsupported by (mt) Media Temple. Our support staff will be unable to assist you should you run into any complications installing this software. Please take a moment to review the Statement of Support

Video

Watch this video to learn more about LAMP stacks.

Overview

This article will show you how to install a LAMP stack to your DV Developer(ve) Server. Your instructions will vary slightly depending on which operating system you have installed to your server.

TIP:

All of the examples in the article use a sample IP address of 12.34.56.78 and an example domain of mt-example.com. Don't forget to change these values to reflect your domain and IP address!

Instructions

Instructions for Ubuntu

Getting Started

First, log into your server via SSH as the root user.

We'll be using apt-get to streamline the installation of this software, so we'll first want to make sure that your server is up-to-date by running the following commands:

apt-get update
apt-get upgrade

Installation

    • Run the following command to install Apache, MySQL, and PHP to your server:
apt-get install apache2 php5 libapache2-mod-php5 mysql-server mysql-client php5-mysql
  • You will be asked to set the MySQL password. Please choose a strong password.

Configure Apache

Now that you have your LAMP environment installed, you can add some VirtualHost entries. This will allow you to host multiple sites on the one IP address that comes with your (ve) Server.

    1. First, test that Apache was installed correctly by using your browser to visit your IP address or any domain that points to your server. You will see a default message if Apache was installed correctly.
    2. Next, edit your ports.conf file to include information for your specific IP. (In our example, we're using the IP address 12.34.56.78.)
vi /etc/apache2/ports.conf 

Filename: /etc/apache2/ports.conf

You should edit the line starting with NameVirtualHost to show your IP address instead of *:

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default
# This is also true if you have upgraded from before 2.2.9-3 (i.e. from
# Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and
# README.Debian.gz

NameVirtualHost 12.34.56.78:80
Listen 80

<IfModule mod_ssl.c>
# If you add NameVirtualHost *:443 here, you will also have to change
# the VirtualHost statement in /etc/apache2/sites-available/default-ssl
# to <VirtualHost *:443>
# Server Name Indication for SSL named virtual hosts is currently not
# supported by MSIE on Windows XP.
Listen 443
</IfModule>

<IfModule mod_gnutls.c>
Listen 443
</IfModule>
    1. Next, we'll edit your default VirtualHost file to reflect the change in port. Only the very first line is changing (although you can change other lines if you have a reason to do so):

Filename: /etc/apache2/sites-available/default

<VirtualHost 12.34.56.78:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

</VirtualHost>
    1. Optional: The default site will be what displays for your server if someone requests a domain, subdomain, or IP address that resolves to your server but doesn't have a distinct VirtualHost file. The content for this domain is stored in /var/www/. If you don't want to have a default website, you can disable it. Run these commands to disable the default site (only if desired):
a2dissite default
/etc/init.d/apache2 reload
    1. You will now create a custom sites-available VirtualHost file so you can add your own websites to the server. Our example will be for the mt-example.com domain:
vi /etc/apache2/sites-available/mt-example.com

Filename: /etc/apache2/sites-available/mt-example.com

<VirtualHost 12.34.56.78:80>
ServerName mt-example.com
ServerAlias www.mt-example.com
ServerAdmin webmaster@mt-example.com

DocumentRoot /var/www/mt-example.com/html

ErrorLog /var/www/mt-example.com/log/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/www/mt-example.com/log/access.log combined

</VirtualHost>
    1. The file you just edited references some paths that don't yet exist. Let's create them:
mkdir -p /var/www/mt-example.com/html

mkdir -p /var/www/mt-example.com/log
    1. For the sake of testing, you can also create a "Hello World!" page, such as in the example below:
echo -e '<html>\n<head>\n<title>Welcome to Apache!</title>\n</head>\n<body bgcolor="white" text="black">\n<center><h1>mt-example.com is working!</h1></center>\n</body>\n</html>' > /var/www/mt-example.com/html/index.html
    1. You now have an html and log directory for your site, and an index file. This means we're almost ready to go! Enable your site using the following command:
a2ensite mt-example.com,

TIP:

If you ever need to disable your sites, you can do so using the a2dissite command, followed by the site name.

    1. Lastly, reload Apache for the settings to take effect:
/etc/init.d/apache2 reload

Test PHP

The document root for your site should now be /var/www/mt-example.com/html/. Creating a simple phpinfo page will provide useful details about your PHP installation and confirm that PHP is working:

vi /var/www/mt-example.com/html/info.php

The file should read as follows:

Filename: /var/www/mt-example.com/html/info.php

<?php
phpinfo();
?>

Configure and Connect to MySQL

    • With MySQL installed, we recommend you run the following program to secure MySQL:
      mysql_secure_installation

      This will allow you to change the MySQL root password, remove anonymous user accounts, disable root logins outside of "localhost," and remove any test databases.

    • You can connect to MySQL as the root user using the following command:
mysql -u root -p
    • As the root user, you can exercise extensive control over your MySQL environment. The example below creates the database "woot," grants read/write access to the user "meh," and assigns that user the password "k1Tt7":
create database woot; grant all on woot.* to 'meh' identified by 'k1Tt7'; 

Instructions for Debian

Getting Started

First, log into your server via SSH as the root user.

We'll be using apt-get to streamline the installation of this software, so we'll first want to make sure that your server is up-to-date by running the following commands:

apt-get update
apt-get upgrade

Installation

      • Run the following command to install Apache, MySQL, and PHP to your server:
apt-get install apache2 php5 libapache2-mod-php5 mysql-server mysql-client php5-mysql
      • You will be asked to set the MySQL password. Please choose a strong password.

Configure Apache

Now that you have your LAMP environment installed, you can add some VirtualHost entries. This will allow you to host multiple sites on the one IP address that comes with your (ve) Server.

      1. First, test that Apache was installed correctly by using your browser to visit your IP address or any domain that points to your server. You will see a default message if Apache was installed correctly.
      2. Next, edit your ports.conf file to include information for your specific IP. (In our example, we're using the IP address 12.34.56.78.)
vi /etc/apache2/ports.conf 

Filename: /etc/apache2/ports.conf

You should edit the line starting with NameVirtualHost to show your IP address instead of *:

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default
# This is also true if you have upgraded from before 2.2.9-3 (i.e. from
# Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and
# README.Debian.gz

NameVirtualHost 12.34.56.78:80
Listen 80

<IfModule mod_ssl.c>
# If you add NameVirtualHost *:443 here, you will also have to change
# the VirtualHost statement in /etc/apache2/sites-available/default-ssl
# to <VirtualHost *:443>
# Server Name Indication for SSL named virtual hosts is currently not
# supported by MSIE on Windows XP.
Listen 443
</IfModule>

<IfModule mod_gnutls.c>
Listen 443
</IfModule>
      1. Next, we'll edit your default VirtualHost file to reflect the change in port. Only the very first line is changing (although you can change other lines if you have a reason to do so):

Filename: /etc/apache2/sites-available/default

<VirtualHost 12.34.56.78:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

</VirtualHost>
      1. Optional: The default site will be what displays for your server if someone requests a domain, subdomain, or IP address that resolves to your server but doesn't have a distinct VirtualHost file. The content for this domain is stored in /var/www/. If you don't want to have a default website, you can disable it. Run these commands to disable the default site (only if desired):
a2dissite default
/etc/init.d/apache2 reload
      1. You will now create a custom sites-available VirtualHost file so you can add your own websites to the server. Our example will be for the mt-example.com domain:
vi /etc/apache2/sites-available/mt-example.com

Filename: /etc/apache2/sites-available/mt-example.com

<VirtualHost 12.34.56.78:80>
ServerName mt-example.com
ServerAlias www.mt-example.com
ServerAdmin webmaster@mt-example.com

DocumentRoot /var/www/mt-example.com/html

ErrorLog /var/www/mt-example.com/log/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/www/mt-example.com/log/access.log combined

</VirtualHost>
      1. The file you just edited references some paths that don't yet exist. Let's create them:
mkdir -p /var/www/mt-example.com/html

mkdir -p /var/www/mt-example.com/log
      1. For the sake of testing, you can also create a "Hello World!" page, such as in the example below:
echo -e '<html>\n<head>\n<title>Welcome to Apache!</title>\n</head>\n<body bgcolor="white" text="black">\n<center><h1>mt-example.com is working!</h1></center>\n</body>\n</html>' > /var/www/mt-example.com/html/index.html
      1. You now have an html and log directory for your site, and an index file. This means we're almost ready to go! Enable your site using the following command:
a2ensite mt-example.com,

TIP:

If you ever need to disable your sites, you can do so using the a2dissite command, followed by the site name.

      1. Lastly, reload Apache for the settings to take effect:
/etc/init.d/apache2 reload

Test PHP

The document root for your site should now be /var/www/mt-example.com/html/. Creating a simple phpinfo page will provide useful details about your PHP installation and confirm that PHP is working:

vi /var/www/mt-example.com/html/info.php

The file should read as follows:

Filename: /var/www/mt-example.com/html/info.php

<?php
phpinfo();
?>

Configure and Connect to MySQL

      • With MySQL installed, we recommend you run the following program to secure MySQL:
        mysql_secure_installation

        This will allow you to change the MySQL root password, remove anonymous user accounts, disable root logins outside of "localhost," and remove any test databases.

      • You can connect to MySQL as the root user using the following command:
mysql -u root -p
      • As the root user, you can exercise extensive control over your MySQL environment. The example below creates the database "woot," grants read/write access to the user "meh," and assigns that user the password "k1Tt7":
create database woot; grant all on woot.* to 'meh' identified by 'k1Tt7'; 

Instructions for CentOS

Getting Started

First, log into your server via SSH as the root user.

We'll be using Yum to streamline the installation of this software, so we'll first want to make sure that Yum is up-to-date by running the following command:

yum update

Apache

        1. Run the following command to install the latest version of Apache:
          yum install httpd httpd-devel mod_ssl
        2. Next, we'll need to create a configuration file (vhost.conf) in the /etc/httpd/conf.d/ directory:
          touch /etc/httpd/conf.d/vhost.conf
        3. We'll then add the configuration details to this file using an editor such as VIM. Note that we're using the sample IP address 12.34.56.78 and the example domain mt-example.com. You'll want to replace these with your own IP address and domain name:

          Filename: /etc/httpd/conf.d/vhost.conf

          NameVirtualHost <strong>12.34.56.78</strong>:80
          
          
          <VirtualHost <strong>12.34.56.78:80>
          ServerAdmin webmaster@mt-example.com
          ServerName mt-example.com
          ServerAlias www.mt-example.com
          DocumentRoot /var/www/mt-example.com/html/
          ErrorLog /var/www/mt-example.com/logs/error.log
          CustomLog /var/www/mt-example.com/logs/access.log combined
          </VirtualHost>
        4. Create the directory to house the site. Make sure this matches the DocumentRoot specified in your vhost.conf file:
 mkdir -p /var/www/mt-example.com/{html,logs}
        1. Next, create a test page to make sure Apache is working correctly:
 echo '<html><head><title>ve-server1.com</title></head><body><h1>Hello, World!</h1></body></html>' > /var/www/ve-server1.com/html/index.html
        1. You'll also want to configure Apache to start at boot-up:
chkconfig --levels 235 httpd on 
        1. Finally, start Apache:
/etc/init.d/httpd start

You should now be able to see the "Hello World!" page by visiting your IP address.

MySQL

        1. Next, let's install MySQL to your server. Run the following command to begin the installation:
yum install mysql mysql-server mysql-devel
        1. Next, we'll configure the system startup links for MySQL. We want MySQL to start automatically whenever the system boots:
chkconfig --levels 235 mysqld on

/etc/init.d/mysqld start
        1. When MySQL starts up, it will warn you about various security issues. The following command will secure MySQL by walking you through setting your MySQL root password, removing anonymous users, disabling remote root access, and removing the test database. Remember to choose a strong password!
mysql_secure_installation

That's it! MySQL should now be installed to your server.

PHP

        1. Use this command to install PHP5 and the Apache PHP5 module, as well as most of the "common" php packages, including MySQL support:
 sudo yum install php php-common php-gd php-mcrypt php-pear php-pecl-memcache php-mhash php-mysql php-xml php-devel
        1. Next, restart Apache:
/etc/init.d/httpd restart
        1. To test out PHP, add a phpinfo page:
 echo '<?php phpinfo();' > /var/www/mt-example.com/html/phpinfo.php

You can then visit this page at your IP address or domain name (if active). For example, to view your PHP information using the sample IP of 12.34.56.78, you'd visit http://12.34.56.78/phpinfo.php. To be safe, you should delete the "phpinfo.php" file once you've verified that PHP is running.

        1. PHP is now installed! However, your applications may require additional modules. If you're looking for more PHP modules, you can run a search:
yum search php
        1. If you need to install other modules, you can install them as needed. This example includes PHP MySQL support:
yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-eaccelerator php-magickwand php-magpierss php-mapserver php-mbstring php-mcrypt php-mssql php-shout php-snmp php-soap php-tidy

To reduce overhead, it's wise to install only the PHP packages you need to your server. Don't forget to restart Apache after installing any new modules so that the changes can take effect!

Instructions for Fedora

Getting Started

First, log into your server via SSH as the root user.

We'll be using Yum to streamline the installation of this software, so we'll first want to make sure that Yum is up-to-date by running the following command:

yum update

Apache

        1. Run the following command to install the latest version of Apache:
          yum install httpd httpd-devel mod_ssl
        2. Next, we'll need to create a configuration file (vhost.conf) in the /etc/httpd/conf.d/ directory:
          touch /etc/httpd/conf.d/vhost.conf
        3. We'll then add the configuration details to this file using an editor such as VIM. Note that we're using the sample IP address 12.34.56.78 and the example domain mt-example.com. You'll want to replace these with your own IP address and domain name:

          Filename: /etc/httpd/conf.d/vhost.conf

          NameVirtualHost <strong>12.34.56.78</strong>:80
          
          
          <VirtualHost <strong>12.34.56.78:80>
          ServerAdmin webmaster@mt-example.com
          ServerName mt-example.com
          ServerAlias www.mt-example.com
          DocumentRoot /var/www/mt-example.com/html/
          ErrorLog /var/www/mt-example.com/logs/error.log
          CustomLog /var/www/mt-example.com/logs/access.log combined
          </VirtualHost>
        4. Create the directory to house the site. Make sure this matches the DocumentRoot specified in your vhost.conf file:
 mkdir -p /var/www/mt-example.com/{html,logs}
        1. Next, create a test page to make sure Apache is working correctly:
 echo '<html><head><title>ve-server1.com</title></head><body><h1>Hello, World!</h1></body></html>' > /var/www/ve-server1.com/html/index.html
        1. You'll also want to configure Apache to start at boot-up:
chkconfig --levels 235 httpd on 
        1. Finally, start Apache:
/etc/init.d/httpd start

You should now be able to see the "Hello World!" page by visiting your IP address.

MySQL

        1. Next, let's install MySQL to your server. Run the following command to begin the installation:
yum install mysql mysql-server mysql-devel
        1. Next, we'll configure the system startup links for MySQL. We want MySQL to start automatically whenever the system boots:
chkconfig --levels 235 mysqld on

/etc/init.d/mysqld start
        1. When MySQL starts up, it will warn you about various security issues. The following command will secure MySQL by walking you through setting your MySQL root password, removing anonymous users, disabling remote root access, and removing the test database. Remember to choose a strong password!
mysql_secure_installation

That's it! MySQL should now be installed to your server.

PHP

        1. Use this command to install PHP5 and the Apache PHP5 module, as well as most of the "common" php packages, including MySQL support:
 sudo yum install php php-common php-gd php-mcrypt php-pear php-pecl-memcache php-mhash php-mysql php-xml php-devel
        1. Next, restart Apache:
/etc/init.d/httpd restart
        1. To test out PHP, add a phpinfo page:
 echo '<?php phpinfo();' > /var/www/mt-example.com/html/phpinfo.php

You can then visit this page at your IP address or domain name (if active). For example, to view your PHP information using the sample IP of 12.34.56.78, you'd visit http://12.34.56.78/phpinfo.php. To be safe, you should delete the "phpinfo.php" file once you've verified that PHP is running.

        1. PHP is now installed! However, your applications may require additional modules. If you're looking for more PHP modules, you can run a search:
yum search php
        1. If you need to install other modules, you can install them as needed. This example includes PHP MySQL support:
yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-eaccelerator php-magickwand php-magpierss php-mapserver php-mbstring php-mcrypt php-mssql php-shout php-snmp php-soap php-tidy

To reduce overhead, it's wise to install only the PHP packages you need to your server. Don't forget to restart Apache after installing any new modules so that the changes can take effect!

Instructions

Instructions for Ubuntu 10.04

Getting Started

First, log into your server via SSH as the root user.

We'll be using apt-get to streamline the installation of this software, so we'll first want to make sure that your server is up-to-date by running the following commands:

apt-get update
apt-get upgrade

Installation

    • Run the following command to install Apache, MySQL, and PHP to your server:
apt-get install apache2 php5 libapache2-mod-php5 mysql-server mysql-client php5-mysql
  • You will be asked to set the MySQL password. Please choose a strong password.

Configure Apache

Now that you have your LAMP environment installed, you can add some VirtualHost entries. This will allow you to host multiple sites on the one IP address that comes with your (ve) Server.

    1. First, test that Apache was installed correctly by using your browser to visit your IP address or any domain that points to your server. You will see a default message if Apache was installed correctly.
    2. Next, edit your ports.conf file to include information for your specific IP. (In our example, we're using the IP address 12.34.56.78.)
vi /etc/apache2/ports.conf 

Filename: /etc/apache2/ports.conf

You should edit the line starting with NameVirtualHost to show your IP address instead of *:

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default
# This is also true if you have upgraded from before 2.2.9-3 (i.e. from
# Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and
# README.Debian.gz

NameVirtualHost 12.34.56.78:80
Listen 80

<IfModule mod_ssl.c>
# If you add NameVirtualHost *:443 here, you will also have to change
# the VirtualHost statement in /etc/apache2/sites-available/default-ssl
# to <VirtualHost *:443>
# Server Name Indication for SSL named virtual hosts is currently not
# supported by MSIE on Windows XP.
Listen 443
</IfModule>

<IfModule mod_gnutls.c>
Listen 443
</IfModule>
    1. Next, we'll edit your default VirtualHost file to reflect the change in port. Only the very first line is changing (although you can change other lines if you have a reason to do so):

Filename: /etc/apache2/sites-available/default

<VirtualHost 12.34.56.78:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

</VirtualHost>
    1. Optional: The default site will be what displays for your server if someone requests a domain, subdomain, or IP address that resolves to your server but doesn't have a distinct VirtualHost file. The content for this domain is stored in /var/www/. If you don't want to have a default website, you can disable it. Run these commands to disable the default site (only if desired):
a2dissite default
/etc/init.d/apache2 reload
    1. You will now create a custom sites-available VirtualHost file so you can add your own websites to the server. Our example will be for the mt-example.com domain:
vi /etc/apache2/sites-available/mt-example.com

Filename: /etc/apache2/sites-available/mt-example.com

<VirtualHost 12.34.56.78:80>
ServerName mt-example.com
ServerAlias www.mt-example.com
ServerAdmin webmaster@mt-example.com

DocumentRoot /var/www/mt-example.com/html

ErrorLog /var/www/mt-example.com/log/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/www/mt-example.com/log/access.log combined

</VirtualHost>
    1. The file you just edited references some paths that don't yet exist. Let's create them:
mkdir -p /var/www/mt-example.com/html

mkdir -p /var/www/mt-example.com/log
    1. For the sake of testing, you can also create a "Hello World!" page, such as in the example below:
echo -e '<html>\n<head>\n<title>Welcome to Apache!</title>\n</head>\n<body bgcolor="white" text="black">\n<center><h1>mt-example.com is working!</h1></center>\n</body>\n</html>' > /var/www/mt-example.com/html/index.html
    1. You now have an html and log directory for your site, and an index file. This means we're almost ready to go! Enable your site using the following command:
a2ensite mt-example.com,

TIP:

If you ever need to disable your sites, you can do so using the a2dissite command, followed by the site name.

    1. Lastly, reload Apache for the settings to take effect:
/etc/init.d/apache2 reload

Test PHP

The document root for your site should now be /var/www/mt-example.com/html/. Creating a simple phpinfo page will provide useful details about your PHP installation and confirm that PHP is working:

vi /var/www/mt-example.com/html/info.php

The file should read as follows:

Filename: /var/www/mt-example.com/html/info.php

<?php
phpinfo();
?>

Configure and Connect to MySQL

    • With MySQL installed, we recommend you run the following program to secure MySQL:
      mysql_secure_installation

      This will allow you to change the MySQL root password, remove anonymous user accounts, disable root logins outside of "localhost," and remove any test databases.

    • You can connect to MySQL as the root user using the following command:
mysql -u root -p
    • As the root user, you can exercise extensive control over your MySQL environment. The example below creates the database "woot," grants read/write access to the user "meh," and assigns that user the password "k1Tt7":
create database woot; grant all on woot.* to 'meh' identified by 'k1Tt7'; 

Instructions for Debian 5.0

Getting Started

First, log into your server via SSH as the root user.

We'll be using apt-get to streamline the installation of this software, so we'll first want to make sure that your server is up-to-date by running the following commands:

apt-get update
apt-get upgrade

Installation

      • Run the following command to install Apache, MySQL, and PHP to your server:
apt-get install apache2 php5 libapache2-mod-php5 mysql-server mysql-client php5-mysql
      • You will be asked to set the MySQL password. Please choose a strong password.

Configure Apache

Now that you have your LAMP environment installed, you can add some VirtualHost entries. This will allow you to host multiple sites on the one IP address that comes with your (ve) Server.

      1. First, test that Apache was installed correctly by using your browser to visit your IP address or any domain that points to your server. You will see a default message if Apache was installed correctly.
      2. Next, edit your ports.conf file to include information for your specific IP. (In our example, we're using the IP address 12.34.56.78.)
vi /etc/apache2/ports.conf 

Filename: /etc/apache2/ports.conf

You should edit the line starting with NameVirtualHost to show your IP address instead of *:

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default
# This is also true if you have upgraded from before 2.2.9-3 (i.e. from
# Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and
# README.Debian.gz

NameVirtualHost 12.34.56.78:80
Listen 80

<IfModule mod_ssl.c>
# If you add NameVirtualHost *:443 here, you will also have to change
# the VirtualHost statement in /etc/apache2/sites-available/default-ssl
# to <VirtualHost *:443>
# Server Name Indication for SSL named virtual hosts is currently not
# supported by MSIE on Windows XP.
Listen 443
</IfModule>

<IfModule mod_gnutls.c>
Listen 443
</IfModule>
      1. Next, we'll edit your default VirtualHost file to reflect the change in port. Only the very first line is changing (although you can change other lines if you have a reason to do so):

Filename: /etc/apache2/sites-available/default

<VirtualHost 12.34.56.78:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

</VirtualHost>
      1. Optional: The default site will be what displays for your server if someone requests a domain, subdomain, or IP address that resolves to your server but doesn't have a distinct VirtualHost file. The content for this domain is stored in /var/www/. If you don't want to have a default website, you can disable it. Run these commands to disable the default site (only if desired):
a2dissite default
/etc/init.d/apache2 reload
      1. You will now create a custom sites-available VirtualHost file so you can add your own websites to the server. Our example will be for the mt-example.com domain:
vi /etc/apache2/sites-available/mt-example.com

Filename: /etc/apache2/sites-available/mt-example.com

<VirtualHost 12.34.56.78:80>
ServerName mt-example.com
ServerAlias www.mt-example.com
ServerAdmin webmaster@mt-example.com

DocumentRoot /var/www/mt-example.com/html

ErrorLog /var/www/mt-example.com/log/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/www/mt-example.com/log/access.log combined

</VirtualHost>
      1. The file you just edited references some paths that don't yet exist. Let's create them:
mkdir -p /var/www/mt-example.com/html

mkdir -p /var/www/mt-example.com/log
      1. For the sake of testing, you can also create a "Hello World!" page, such as in the example below:
echo -e '<html>\n<head>\n<title>Welcome to Apache!</title>\n</head>\n<body bgcolor="white" text="black">\n<center><h1>mt-example.com is working!</h1></center>\n</body>\n</html>' > /var/www/mt-example.com/html/index.html
      1. You now have an html and log directory for your site, and an index file. This means we're almost ready to go! Enable your site using the following command:
a2ensite mt-example.com,

TIP:

If you ever need to disable your sites, you can do so using the a2dissite command, followed by the site name.

      1. Lastly, reload Apache for the settings to take effect:
/etc/init.d/apache2 reload

Test PHP

The document root for your site should now be /var/www/mt-example.com/html/. Creating a simple phpinfo page will provide useful details about your PHP installation and confirm that PHP is working:

vi /var/www/mt-example.com/html/info.php

The file should read as follows:

Filename: /var/www/mt-example.com/html/info.php

<?php
phpinfo();
?>

Configure and Connect to MySQL

      • With MySQL installed, we recommend you run the following program to secure MySQL:
        mysql_secure_installation

        This will allow you to change the MySQL root password, remove anonymous user accounts, disable root logins outside of "localhost," and remove any test databases.

      • You can connect to MySQL as the root user using the following command:
mysql -u root -p
      • As the root user, you can exercise extensive control over your MySQL environment. The example below creates the database "woot," grants read/write access to the user "meh," and assigns that user the password "k1Tt7":
create database woot; grant all on woot.* to 'meh' identified by 'k1Tt7'; 

Instructions for CentOS 5

Getting Started

First, log into your server via SSH as the root user.

We'll be using Yum to streamline the installation of this software, so we'll first want to make sure that Yum is up-to-date by running the following command:

yum update

Apache

        1. Run the following command to install the latest version of Apache:
          yum install httpd httpd-devel mod_ssl
        2. Next, we'll need to create a configuration file (vhost.conf) in the /etc/httpd/conf.d/ directory:
          touch /etc/httpd/conf.d/vhost.conf
        3. We'll then add the configuration details to this file using an editor such as VIM. Note that we're using the sample IP address 12.34.56.78 and the example domain mt-example.com. You'll want to replace these with your own IP address and domain name:

          Filename: /etc/httpd/conf.d/vhost.conf

          NameVirtualHost <strong>12.34.56.78</strong>:80
          
          
          <VirtualHost <strong>12.34.56.78:80>
          ServerAdmin webmaster@mt-example.com
          ServerName mt-example.com
          ServerAlias www.mt-example.com
          DocumentRoot /var/www/mt-example.com/html/
          ErrorLog /var/www/mt-example.com/logs/error.log
          CustomLog /var/www/mt-example.com/logs/access.log combined
          </VirtualHost>
        4. Create the directory to house the site. Make sure this matches the DocumentRoot specified in your vhost.conf file:
 mkdir -p /var/www/mt-example.com/{html,logs}
        1. Next, create a test page to make sure Apache is working correctly:
 echo '<html><head><title>ve-server1.com</title></head><body><h1>Hello, World!</h1></body></html>' > /var/www/ve-server1.com/html/index.html
        1. You'll also want to configure Apache to start at boot-up:
chkconfig --levels 235 httpd on 
        1. Finally, start Apache:
/etc/init.d/httpd start

You should now be able to see the "Hello World!" page by visiting your IP address.

MySQL

        1. Next, let's install MySQL to your server. Run the following command to begin the installation:
yum install mysql mysql-server mysql-devel
        1. Next, we'll configure the system startup links for MySQL. We want MySQL to start automatically whenever the system boots:
chkconfig --levels 235 mysqld on

/etc/init.d/mysqld start
        1. When MySQL starts up, it will warn you about various security issues. The following command will secure MySQL by walking you through setting your MySQL root password, removing anonymous users, disabling remote root access, and removing the test database. Remember to choose a strong password!
mysql_secure_installation

That's it! MySQL should now be installed to your server.

PHP

        1. Use this command to install PHP5 and the Apache PHP5 module, as well as most of the "common" php packages, including MySQL support:
 sudo yum install php php-common php-gd php-mcrypt php-pear php-pecl-memcache php-mhash php-mysql php-xml php-devel
        1. Next, restart Apache:
/etc/init.d/httpd restart
        1. To test out PHP, add a phpinfo page:
 echo '<?php phpinfo();' > /var/www/mt-example.com/html/phpinfo.php

You can then visit this page at your IP address or domain name (if active). For example, to view your PHP information using the sample IP of 12.34.56.78, you'd visit http://12.34.56.78/phpinfo.php. To be safe, you should delete the "phpinfo.php" file once you've verified that PHP is running.

        1. PHP is now installed! However, your applications may require additional modules. If you're looking for more PHP modules, you can run a search:
yum search php
        1. If you need to install other modules, you can install them as needed. This example includes PHP MySQL support:
yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-eaccelerator php-magickwand php-magpierss php-mapserver php-mbstring php-mcrypt php-mssql php-shout php-snmp php-soap php-tidy

To reduce overhead, it's wise to install only the PHP packages you need to your server. Don't forget to restart Apache after installing any new modules so that the changes can take effect!

Instructions for Fedora 12

Getting Started

First, log into your server via SSH as the root user.

We'll be using Yum to streamline the installation of this software, so we'll first want to make sure that Yum is up-to-date by running the following command:

yum update

Apache

        1. Run the following command to install the latest version of Apache:
          yum install httpd httpd-devel mod_ssl
        2. Next, we'll need to create a configuration file (vhost.conf) in the /etc/httpd/conf.d/ directory:
          touch /etc/httpd/conf.d/vhost.conf
        3. We'll then add the configuration details to this file using an editor such as VIM. Note that we're using the sample IP address 12.34.56.78 and the example domain mt-example.com. You'll want to replace these with your own IP address and domain name:

          Filename: /etc/httpd/conf.d/vhost.conf

          NameVirtualHost <strong>12.34.56.78</strong>:80
          
          
          <VirtualHost <strong>12.34.56.78:80>
          ServerAdmin webmaster@mt-example.com
          ServerName mt-example.com
          ServerAlias www.mt-example.com
          DocumentRoot /var/www/mt-example.com/html/
          ErrorLog /var/www/mt-example.com/logs/error.log
          CustomLog /var/www/mt-example.com/logs/access.log combined
          </VirtualHost>
        4. Create the directory to house the site. Make sure this matches the DocumentRoot specified in your vhost.conf file:
 mkdir -p /var/www/mt-example.com/{html,logs}
        1. Next, create a test page to make sure Apache is working correctly:
 echo '<html><head><title>ve-server1.com</title></head><body><h1>Hello, World!</h1></body></html>' > /var/www/ve-server1.com/html/index.html
        1. You'll also want to configure Apache to start at boot-up:
chkconfig --levels 235 httpd on 
        1. Finally, start Apache:
/etc/init.d/httpd start

You should now be able to see the "Hello World!" page by visiting your IP address.

MySQL

        1. Next, let's install MySQL to your server. Run the following command to begin the installation:
yum install mysql mysql-server mysql-devel
        1. Next, we'll configure the system startup links for MySQL. We want MySQL to start automatically whenever the system boots:
chkconfig --levels 235 mysqld on

/etc/init.d/mysqld start
        1. When MySQL starts up, it will warn you about various security issues. The following command will secure MySQL by walking you through setting your MySQL root password, removing anonymous users, disabling remote root access, and removing the test database. Remember to choose a strong password!
mysql_secure_installation

That's it! MySQL should now be installed to your server.

PHP

        1. Use this command to install PHP5 and the Apache PHP5 module, as well as most of the "common" php packages, including MySQL support:
 sudo yum install php php-common php-gd php-mcrypt php-pear php-pecl-memcache php-mhash php-mysql php-xml php-devel
        1. Next, restart Apache:
/etc/init.d/httpd restart
        1. To test out PHP, add a phpinfo page:
 echo '<?php phpinfo();' > /var/www/mt-example.com/html/phpinfo.php

You can then visit this page at your IP address or domain name (if active). For example, to view your PHP information using the sample IP of 12.34.56.78, you'd visit http://12.34.56.78/phpinfo.php. To be safe, you should delete the "phpinfo.php" file once you've verified that PHP is running.

        1. PHP is now installed! However, your applications may require additional modules. If you're looking for more PHP modules, you can run a search:
yum search php
        1. If you need to install other modules, you can install them as needed. This example includes PHP MySQL support:
yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-eaccelerator php-magickwand php-magpierss php-mapserver php-mbstring php-mcrypt php-mssql php-shout php-snmp php-soap php-tidy

To reduce overhead, it's wise to install only the PHP packages you need to your server. Don't forget to restart Apache after installing any new modules so that the changes can take effect!