This guide provides step-by-step instructions for installing a full-featured LAMP stack on any Linux OS (almost same on all variants:
Install and Configure the Apache Web Server
Configure Name based Virtual HostsInstalling and Configuring MySQL
Installing and Configuring PHP
Before you begin installing and configuring the components mentioned in this guide, make sure you’ve chose your FQDN hostname for your Server. These are the commands to make sure it is set properly:
hostname hostname -f
If you are using Red Hat or Fedora Linux:
Use redhat-config-network GUI tool. Type following command and click on DNS tab > Setup hostname and domain name
On other hand you can edit a text file. Find out and set up the value for HOSTNAME in the file /etc/sysconfig/network:
# vi /etc/sysconfig/network
Users of Debian:
# vi /etc/hostname
Debian, Suse and other Linux distro support GUI tool called network-admin. Type following command and click on DNS tab > Setup hostname and domain name:
Install and Configure the Apache Web Server
The Apache Web Server is a very popular choice for serving web pages. While many alternatives have appeared in the last few years, Apache remains a powerful option that I recommend for most uses. (My Study @ http://www.netcraft.com)
To install the current version of the Apache web server (in the 2.x series) use the following command:
yum update yum install httpd
The configuration for Apache is contained in the httpd.conf file, which is located at: /etc/httpd/conf/httpd.conf. Make Backup for Safety Reason(Optional)
cp /etc/httpd/conf/httpd.conf ~/httpd.conf.backup
By default all files ending in the .conf extension in /etc/httpd/conf.d/ are treated as Apache configuration files, and I recommend placing your non-standard configuration options in files in these directories. Regardless how you choose to organize your configuration files, making regular backups of known working states is highly recommended.
Now configure virtual hosting so that we can host multiple domains (or subdomains) with the server. These websites can be controlled by different users, or by a single user, as you prefer.
I suggest that you combine all configuration on virtual hosting into a single file called vhost.conf located in the /etc/httpd/conf.d/ directory. Open this file in your favorite text editor, and begin by setting up virtual hosting.
Configure Name based Virtual Hosts
There are different ways to set up Virtual Hosts, however we recommend the method below. By default, Apache listens on all IP addresses available to it.
Now create virtual host entries for each site that we need to host with this server. Here are two examples for sites at “shery.com” and “shery.net”.
NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin firstname.lastname@example.org ServerName shery.com ServerAlias www.shery.com DocumentRoot /srv/www/shery.com/public_html/ ErrorLog /srv/www/shery.com/logs/error.log CustomLog /srv/www/shery.com/logs/access.log combined </VirtualHost> <VirtualHost *:80> ServerAdmin email@example.com ServerName shery.net ServerAlias www.shery.net DocumentRoot /srv/www/shery.net/public_html/ ErrorLog /srv/www/shery.net/logs/error.log CustomLog /srv/www/shery.net/logs/access.log combined </VirtualHost>
- All of the files for the sites that you host will be located in directories that exist underneath /srv/www You can symbolically link these directories into other locations if you need them to exist in other places.
- ErrorLog and CustomLog entries are suggested for more fine-grained logging, but are not required. If they are defined (as shown above), the logs directories must be created before you restart Apache.
Before you can use the above configuration you’ll need to create the specified directories. For the above configuration, you can do this with the following commands:
mkdir -p /srv/www/shery.com/public_html mkdir /srv/www/shery.com/logs mkdir -p /srv/www/shery.net/public_html mkdir /srv/www/shery.net/logs
After you’ve set up your virtual hosts, issue the following command to run Apache for the first time:
Assuming that you have configured the DNS for your domain to point to your IP address, Virtual hosting for your domain should now work. Remember that you can create as many virtual hosts with Apache as you need.
If you want to run Apache by default when the system boots, which is a typical setup, execute the following command:
/sbin/chkconfig --levels 235 httpd on
Use the chkconfig command to setup runlevels as needed.
Anytime you change an option in your vhost.conf file, or any other Apache configuration remember to reload the configuration with the following command:
Installing and Configuring MySQL
MySQL is a relational database management system (RDBMS) and is a popular component in contemporary web development tool-chains. It is used to store data for many popular applications, including WordPress, Joomla, VBulletin and Drupal.
The first step is to install the mysql-server package, which is accomplished by the following command:
yum install mysql-server
If you want to run MySQL by default when the system boots, which is a typical setup, execute the following command:
/sbin/chkconfig --levels 235 mysqld on
Now you can start the mysql daemon (mysqld) with the following command (as root):
At this point MySQL should be ready to configure and run. While you shouldn’t need to change the configuration file, note that it is located at /etc/my.cnf for future reference.
After installing MySQL, it’s recommended that you run mysql_secure_installation, a program that helps secure MySQL. While running mysql_secure_installation, you will be presented with the opportunity to change the MySQL root password, remove anonymous user accounts, disable root logins outside of localhost, and remove test databases. It is recommended that you answer yes to these options. If you are prompted to reload the privilege tables, select yes. Run the following command to execute the program:
Next, create a database and grant your users permissions to use databases. First, log in to MySQL:
mysql -u root -p
Enter MySQL’s root password, and you’ll be presented with a prompt where you can issue SQL statements to interact with the database.
To create a database and grant your users permissions on it, issue the following command. Note, the semi-colons (;) at the end of the lines are crucial for ending the commands. Your command should look like this:
create database wordpress; grant all on wordpress.* to 'shery' identified by 'test123+';
In the example above, wordpress is the name of the database, shery is the username, and test123+ password. Note that database user names and passwords are only used by scripts connecting to the database, and that database user account names need not (and perhaps should not) represent actual user accounts on the system.
With that completed you’ve successfully configured MySQL and you may now pass these database credentials on to your users. To exit the MySQL database administration utility issue the following command:
With Apache and MySQL installed you are now ready to move on to installing PHP to provide scripting support for your web pages.
Installing and Configuring PHP
PHP makes it possible to produce dynamic and interactive pages using your own scripts and popular web development frameworks. Furthermore, many popular web applications like WordPress are written in PHP. If you want to be able to develop your websites using PHP, you must first install it.
Issue the following command:
yum install php php-pear
Once PHP5 is installed we’ll need to tune the configuration file located in /etc/php.ini to enable more descriptive errors, logging, and better performance. These modifications provide a good starting point if you’re unfamiliar with PHP configuration.
Make sure that the following values are set, and relevant lines are uncommented (comments are lines beginning with a semi-colon (;)):
error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR display_errors = Off log_errors = On error_log = /var/log/php.log max_execution_time = 300 memory_limit = 64M register_globals = Off
If you need support for MySQL in PHP, then you must install the php5-mysql package with the following command:
yum install php-mysql