LAMP

Da Blah Hacklab, GNU/Linux e software libero.

Indice

Linux Apache MySql Php

Questa guida raccoglie informazioni derivate da altri siti e serve ad installare un ambiente di sviluppo web che si basa su:

    GNU/Linux: il sistema operativo
    Apache: il web server
    MySQL multithreaded, multi-user, SQL database management system
    PHP (a volte anche Perl o Python): linguaggio di scripting

Storia dei Web Server

Nel 1989 Tim Berners-Lee ha proposto un nuovo progetto per il suo datore di lavoro il CERN, con l'obiettivo di facilitare lo scambio di informazioni tra gli scienziati utilizzando un sistema ipertestuale. Il progetto porta Berners-Lee a scrivere due programmi nel 1990:

    - un browser chiamato WorldWideWeb;
    - il primo web server  del mondo, più tardi chiamato httpd del CERN, che girava su NeXTSTEP 

(NeXTSTEP era il computer prodotto dalla società che fondò Steve Jobs dopo essere stato licenziato dalla Apple e successivamente inglobata in quest'ultima. Ancora ora le classi dell'objective C, il linguaggio con cui è programmato il Mac e l'iPhone, iniziano con la sigla NS).

Tra il 1991 e il 1994, la semplicità e l'efficacia delle prime tecnologie utilizzate per navigare e scambiare dati attraverso il World Wide Web ha contribuito al porting verso molti altri sistemi operativi e alla diffusione del loro utilizzo tra gruppi di persone socialmente eterogeneo, prima in organizzazioni scientifiche, poi in università e, infine, nel settore industriale.

Nel 1994 Tim Berners-Lee ha deciso di costituire il World Wide Web Consortium (W3C) per regolare l'ulteriore sviluppo delle molte tecnologie coinvolte (HTTP, HTML, ecc) attraverso un processo di normalizzazione.

Mercato (Dati di Luglio 2011)

Google Web Server: Custom Linux-based Web server che Google usa per i suoi servizi online; Google asserisce che non è basato su Apache. Lo usa Google e da solo arriva a circa l'8% dei siti web.

nginx (si pronuncia “engine-x”): è un Web server incentrato nell'elevata concorrenzialità, alte performance e uso di poca memoria. Ha licenza BSD-like e gira sui principali OS. Nginx fornisce rapidamente contenuti statici con l'utilizzo efficiente delle risorse di sistema. Nginx usa un approccio “asynchronous event-driven” per gestire le richieste che fornisce performance più prevedibili sotto carico, in contrasto al modello dell'Apache HTTP server che usa un approccio “threaded” o “process-oriented” per gestire le richieste. Negli ultimi anni è in crescita e serve circa il 10% dei siti web.

Internet Information Services (IIS): - formalmente chiamato Internet Information Server - è una applicazione web server e una serie di moduli di estensione caratteristica creato da Microsoft per l'utilizzo con Microsoft Windows. E' il server web più utilizzato dopo Apache HTTP Server (12% di share). E' usato sopratutto dalle grandi aziende o corporation. IIS 7.5 supporta i protocolli HTTP, HTTPS, FTP, FTPS, SMTP e NNTP. Essa è parte integrante della famiglia di prodotti Windows Server, così come alcune edizioni di Windows XP, Windows Vista e Windows 7. IIS non è attivata per impostazione predefinita quando Windows è installato.

The Apache HTTP Server: comunemente chiamato solo Apache, e un software web server che si è distinto per il ruolo chiave nella crescita iniziale del World Wide Web. Nel 2009 divenne il primo server web a superare la pietra miliare dei 100 milioni di siti. Apache è stata la prima alternativa valida al “Netscape Communications Corporation web server” (attualmente denominata Oracle iPlanet web Server), e si è evoluto per rivaleggiare con altri web server in termini di funzionalità e prestazioni. Tipicamente Apache viene eseguito su un sistema operativo Unix-like. Apache è sviluppato e mantenuto da una comunità aperta di sviluppatori sotto l'egida della Apache Software Foundation. L'applicazione è disponibile per una vasta gamma di sistemi operativi, inclusi Linux, Mac OS X, Microsoft Windows. Rilasciato sotto licenza Apache, Apache è software open source. Dall'aprile 1996 Apache è stato il più popolare software del server HTTP in uso. A partire dal maggio 2011 è stato stimato che Apache serva il 60% di tutti i siti web.

Installazione su Debian

Installazione

Since Apache and MySQL servers must be installed prior to the PHP installation, I recommend installing the triad in this order: MySQL, Apache, PHP. This tutorial is based on a machine runnning debian/linux.

In questa guida viene usato aptitude, è possibile usare apt-get con modalità similare. Le operazioni vanno eseguite da root.

Installing MySQL 5.0

First we install MySQL 5.0 like this:

    aptitude install mysql-server mysql-client

You will be asked to provide a password for the MySQL root user - this password is valid for the user root@localhost as well as root@dev.example.com, so we don't have to specify a MySQL root password manually later on:

   New password for the MySQL "root" user: <-- yourrootsqlpassword
   Repeat password for the MySQL "root" user: <-- yourrootsqlpassword

Installing Apache2

Apache2 is available as a Debian package, therefore we can install it like this:

    aptitude install apache2

Now direct your browser to http://localhost, and you should see the Apache2 placeholder page (It works!)

Apache's default document root is

    /var/www 

on Debian, and the configuration file is

    /etc/apache2/apache2.conf 

Additional configurations are stored in subdirectories of the /etc/apache2 directory such as /etc/apache2/mods-enabled (for Apache modules), /etc/apache2/sites-enabled (for virtual hosts), and /etc/apache2/conf.d.

Installing PHP5

We can install PHP5 and the Apache PHP5 module as follows:

    aptitude install php5 libapache2-mod-php5

We must restart Apache afterwards:

    /etc/init.d/apache2 restart

As you see, PHP5 is working, and it's working through the Apache 2.0 Handler, as shown in the Server API line. If you scroll further down, you will see all modules that are already enabled in PHP5. MySQL is not listed there which means we don't have MySQL support in PHP5 yet.

Il file php.ini relativo a PHP 5 su Debian lo troviamo in

    /etc/php5/apache2/php.ini

e sono richiesti privilegi di root per poterlo modificare.

Getting MySQL Support In PHP5

To get MySQL support in PHP, we can install the php5-mysql package. It's a good idea to install some other PHP5 modules as well as you might need them for your applications. You can search for available PHP5 modules like this:

    aptitude search php5

Pick the ones you need and install them like this:

    aptitude install php5-mysql php5-curl php5-gd 
    php5-idn php-pear php5-imagick php5-imap php5-mcrypt  
    php5-memcache php5-mhash php5-ming php5-ps php5-pspell 
    php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc 
    php5-xsl php5-json

Now restart Apache2:

    /etc/init.d/apache2 restart

Now reload http://localhost/info.php in your browser and scroll down to the modules section again. You should now find lots of new modules there, including the MySQL module

phpMyAdmin

phpMyAdmin is a web interface through which you can manage your MySQL databases. It's a good idea to install it:

    aptitude install phpmyadmin

You will see the following question:

Web server to reconfigure automatically: <-- apache2 (Select apache2 with Space and then hit Return) Afterwards, you can access phpMyAdmin under http://localhost/phpmyadmin/

Permessi di scrittura

Per abilitare il supporto alla scrittura su disco da parte del web server è necessario cambiare i permessi della cartella in cui sono ospitati i file.

Cambio permessi su cartella (l'utente e il gruppo di default con cui funziona apache è www-data):

    chown -R www-data:www-data /var/www

Virtual Hosting

Virtual Hosting allow web servers to host more than one website on a sing machine. allows you to access to your local repository using addresses such as http://dev.mysite.com instead of http://localhost/~myuser/myproject/ :) .

When starting apache will look for files in /etc/apache2/sites-enabled/. Lets go there and see what is in.

    cd /etc/apache2/sites-enabled/
    ls -l

Well, this only links to the file in directory /etc/apache2/sites-available/ . You might wonder what is the point in doing such. Well, this simply allows you, mainly when you are using your box as a web server, to: Have a simple main configuration file Do be able to edit or create a new host by creating/editing a file from /etc/apache2/sites-available/ In case your web server doesn't restart because of misconfiguration, you can simply remove the link from the file in /etc/apache2/sites-enabled/ pointing to the malformed file in /etc/apache2/sites-available/

Now let say you want to be able to map the domain name dev.example.com to you local machine, using the code file in /home/myuser/public_html/example.com/. While in /etc/apache2/sites-available, create a new file (let say example.com.conf)

    nano example.com.conf

Now add the following lines (minimal configuration):

<VirtualHost *:80> ServerAdmin webmaster@localhost ServerName dev.example.com ServerAlias www.dev.example.com DocumentRoot /home/blah/public_html/example </VirtualHost>

You can use a debian specific command to enable a new virtual host simply type: a2ensite mysiteavailable-site to disable a virtual host: a2dissite mysiteavailable-site

where mysiteavailable-site is the name of the virtual hos you want to enable/disable, so in out example: example.com.conf Otherwise we specified a new host to apache but it is not yet linked to the repertory where apache actually look for virtual hosts. Let go to:

    cd /etc/apache2/sites-enabled/

and create a link to the file we just created:

    ln -s /etc/apache2/sites-available/example.com.conf example.com.conf
   

Now apache is almost ready to restart, but before doing so, we must inform our linux system that dev.example.com and www.dev.example.com are not to be looked for on the net, but on the local machine instead. To do so, simply edit /etc/hosts and add the new host names at the end of the line beginning by 127.0.0.1, which is localhost. In the end, your file should look like:

    127.0.0.1 localhost.localdomain localhost dev.example.com www.dev.example.com

And now we are done, simply reload apache:

    /etc/init.d/apache2 reload

Web Based file explorer

Dopo aver instllato un server LAMP su VirtualBox, senza interfaccia grafica su un server M$ Windows XP a cui accedo tramite VNC, mi sono chiesto come fare per gestire in maniera semplice i file dentro al server, senza stare lì a fare mille mila passaggi, o installare un server FTP ;-) Così ho trovato questo progetto carino che implementa un Gestore file via Web:

    [http://sourceforge.net/projects/quixplorer/ QuiXplorer

Download e installazione

Ora per installarlo andiamo sulla pagina di sourceforge e clicchiamo su Download, si aprirà una pagina con un conto alla rovescia. Quando appare il pop-up che vi chiede di salvare il file fate Annulla. Cliccate col destro su "direct link" e copiate l'indirizzo.

Ora che abbiamo l'indirizzo e lo scompattatore, possiamo fare il download del file tramite wget:

    cd /var/www
    ATTENZIONE: bisogna aggiungere un apice (') prima e dopo l'indirizzo, come da esempio
    wget 'http://downloads.sourceforge.net/project/quixplorer/unstable/2.4.1%20beta/quixplorer-2.4.1beta.zip?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fquixplorer%2F&ts=1326543993&use_mirror=ignum' -O quixplorer.zip     

Se non lo avete serve anche il programmino per scompressare il file, quindi diamo:

    aptitude install unzip

Per installarlo basta scompattare la cartella dentro alla home directory del nostro web server:

    unzip quixplorer.zip

Bisogna ambiare il proprietario dei file mettendo www-data (vedi capitolo 2.1.6) e poi modificare il file di configurazione che trovate nella cartella (nascosta, perchè ha il "." all'inizio del nome)

    .config/conf.php

I parametri da cambiare sono:

    // la home directory del filemanager: (usare '/', non '\' o '\\', non terminare con '/')
    $GLOBALS["home_dir"] = "/var/www";
    // l'url che corrisponde alla home directory: (non aggiungete la '/' alla fine)
    $GLOBALS["home_url"] = "http://localhost";



Fine. Guida by Nicola Danese.

Strumenti personali