Tuncay Sahin

ICT Engineer | Docent ICT & Trainer

This document describes the entire process of installing and configuring a LAMP server. LAMP stack is a group of open source software used to get websites with databases running.

Install Linux

First get a server with already running Linux. This document is based on CentOS. The linux installation part is taken care of. Here is how to install the rest.

Login with SSH root privileges to your Linux server and follow the instructions below.

Install Apache

Apache is a free open source software which runs web servers.

  • To install apache

yum install httpd

  • To start Apache

service httpd start

systemctl start httpd

  • Set Apache to automatically start on boot

chkconfig httpd on

systemctl enable httpd

 

Install MySQL

MySQL is a database management system.

  • To install MySQL

yum install mysql-server

To start MySQL

service mysqld start

systemctl start mysqld

  • To start MySQL automatically on system startup

chkconfig mysqld on

systemctl enable mysqld

  • To set a password for the MySQL root user.

mysqladmin -u root password ‘new-password’

  • Or run wizard to set a MySQL root password. This will guide you through a wizard. Say Yes to all the options.

/usr/bin/mysql_secure_installation

 

Install PHP

PHP is an open source web scripting language that is widely used to build dynamic webpages.

  • To install PHP

yum install php php-mysql

PHP Modules

PHP also has a variety of useful libraries and modules that you can add onto your server.

  • Show the available libraries

yum search php-

  • For more information about a module

yum info name of the module

  • To install a module

yum install name of the module

You can install multiple libraries at once by separating the name of each module with a space.

PHP-info page on your Apache Server

Although LAMP is installed on your virtual server, we can still take a look and see the components online by creating a quick php info page.

  • To set this up, first create a new file

vi /var/www/html/info.php

  • Press Insert-key  and type the following code

<?php

phpinfo();

?>

  • Save and exit by pressing the Escape-key

!q

  • Restart apache to take changes effect

service httpd restart

  • Finish up by visiting your php-info page

http://your_server_ip/info.php

 

To Install the LAMP stack at once

 

  • Run the following command

yum groupinstall “Web Server” “PHP Support” “MySQL Database server” “MySQL Database client”

  • Add PHP-MySQL support

yum install php-mysql

Configure iptables (firewall)

Make sure the firewall does not block access to port 80

Edit the iptables config file

vi /etc/sysconfig/iptables

Allow http traffic

Below the :OUTPUT ACCEPT [0:0] line, add

-A INPUT -m state –state NEW -p tcp –dport 80 -j ACCEPT

Restart firewall

service iptables restart

Install phpmyadmin (optional)

phpMyAdmin is a powerful tool for manipulating MySQL databases.

Change directory to your documentroot

cd /var/www/html

Download phpMyAdmin

wget http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/4.0.1/phpMyAdmin-4.0.1-english.zip?r=http%3A%2F%2Fwww.phpmyadmin.net%2Fhome_page%2Fdownloads.php&ts=1369351562&use_mirror=heanet

Unzip phpMyAdmin

unzip phpMyAdmin-3.5.6-english.zip

Rename directory

mv phpMyAdmin-3.5.6-english phpmyadmin

Remove the zip-file

rm -f phpMyAdmin-3.5.6-english.zip

Now you can browse to:

http:///phpmyadmin

Add blowfish_secret for security

cd phpmyadmincp config.sample.inc.php config.inc.php

vim config.inc.php

Add a secret key to $cfg[‘blowfish_secret’] so it looks like below:

$cfg[‘blowfish_secret’] = ‘your-secret-key’;

Add virtual hosts to Apache

Virtual hosts allow multiple web sites to be served from a single Apache installation.

The virtual hosts can be added to the end of the Apache configuration file (/etc/httpd/conf/httpd.conf).

Here is an example configuration with two web hosts:

# Ensure that Apache listens on port 80 and name-based virtual hosting is enabled.
Listen 80
NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.domain1.com
# Other directives here
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/example2
ServerName www.domain2.org
# Other directives here
</VirtualHost>

Setting permissions for PHP sites

Secure your site by setting the correct permissions on your DocumentRoot:

Set Apache user as the owner for your DocumentRoot

chown -R apache:apache /var/www/html/yoursite

Modify permissions

chmod -R 400 /var/www/html/yoursite

chmod -R a+X /var/www/html/yoursite

 

In some cases your PHP site requires write access in some folders. For example WordPress sites requires write access into the /wp-content folder to could install plugings, themes or updates.

Provide write permissions to WordPress

chmod -R 775 /var/www/html/yoursite/wp-content

Configure PHP (optional)

By default PHP is preconfigured, but you may customize some setttings.

Edit the PHP configuration file

vi /etc/php.ini

Increase the maximum upload file size

upload_max_filesize = 128M

post_max_size restriction

post_max_size = 128M

Increase the memory limit

memory_limit = 256M

Increase the maximum execution and input time

max_execution_time = 300

maximum time to wait for POST and GET data

max_input_time = 300

Restart httpd to activate the changes

service httpd restart

Meer informatie

Voor meer informatie of voor een persoonlijk adviesgesprek kunt u altijd vrijblijvend contact met mij opnemen.

E-Mail

info@tuncaysahin.nl