(ve):Install LAMP on CentOS

  • This page was last modified on March 8, 2011, at 11:48.
The (mt) Community Wiki is a collaborative project. Any (mt) Media Temple customer or employee may contribute. Not all articles and/or content have been tested for accuracy by (mt) Media Temple.

For officially moderated and tested articles, be sure to visit our KnowledgeBase.

From (mt) Community Wiki

Contents

Install

Log in to your (ve) server as root or another user with sudo privileges:

ssh root@example.com

Make sure your server is up to date:

yum update

Apache

Install the latest version of Apache

yum install httpd httpd-devel mod_ssl

For this example, the IP is 12.34.56.78 and the domain is ve-server1.com. Be sure to change these values to yours. The NameVirtualHost line is your IP address which you can easily find in your AccountCenter Server Guide.

  • Next we need to create a vhost.conf file in /etc/httpd/conf.d/:
touch /etc/httpd/conf.d/vhost.conf
  • Then we need to add the following code:
/etc/httpd/conf.d/vhost.conf


NameVirtualHost 12.34.56.78:80


<VirtualHost 12.34.56.78:80>
ServerAdmin webmaster@ve-server1.com
ServerName ve-server1.com
ServerAlias www.ve-server1.com
DocumentRoot /var/www/ve-server1.com/html/
ErrorLog /var/www/ve-server1.com/logs/error.log
CustomLog /var/www/ve-server1.com/logs/access.log combined
</VirtualHost>
  • Now we will create the directory for the site:
mkdir -p /var/www/ve-server1.com/{html,logs}
  • We will create a test file to make sure things are 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

Then let's configure Apache to start at boot-up.

chkconfig --levels 235 httpd on

Now start Apache:

/etc/init.d/httpd start

We should now be able to point our browser to the IP address to see the default "Hello, World!" page: IMAGE GOES HERE

MySQL

Run this command to install MySQL:

yum install mysql mysql-server mysql-devel

Then we'll configure the system startup links for MySQL. We want MySQL to start automatically whenever the system boots and start the MySQL server:

chkconfig --levels 235 mysqld on
/etc/init.d/mysqld start

When MySQL starts up, it will warn you about security issues. The following command will walk you through setting your MySQL root password, removing anonymous users, disabling remote root access, and removes the test database. Remember to choose a strong password. Please read our Strong password guide.

mysql_secure_installation

PHP

Use this to install PHP5 and the Apache PHP5 module:

sudo yum install php php-common php-gd php-mcrypt php-pear php-pecl-memcache php-mhash php-mysql php-xml php-devel

This will also install most of the "common" php packages, including MySQL support.

Then restart Apache:

/etc/init.d/httpd restart

To test out php, add a phpinfo page

echo '<?php phpinfo();' > /var/www/ve-server1.com/html/phpinfo.php

Visiting http://IP_ADDRESS/phpinfo.php will display the phpinfo page. Once everything is running, you should delete this page. IMAGE HERE.

  • If you're looking for more PHP modules you can run a search:
yum search php

You can install whichever modules you wish, including PHP MySQL support, like this:

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

However, you should only install the packages you need to reduce overhead.

Once again, restart Apache:

/etc/init.d/httpd restart


Security

Follow these articles to make your server more secure: