Pas 1: baixada/instal·lació d'Apache 2.4
Pas 2: baixada/instal·lació de MySQL
Pas 4: inici/atura de la pila LAMP
Conclusió
La compilació de la vostra pròpia pila LAMP us permet utilitzar les últimes versions d'Apache, MySQL i PHP. Amb el gestor de paquets CentOS 6, rebeu Apache 2.2, MySQL 5.1 i PHP 5.3. El gestor de paquets només instal·la actualitzacions de seguretat de l'equip de CentOS.
Com a administrador del sistema, sabeu que mantenir el programari actualitzat és clau. I amb el vostre servidor web orientat a Internet, heu d'assegurar-vos que el programari del servidor web estigui actualitzat per evitar vulnerabilitats.
Aquest article us ensenya com compilar la vostra pròpia pila LAMP. Cada una de les ordres s'explicarà amb el format següent.
# Commands will be listed here
An explanation of the commands will be stated here.
Pas 1: baixada/instal·lació d'Apache 2.4
Per a aquest article, utilitzarem un mirall preestablert; però si ho desitgeu, podeu utilitzar un altre mirall de la pàgina de mirall d'Apache amb una trucada del vostre VPS.
curl -q -s apache.org/dyn/closer.cgi > /tmp/closer
sed -e 151b -e '$!d' /tmp/closer
The curl command sends an HTTP request to the URL, and retrieves its contents. We redirect the output to /tmp/closer, and then the sed command cuts it down to something you can read.
Veureu un enllaç mirall contingut a la secció. Només heu de substituir els enllaços especificats en aquest article per aquest mirall.
Baixeu la font a Apache 2.4.
cd /usr/src && wget http://apache.mirrors.ionfish.org/httpd/httpd-2.4.17.tar.gz && tar xvf httpd-2.4.17.tar.gz
The first part of this command will change our current directory to /usr/src, then the wget section will download the source. The last part of this command unzips the source.
Com que Apache requereix APR i APR-util, feu el següent:
wget http://apache.mirrors.ionfish.org/apr/apr-1.5.2.tar.gz && tar xvf apr-1.5.2.tar.gz && mv apr-1.5.2 httpd-2.4.17/srclib/apr
wget http://apache.mirrors.ionfish.org/apr/apr-util-1.5.4.tar.gz && tar xvf apr-util-1.5.4.tar.gz && mv apr-util-1.5.4 httpd-2.4.17/srclib/apr-util
These commands will download the sources for APR and APR-util, and unzip them. Then, we move the source into Apache's build directory so that Apache will build properly.
Com que necessitem un compilador C adequat, n'haurem d'instal·lar-ne un mitjançant el gestor de paquets.
yum groupinstall 'Development Tools' -y
yum install gcc-c++ -y
yum install pcre-devel -y
yum install bison bison-devel -y
yum install ncurses-devel -y
yum install perl-devel -y
As I've mentioned above, we still need to obtain Apache's prerequisites, so we'll be installing them using the package manager.
Bona feina! Ara és el moment de configurar i construir Apache.
cd httpd-2.4.17 && ./configure
The cd httpd-2.4.17 part changes our current working directory to httpd-2.4.17/. When we run ./configure, we're configuring our system to build Apache.
Permet que el sistema configure la font per a la instal·lació, no hauria de trigar massa. Un cop completat, executeu:
make && make install
cp support/apachectl /usr/sbin
chmod 755 /usr/sbin/apachectl
The make section of these commands will build the software. When we run make install, we effectively install Apache onto our system. Now, we need to copy it to the secure bin directory (cp signifies copy). Finally, we'll give it permissions to execute with chmod 755.
Enhorabona, heu instal·lat correctament Apache 2.4!
Pas 2: baixada/instal·lació de MySQL
Ara, instal·lem MySQL, una base de dades utilitzada per moltes aplicacions web. Com que MySQL ja proporciona l'última versió en forma d'RPM, és més fàcil utilitzar el fitxer d'instal·lació preconstruït i després configurar-lo. Utilitzarem el repositori oficial de MySQL.
cd /usr/src && wget http://dev.mysql.com/get/mysql57-community-release-el6-7.noarch.rpm && rpm -i mysql57-community-release-el6-7.noarch.rpm
yum install mysql-community-server -y
The first command is where we download the RPM file to enable the MySQL repository on our system. Then, rpm -i installs the RPM file. Finally, we'll install MySQL from the official MySQL repository.
Pas 3: baixada/instal·lació de PHP
PHP té algunes dependències que hem d'instal·lar, així que anem a això primer.
yum install -y libxml2-devel libcurl-devel libmcrypt libmcrypt-devel
We're using the package manager once more - but this time, we're installing some components to allow PHP applications to run properly.
Baixeu la font per a PHP, que es fa executant les ordres següents:
wget http://docs.php.net/distributions/php-5.6.15.tar.gz && tar xvf php-5.6.15.tar.gz
cd php-5.6.15
./configure --with-pear=/usr/lib/pear --enable-libxml --with-pdo-mysql --with-mysqli --with-mysql --enable-mbstring --with-mcrypt --with-apxs2=/usr/local/apache2/bin/apxs --enable-maintainer-zts --with-curl=/lib
make && make install
The first part, wget, is where we download the source to PHP 5.6.15. Then, we change our working directory to php-5.6.15. Finally, we configure PHP with the features required to run various web applications, such as e-commerce websites.
Tingueu en compte que si rebeu un missatge que conté "/path/to/perl", haureu d'editar el fitxer /usr/local/apache2/bin/apxs.
nano /usr/local/apache2/bin/apxs
Canvia la primera línia per:
#!/usr/bin/perl -w
Pas 4: inici/atura de la pila LAMP
Com que hem construït Apache des de zero, no inclou un servei preconstruït. Haurem de configurar l'script d'inici nosaltres mateixos.
cd /usr/src && wget https://gist.githubusercontent.com/anonymous/62b0b788f86e7773e901/raw/6bcc88f9354f7139916272ac7a4eb998b1f26fdd/httpd-init
mv httpd-init /etc/init.d/httpd
chmod 755 /etc/init.d/httpd
The first part, where we cd, changes our working directory to the directory where we build/compile software. Then, with &&, we execute anything after it as well, which in this case, downloads the service file for Apache. Finally, we give permission for it to be executed with the chmod command.
Fet, i fet!
Ara, comencem Apache + MySQL + PHP:
service httpd start
service mysqld start
With the service commands, we can manage the status of services. In this case, we've started the services httpd and mysqld.
PHP s'inicia amb Apache, no s'inicia mitjançant un servei.
Conclusió
En aquest article, vam tractar com configurar una pila LAMP des de zero mitjançant versions actualitzades d'Apache/PHP/MySQL. Tot i que requereix més administració per gestionar, aquesta tècnica és útil quan volem una pila més nova que la que ofereix el proveïdor del sistema operatiu.