apache2.0 PHP, MySQL

By 5 de agosto de 2006 Linux No Comments

180px-Apache-Server.gifCuidado con APACHE_OPTS, APACHE2_OPTS="-D SSL -D PHP4"

Setting up Apache2 with PHP and MySQL

This HOWTO details setting up Apache2 on Gentoo Linux with PHP and MySQL installed as well.

  • Getting Started

Got Root?

Due to the nature of this procedure, you will need root access in order to successfully complete this HOWTO. It is your choice whether you login as root, use su , or use sudo to actually get the access required.

Setting your USE Flags

To begin with, your use flags need to be set up properly to ensure that all the required functionality is compiled into the relevant programs. Set up your use flags however your want, and then ensure the following flags are set.

File: /etc/make.conf
USE="apache2 mysql pam ssl xml xml2"

These flags, at least, will ensure a robust installation. Other use flags, such as gif, jpg, png, etc... can enhance the functionality of some of the modules. Don't forget to run env-update after modifying /etc/make.conf

Emerge Sync/System Update

The next thing to ensure is that your system is up-to-date. Thanks to the nature of portage, this is ridiculously easy.

Code: Updating Gentoo
# emerge sync // update your portage tree
# emerge -Davu world // list updates to be installed and ask about installing them
  • Step 1: Installing Packages

Installing MySQL

Installing MySQL is done first, because with it's use flag set, it will be installed anyway, and this way you have more of a chance to see what is going on. There are some use flags that may affect what type of database support your mysql compiles with. They are as follows.

File: /etc/make.conf
USE="berkdb innodb"

The first thing to do is actually install the package. Next, you need to configure the installation. And finally you will need to add the mysql daemon to the default runlevel so that it starts when the machine boots up. All the commands needed to do this are in the following code block.

It is recommended that you use the /etc/portage/package.* files instead of USE=" " on the command line. The biggest benefit of this is that on future upgrades of the package, your same use flags will be applied.

To add custom use flags to a package, first create the /etc/portage directory. It does not exist by default. Next, create a package.use file (nano -w /etc/portage/package.use). The format of this file is very simple,

package-category/packagename{optional-version} {useflags}

File: MySQL package.use file entry
dev-db/mysql innodb berkdb

What this entry means is "I want all version of mysql to be emerged with innodb and berkdb support".

File: Installing MySQL
# emerge mysql -pv //''list mysql, it's dependancies, and the USE flags they take'' //''if you missed a USE flag, you can always prepend it to your emerge command'' # [USE="foo"] emerge mysql //''install mysql, and any dependancies it has. USE optional'' # ebuild /var/db/pkg/dev-db/mysql-foo*/mysql-foo*.ebuild config //''replace 'foo' with the version number of MySQL that you installed. Tab completion is your friend'' # rc-update add mysql default //''add mysql to the default runlevel''

Installing Apache

Installing Apache is done second, because that's the way I've always done it. I don't think you'd break anything by swapping this step and the next one, Installing PHP. Installing apache is very, very easy. Just follow the following commands.

Code: Installing Apache
# emerge apache -pv
# emerge apache
# rc-update add apache2 default

Installing PHP

Installing PHP is done last, because, well, that's when it's done. Again, you probably won't break anything by installing PHP before Apache, but you'd probably want to have apache installed before you install mod_php. Again, the installation steps are very simple and straightforward.

Using the --pretend (p) and --verbose (v) options will display the PHP compile options, which are quite extensive. You should look this listing over and make sure PHP will have the functionality you desire. For example, the default options for PHP5 do not include the PHP calendar extension. This is readily available on commercial servers and is sometimes taken for granted to be installed. To add this extension you will need to change the appropriate USE flag.

Please note that if you compile PHP with both freetds and mssql support, your build will not be stable. If you need only mssql support, emerge with the mssql USE flag, otherwise use the freetds use flag, but not both.

Code: Installing PHP
# emerge php -pv
# emerge php
# emerge mod_php -pv
# emerge mod_php
# emerge clean
# ebuild /var/db/pkg/dev-php/mod_php-foo*/mod_php-foo*.ebuild config
  • Configuring the Packages

Configuring MySQL

This is rather simple to do so I will quickly write it up. After you have emerged mysql and done the ebuild config, this will be quoted to you:

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /etc/init.d/mysql start (you have to start the server first!) /usr/bin/mysqladmin -u root -h hostname password 'new-password' /usr/bin/mysqladmin -u root password 'new-password'

En la sección de Manuales Linux encontrarás documentación sobre esto.
Manual: MySQL, phpMyAdmin, ODBC

Just follow these instructions and you will have at least secured your mysql server by setting a root password. Beyond this, there is no extra configuration necessary unless you intend to run it with phpmyadmin where you will have to add a user called pma with readonly access. However, when you emerge phpmyadmin it will prompt you to do it anyway.

Configuring PHP

PHP, to the best of my knowledge, does not require any additional configuration. As usual, if you want to check whether the installation worked, create a php file with in it and load it in your browser.

Configuring Apache
!!! Atención a esto

The first file that needs editing is /etc/conf.d/apache2

File: /etc/conf.d/apache2

Pero en la versión: 2.0.51-r1 (y posiblemente en otras)

File: /etc/conf.d/apache2

De otra manera PHP, no nos funcionará.

  • Starting Everything

This one's easy.

Code: Starting servers
# /etc/init.d/mysql start
# /etc/init.d/apache2 start

Leave a Reply

Your email address will not be published.