This tutorial will explain how to install a development environment LAMP. But what is that LAMP? LAMP is short for Linux + Apache2 + PHP5 + MySQL, that is, an environment to write scripts, maintain or set up sites made or written in PHP with MySQL on an Apache server.
Getting your hands on the matter ...
We install Apache2
server@host:# apt-get install apache2 apache2-doc
Basic use of Apache:
server@host:# /etc/init.d/apache2 {start|stop|restart|reload|force-reload}
Now, how do we tell Apache2 to use the modules we installed for it?
Editing /etc/apache2/apache2.conf and adding:
<IfModule dir_module>
DirectoryIndex index.html index.htm index.shtml index.cgi index.php index.php3 index.pl index.xhtml
</IfModule>
Add modules:
Can be found in / usr / lib / apache2 / modules /
For example: Mod_Rewrite overwrite urls to make them more user friendly.
Add in /etc/apache2/apache2.conf:
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
A more elegant way can be, from the command terminal enable it with the following command:
server@host:# a2enmod rewrite
And then restart Apache:
server@host:# /etc/init.d/apache2 restart
PHP5 Installation / Configuration
server@host:# apt-get install libapache2-mod-php5 php5 php5-common php5-curl php5-dev php5-gd php5-idn php-pear php5-imagick php5-imap php5-json php5-mcrypt php5-memcache php5-mhash php5-ming php5-mysql php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
Some changes to PHP 5
En /etc/php5/apache2/php.ini:
Upload files to server [size]:
upload_max_filesize = 8M
Memory usage:
memory_limit = 32M
Upload files, POST method:
post_max_size = 8M
Start, restart PHP 5?
PHP 5 runs on the system as an Apache2 module, so if we do some configuration in PHP5 just by restarting Apache, the changes made are applied.
MySQL Installation / Configuration
server@host:# apt-get install mysql-server
During the installation you will be asked for the password for the MySQL root user, for security reasons, try to make it different from the root password of the system.
Basic usage of MySQL:
server@host:# /etc/init.d/mysql {start|stop|restart|reload|force-reload|status}
And in the settings [/etc/mysql/my.cnf, line 71 approximately] we enable the logs uncommenting:
log /var/log/mysql/mysql.log
And then restarting MySQL for the changes to take effect ...
server@host:# /etc/init.d/mysql restart
Installation / Configuration of PHPMyAdmin
server@host:# apt-get install phpmyadmin
And the configuration comes in the config.inc.php file, which is not there, but we will create it with the following content:
<?php
$cfg['blowfish_secret'] = 'phpmyadmin';
$i = 0;
$i++;
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['extension'] = 'mysql';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['auth_type'] = 'cookie';
?>
Virtualhosting
It is a method that allows the publication of several websites [with several different domain names] under the same IP address. Allows you to share memory and processor cycles [Hz] more efficiently.
Apache2 Commands for VirtualHosting:
- a2ensite: Activate a website. The configs must be in / etc / apache2 / sites-available /
- a2dissite: Deactivate a website.
- a2enmod: Activates an apache module available in / etc / apache2 / mods-available /
- a2dismod: Deactivate a module.
Create a virtualhost
We create the configuration file of the VirtualHost:
server@host:# cd /etc/apache2/sites-available/
server@host:/etc/apache2/sites-available# touch blog.example.com
We create the folder where the website will be ...
server@host:# mkdir -p /var/www/blog/
Blog.example.com configuration:
<VirtualHost *:80>
ServerAdmin admin@blog.example.com
ServerName blog.example.com
DocumentRoot /var/www/blog/
# HTML documents, with indexing.
<Directory />
Options +Includes
</Directory>
</VirtualHost>
We enable:
server@host:# a2ensite blog.example.com
And then? Sure, the happy ending:
server@host:# /etc/init.d/apache2 restart
Nota: We should talk to our network administrator, if we are better, to add an A record in DNS that points to our IP with the name "blog”. This must be done to redirect all DNS polls from blog.example.com to our PC.
Then we just write in our browser:
http://blog.example.com
And we will have access to the site in question.
It only remains to install a WordPress or a Drupal on this virtualhost, if we are going to develop, from scratch or a framework.
That's all, see you at another time to continue installing / configuring services on GNU / Linux systems.