Home / guides   Print version

Gentoo LAMP (Linux, Apache, MySQL, PHP) install tutorial

Publish date 03/08/2008
updated 12/11/2013

This is a tutorial to install LAMP: Linux, Apache, MySQL and PHP on Gentoo.

As Gentoo compiles everything it can takes some time. You might want to use screen, so you don't have to leave a console open.

To install on gentoo just emerge the necessary packages.
You might want to sync the emerge database first:

emerge --sync
Then emerge
emerge www-servers/apache
USE="mysql apache2" emerge dev-lang/php
emerge dev-db/mysql

As emerge compiles and installs everything, you only need to configure.

Apache

Change the config file:

nano /etc/conf.d/apache2
APACHE_OPTS="-D PHP5" //uncomment this line and modify it

nano /etc/apache2/conf/apache2.conf [code from apache2.conf]

ServerName 127.0.0.1 //change the IP to your domain name
#parse php in HTML
#add this line to the bottom of the conf file
AddType application/x-httpd-php .php .html .htm 
#for directory views, directory access and vhosts see the example above.

To start the apache server

/etc/init.d/apache2 start
To make it start on boot:
rc-update add apache2 default

MySQL

To start the MySQL server:

/etc/init.d/mysql start
you will get a specific error message telling you to run a mysqladmin command. To set the password for the root user:
/usr/bin/mysqladmin -u root -h localhost password "newpassword"
You might want to create extra users for different task or databases. This can be done with GRANT:
bin/mysql -u root -p
GRANT select,insert,update,delete,create,drop ON database.* TO 'username'@'localhost' IDENTIFIED BY 'password'
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON * . * TO 'username'@'localhost';
(You replace "database" withe the name of the database, "username" with the name of the user and "password" with the secret password) This allows the user to connect from localhost only! Which is in most cases enough, and the most secure.

To start MySQL server at boot:

rc-update add mysql default

 

TOP