Install LAMP in Gentoo/Sabayon

LAMP (Linux, Apache, MySQL and PHP) is an open source Web development platform that uses Linux as operating system, Apache as the Web server, MySQL as the relational database management system and PHP as the object-oriented scripting language.

In this post we will see how to install LAMP in Sabayon and Gentoo

1- FirstĀ  Update yourĀ  System

#emerge --sync

2- Install Apache Webserver

DownloadĀ  andĀ  install

sabayon6 ~ # emergeĀ  apache
^[OH
 * IMPORTANT: 3 news items need reading for repository 'gentoo'.
 * Use eselect news to read news items.

Calculating dependencies… done!

>>> Verifying ebuild manifests

>>> Starting parallel fetch

>>> Emerging (1 of 2) app-admin/apache-tools-2.2.17
* waiting for lock on /usr/portage/distfiles/.httpd-2.2.17.tar.bz2.portage_lockfile
…Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā  [ ok ]

The directory of ROOT is in /var/www/localhost/htdocs/

In case you want to allow the users to have their own webpages (public_html), then do:

echo "www-servers/apache userdir" >> /etc/portage/package.use emerge apache

After that you also need to edit the file /etc/conf.d/apache2 and add “-D USERDIR” to APACHE2_OPTS as shown:

APACHE2_OPTS=”-D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE -D USERDIR”

Then every user have to make a public_html directory in order to put his/her index.html and any other files in there.
[edit] 00_mod_userdir.conf

If you want to allow just some users to have their own web pages, then you have to edit the userdir module in:

/etc/apache2/modules.d/00_mod_userdir.conf

and add to it the following lines:
Code: add to 00_mod_userdir.conf

UserDir public_html
UserDir disabled
UserDir enabled user1 user2 root

 

Now you should check that you can start apache up on your box – to do this run

sabayon6 ~ # /etc/init.d/apache2Ā Ā  start
* Caching service dependencies …Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā  [ ok ]
* Starting apache2 …
apache2: Could not reliably determine the server’s fully qualified domain name, using 10.0.2.15 for ServerNameĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā  [ ok

Add apache2 to the startup script

 

# rc-update -v addĀ  apache2 default

you will see the following response:

* apache2 added to runlevel default
* Caching service dependencies… [ ok ]
* rc-update complete.

 

3- Install the Ā PHP packages

Install Ā php packagesĀ  and some other Ā dependencies

# emerge Ā php mod_php

After installing mod_php there are some instructions for some /etc/conf.d/apache2 configuration changes that won’t be made using etc-update, and must be done manually:

* The INI file for this build is /etc/php/apache2-php5/php.ini
* Due to some previous bloopers with PHP and slotting, you may have
* multiple instances of mod_php installed. Please look at the autoclean
* To have Apache run php programs, please do the following:
* Edit /etc/conf.d/apache2 and add “-D PHP5″ to APACHE2_OPTS
APACHE2_OPTS=”-D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D SUEXEC -D LANGUAGE -D PHP5″

 

Check the PHP install

Now the php packages installed, give small try toĀ  check the php page info

Make aĀ  fileĀ  with theĀ  script Ā bellow on root directoryĀ  ofĀ  apache Ā Ā (example info.php)

< ? phpinfo() ? >

or

echo '<html><body><?php phpinfo(); ?></body></html>' > /var/www/localhost/htdocs/index.php

NowĀ  open theĀ  page http://IP/info.php

4- Install MySQL Database

Install the MySql dameon with emerge:

# emerge mysql

Configure MySQL Database

(Replace [version] with the version number you have just installed.)
# emerge --config =dev-db/mysql-[version]
 * MySQL DATADIR is /var/lib/mysql
 * Press ENTER to create the mysql database and set proper
 * permissions on it, or Control-C to abort now...

   Preparing db table
   Preparing host table
   Preparing user table
   Preparing func table
   Preparing tables_priv table
   Preparing columns_priv table
   Installing all prepared tables

This will install the mysql database and instruct you on how to set a password for the MySQL root user (a very good idea if this box is accessible from outside your network). Here is how that is done:

/etc/init.d/mysql start (you have to start the server first!)
usr/bin/mysqladmin -u root -h [your hostname] password ‘new-password’

The following line is not exactly as they instructed. I added the -p flag as I just set a password in the previous line so you need to use your new password to change this.

/usr/bin/mysqladmin -u root -p password ‘new-password’

Test MySQL Server

I start by restarting the MySQL server:

# /etc/init.d/mysql restart

Log in as root (mysql root user, but doesn’t have to be from the Linux root account)

# mysql -u root -p

Check that the database was created correctly, view tables and some data, exit.

mysql> use mysql
mysql> show tables;
mysql> select * from user;

You should have no errors and see a few lines from the select on the user database.

Add MySQL to the startup script

This step is optional, but if you want MySQL to be running automatically upon reboot – a good idea for a web or db server, you should run this command.

# rc-update -v add mysql default

If it worked you will see the following response:

* mysql added to runlevel default
* Caching service dependencies… [ ok ]
* rc-update complete.

5- Install phpMyAdmin

emerge -av phpmyadmin

You’ll need to grant some rights for it to let it do its magic.

mysql -u root -p < /usr/share/webapps/phpmyadmin/<VERSION>/sqlscripts/mysql/<VERSION>_create.sql