miércoles, 9 de septiembre de 2009

Compilar e instalar Apache2, MySQL y PHP5 desde cero y no morir en el intento.

Lo he montado en Debian con kernel 2.6.31, pero me imagino que en otras distribuciones será similar. También he añadido los siguientes flags para el compilador. Esto no es necesario y depende del procesador.
export CFLAGS="-march=pentium3 -O3 -pipe -fomit-frame-pointer"
export CXXFLAGS="$CFLAGS"
Nos bajamos los fuentes desde sus respectivas webs. Apache2, MySQL y PHP5. A ser posible tar.bz2 y los copiamos en /usr/local/src

APACHE:
tar -zxvf http-X.X.XX.tar.bz2
./configure --prefix=/usr/local/apache2 --enable-so
make
make install
useradd -s /usr/sbin/nologin apache

Cambiar en conf/httpd.conf user apache y group apache
Para probar instalación /usr/local/apache2/bin/apachectl start
En cualquier navegador o lynx http://localhost. Debe salir It works!

MySQL:
Como root creamos el usuario y el grupo mysql y añadimos el usuario al grupo:
groupadd mysql
useradd -g mysql mysql

Descomprimimos los fuentes (normalmente desde /usr/local/src):
tar -zxvf mysql-X.X.XX.tar.gz ó
gunzip mysql-X.X.XX.tar.gz y
tar -xvf mysql-X.X.XX.tar

Configuramos los fuentes antes de compilar:
cd /usr/local/src/mysql.X.X.XX
./configure --prefix=/usr/local/mysql

Compilamos e instalamos:
make && make install

Si todo ha ido correcto, instalamos las bases de datos:
scripts/mysql_install_db

Cambiamos los propietarios de los directorios:
cd /usr/local/mysql
chown -R root:mysql .
chown -R mysql var

creamos el archivo de configuración:
cp ../src/mysql-X.X.XX/support-files/my-medium.cnf /etc/my.cnf

Probamos el servidor:
bin/mysqld_safe --user=mysql &

Si no hay error, todo perfecto.
Si no se han creado los enlaces a los clientes de MySQL:
ln /usr/local/mysql/bin/mysql /usr/bin/mysql
ln /usr/local/mysql/bin/mysqladmin /usr/bin/mysqladmin

Para que arranque en el inicio hay que copiar support-files/mysql.server en /etc/init.d/mysqld y crear un enlace en /etc/rc2.d. O sea:
cp /usr/local/src/mysql-X.X.XX/support-files/mysql.server /etc/init.d/mysqld
ln -s /etc/init.d/mysqld /etc/rc2.d/S91MySQL

Para establecer una password para el usuario root:
/usr/local/bin/mysqladmin -u root password 'La_contraseña_nueva'
/usr/local/bin/mysqladmin -u root -h 'Nombre_máquina_local' password 'La_contraseña_nueva'

También se puede ejecutar:
/usr/local/mysql/bin/mysql_secure_installation
que te dará la posibilidad de quitar las bases de datos de prueba y el usuario anónimo creado por defecto.

Para arrancar el demonio MySQL:
/usr/local/bin/mysqld_safe &
Para comprobar el demonio MySQL en perl:
cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl

PHP:
apt-get install libxml2-dev
tar -zxvf php-X.X.XX.tar.bz2
./configure --prefix=/usr/local/php5 --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache2/bin/apxs
make
make install
una de estas 2 según nuestro entorno desarrollo o producción:
cp /usr/local/src/php-X.X.XX/php.ini-development /usr/local/lib/php.ini
cp /usr/local/src/php-X.X.XX/php.ini-production /usr/local/lib/php.ini

En el httpd.conf de apache descomentamos o añadimos según proceda:
LoadModule php5_module modules/libphp5.so

AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps

Compiling and Installing Apache2, MySQL and PHP5 from scratch and not to die trying it.

I've ridden it in Debian with kernel 2.6.31, but I imagine that other distributions will be similar. I've also added the following flags to the compiler. This is not necessary and depends on the processor.
export CFLAGS="-march=pentium3 -O3 -pipe -fomit-frame-pointer"
export CXXFLAGS="$CFLAGS"
Get the sources from their respective websites. Apache2, MySQL and PHP5.
Whenever it's possible download it with the .tar.bz2 extension and copy them into the /usr/local/src directory.
APACHE:
tar -zxvf http-X.X.XX.tar.bz2
./configure --prefix=/usr/local/apache2 --enable-so
make
make install
useradd -s /usr/sbin/nologin apache
In the conf/httpd.conf file change into the following: user apache and group apache
To test the installation we must type /usr/local/apache2/bin/apachectl start
Type in any browser or lynx http://localhost. You should see It works!

MySQL:
As root we create the mysql user and group: 
groupadd mysql
useradd -g mysql mysql
Unzipping the source (usually from /usr/local/src):
tar -zxvf mysql-X.X.XX.tar.gz or
gunzip mysql-X.X.XX.tar.gz and
tar -xvf mysql-X.X.XX.tar
Configuring the sources before compiling: 
cd /usr/local/src/mysql.X.X.XX
./configure --prefix=/usr/local/mysql
Compiling and installing:
make && make install
If everything is Ok, install the databases:
scripts/mysql_install_db
Changing the owners of the directories:
cd /usr/local/mysql
chown -R root:mysql .
chown -R mysql var
Creating the configuration file:
cp ../src/mysql-X.X.XX/support-files/my-medium.cnf /etc/my.cnf
Testing the server:
bin/mysqld_safe --user=mysql &
If no error, everything is perfect.
If you haven't created the links to the MySQL client you must create them now:
ln /usr/local/mysql/bin/mysql /usr/bin/mysql
ln /usr/local/mysql/bin/mysqladmin /usr/bin/mysqladmin
To start at the beginning you have to copy support-files/mysql.server in / etc / init.d / mysqld and create a soft link in / etc/rc2.d. That is:
cp /usr/local/src/mysql-X.X.XX/support-files/mysql.server /etc/init.d/mysqld
ln -s /etc/init.d/mysqld /etc/rc2.d/S91MySQL
Setting a password for root:
/usr/local/bin/mysqladmin -u root password 'A_new_password'
/usr/local/bin/mysqladmin -u root -h 'Localhost_name' password 'A_new_password'
You can also run:
/usr/local/mysql/bin/mysql_secure_installation
to give you the ability to remove the test databases and anonymous user created by default.
Starting MySQL daemon:
/usr/local/bin/mysqld_safe &
Testing MySQL daemon in perl:
cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl

PHP:
apt-get install libxml2-dev
tar -zxvf php-X.X.XX.tar.bz2
./configure --prefix=/usr/local/php5 --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache2/bin/apxs
make
make install
One of this depending of if we have a development environment or a production one
cp /usr/local/src/php-X.X.XX/php.ini-development /usr/local/lib/php.ini
cp /usr/local/src/php-X.X.XX/php.ini-production /usr/local/lib/php.ini
In the Apache httpd.conf file, uncomment the following lines or add them as needed:
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps

No hay comentarios: