Tagged: apache2

LAMP Stack on Gentoo Linux

There aren't many sites showing how to configure LAMP (Linux, Apache, MariaDB, PHP) stack on Gentoo. Since I'm new to Gentoo and in need of configuring LAMP stack, I compiled the steps.

Disclaimer:
The information in this site is the result of my researches in the Internet and of my experiences. This information below is solely used for my purpose and may not be suitable for others.

Apache:

Web Server. Install apache with the threads support.# echo "www-servers/apache threads" > /etc/portage/package.use/apache # emerge --ask www-servers/apache

Then, enable global apache2 support for other applications.# nvim /etc/portage/make.conf ========== .... USE="... apache2"

Once the USE variable in /etc/portage/make.conf is modified, update the system so the changes take effect.# emerge --ask --changed-use --deep @world

Start the apache2 process and make it so that it automatically restarts after each reboot.# /etc/init.d/apache2 start # rc-update add apache2 default

Apache - Virtual Hosts

Apache Virtual Hosts allows to run multiple instances of websites using a single IP address. This is a good option for me when I work on a few websites at the same time. Create a conf file under /etc/apache2/vhosts.d/ for each website.# nvim /etc/apache2/vhosts.d/site1.conf ========== <VirtualHost *:80> ServerAdmin email@localhost DocumentRoot /home/ubyt3m3/www/site1 ServerName site1 ErrorLog /var/log/apache2/site1.err CustomLog /var/log/apache2/site1.log combined <Directory "/home/ubyt3m3/www/site1"> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> </VirtualHost> # nvim /etc/apache2/vhosts.d/site2.conf ========== <VirtualHost *:80> ServerAdmin email@localhost DocumentRoot /home/ubyt3m3/www/site2 ServerName site2 ErrorLog /var/log/apache2/site2.err CustomLog /var/log/apache2/site2.log combined <Directory "/home/ubyt3m3/www/site2"> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> </VirtualHost>

Restart the apache2 process to reload the config file(s).# /etc/init.d/apache2 reload

Maria DB

MariaDB is a community-developed, open source relational database management system (RDBMS). It's a fork from MySQL which's owned by Oracle. # emerge --ask dev-db/mariadb

Auto start mysql after each reboot. # rc-update add mysql default

Now, it's time to configure MariaDB. With Gentoo, this can be done with emerge --config. # emerge --config dev-db/mariadb

This will create a database and set permissions. You will set a root password during this process.

Start the mysql process.# rc-service mysql start

PHP

Set USE flags for PHP and install it.# echo "dev-lang/php cgi cjk curl exif gd mysql mysqli pdo postgres threads xslt" > /etc/portage/package.use/php # emerge --ask dev-lang/php

Then, configure apache for PHP by updating /etc/conf.d/apache2.# nvim /etc/conf.d/apache2 ========== ... APACHE2_OPTS="... -D PHP" ...

Restart the apache2 process.# /etc/init.d/apache2 restart

Verify if PHP works with Apache$ nvim /home/ubyt3m3/www/site1/index.php ========== <html> <body> <?php phpinfo(); ?> </body> </html>

It works!

Troubleshooting 403 Fobidden Error

If the steps are followed, it's not the types of errors you get, but it's good to know how to approach when it happens.

  • Check to see if the directory and file permissions are properly set.

    Directory: 0755
    File: 0644

  • The default directory index page is there. It is defined in the DirectoryIndex directive in apache's modules.d/70_mod_php.conf file.

    DirectoryIndex index.php index.html

  • The Apache website mentions that the index of a directory is handled by mod_dir. In Gentoo, its config file is in modules.d/00_default_settings.conf. Add index.php in front of index.html should allow index.php loaded automatically.

    <IfModule dir_module>
    DirectoryIndex index.php index.html index.html.var
    </IfModule dir_module>

  • Make sure the correct directory permissions are set in the Directory directive in the apache's config file.

    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted

  • Check the error file for some hints.

    tail -f [path_to_apache_error_file]

That's all!
-gibb

Debian Wheezy (7.5): Name-Based Web Sites on a Single IP Address (vhosts)

Configuring virtual hosting with Debian Wheezy has a little different steps from that with Slackware. To avoid from getting myself confused (and hopefully help someone else to set their virtual host sites), these are the steps I used for my local sites.

Disclaimer:
The information in this site is the result of my researches in the Internet and of my experiences. It is solely used for my purpose and may not be suitable for others. I will NOT take any responsibility of end result after following these steps (although I will try to help if you send me your questions/problems).

1) Disabling Default Virtual Host

First, let's disable the default Apache virtual host with a2dissite. What this command do is simply removing a symlink to /etc/apache2/sites-enabled/. # a2dissite default

2) Creating a New Directory and Setting Permissions

It's necessary to create a directory where site's website files and logs reside and grant ownership of the directory to the user instead of keeping it on the root system. For example, I'm setting up for siteA.org and siteB.org.

siteA.org
# mkdir -p /var/www/siteA.org/public_html # mkdir /var/www/siteA.org/logs # chown -R [$user]:[$group] /var/www/siteA.org/public_html
siteB.org
# mkdir -p /var/www/siteB/public_html # mkdir /var/www/siteB.org/logs # chown -R [$user]:[$group] /var/www/siteB.org/public_html

3) Creating Config files

Each virtual host needs own configuration file placed in /etc/apache2/sites-available/ directory. Each configuration file is as follow. Make sure that you have all directories specified in each conf file exist before you restart the apache process; otherwise, it'll fail to start.

siteA.org

# vim /etc/apache2/sites-available/siteA.org.conf ------------------------------------ <VirtualHost *:80> ServerAdmin webmaster@siteA.org ServerName siteA.org ServerAlias www.siteA.org DocumentRoot /var/www/siteA.org/public_html <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/siteA.org/public_html/> Options Indexes FollowSymLinks AllowOverride None Order allow,deny allow from all </Directory> ErrorLog /var/www/siteA.org/logs/error.log CustomLog /var/www/siteA.org/logs/access.log combined </VirtualHost>

siteB.org

# vim /etc/apache2/sites-available/siteB.org.conf ------------------------------------ <VirtualHost *:80> ServerAdmin webmaster@siteA.org ServerName siteB.org ServerAlias www.siteB.org DocumentRoot /var/www/siteB.org/public_html <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/siteB.org/public_html/> Options Indexes FollowSymLinks AllowOverride None Order allow,deny allow from all </Directory> ErrorLog /var/www/siteB.org/logs/error.log CustomLog /var/www/siteB.org/logs/access.log combined </VirtualHost>

4) Enabling the Sites

Now activate the host: # a2ensite siteA.org.conf # a2ensite siteB.org.conf

5) Restarting Apache

Restart the Apache server to initialize the changes: # service apache2 restart

6) Setting Up Local Host

Edit /etc/hosts so that the sites can be found by name: # vim /etc/hosts ------------------------------------ 127.0.0.1 localhost siteA siteB

That's all!
-gibb

Debian Wheezy (7.5): LAMP (Linux, Apache, MariaDB, and PHP)

LAMP used to refer to Linux, Apache, MySQL, and PHP but nowadays the trend is transitioning from MySQL to MySQL's drop-in replacement MariaDB. The Slackware project switched the default database to MariaDB back in March 2013 for the version 14.1 and forward.

I was a little concerned about this change and wasn't sure if my web sites would work with Mhttp://blog.ataboydesign.com/wp-admin/post.php?post=959&action=editariaDB. However, my worry was trivial. MariaDB uses the same files as MySQL so this makes migration a lot easier.

So it's natural for me to try MariaDB on my new Debian Wheezy (7.5) system.

Disclaimer:
The information in this site is the result of my researches in the Internet and of my experiences. It is solely used for my purpose and may not be suitable for others. I will NOT take any responsibility of end result after following these steps (although I will try to help if you send me your questions/problems).

Installing Apache2

Firts, make sure the system is up-to-date: # apt-get update && apt-get upgrade -y

Then, install apache2: # apt-get install apache2

Add apache2 to system start up and start it up now: # update-rc.d apache2 enable update-rc.d: using depndency based boot sequencing # service apache2 start [ ok ] Starting web server: apache2.

If you open a web browser and point it to http://localhost, you'll see the message It works!

Installing php5

Next, install php5 along with the apache php5 module, MySQL(MariaDB) php module, and other modules: # apt-get install php5-curl php5-xmlrpc php5-gd php5-intl libapache2-mod-php5 php5 php5-common php5-dev php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-mysql php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy

Restart the web server: # apache2 restart

Test the php support by creating a php file (phpinfo.php) in the default document root, /var/www: # vim /var/www/phpinfo.php -------------------------------------------- < ?php phpinfo(); ?>

With successful installation/configuration, below page should be loaded:
debian_lamp_install_phpinfo

Installing MariaDB

To properly install and configure MariaDB, I need to know the version/codename of this Debian. I already know its Wheezy but to check, type the following command: # lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 7.5 (wheezy) Release: 7.5 Codename: wheezy

Now, open a web browser and go to MariaDB's download page to get the repository information for MariaDB: debian_lamp_install_mariadb_config

Above selection produces below repository info:
debian_lamp_install_mariadb_repo

Create a file called mariadb.list under /etc/apt/sources.list.d and copy & paste the repository info: # vim /etc/apt/sources.list.d/mariadb.list -------------------------------------------- # MariaDB 10.0 repository list - created 2014-05-10 06:44 UTC # http://mariadb.org/mariadb/repositories/ deb http://mirror.jmu.edu/pub/mariadb/repo/10.0/debian wheezy main deb-src http://mirror.jmu.edu/pub/mariadb/repo/10.0/debian wheezy main

Add MariaDB to the system: # apt-get install python-software-properties # apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db # apt-get update # apt-get install mariadb-server

Follow the on-screen instructions to set up a root password for MariaDB server.

Let's see if MariaDB server was successfully installed: # mysql -u root -p Enter password: Welcome to the MariaDB monitor. Command end with ; or \g. Your MariaDB connection id is 38 Server version: 10.0.10-MariaDB-1~wheezy mariadb.org binary distribution Copyright (c) 2000, 2014 Oracle, SkySQL Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>

VoilĂ ! With above steps, I have successfully installed LAMP stack on my Debian Wheezy server.

If you are interested, take a look at my post on VirtualHost: Name-Based Web Sites on a Single IP Address

That's all!
-gibb

FreeBSD 10: Installing Apache 2.4, MySQL 5.5, and PHP5.5 — Missing libphp5.so

Continuing my quest with FreeBSD.

Today, I was installing Apache 2.4, MySQL 5.5, and PHP 5.5 (php55-5.5.11) on newly installed system. I've done this kind of installation many times on Linux so I didn't expect much of problems. Boy, I was wrong...

Apache and MySQL installation were straight forward and had no problem. After PHP installation, I couldn't find libphp5.so in /usr/local/libexec/apache24/! A little googling found articles/forums on older version of FAMP. They said its installation should be automatic or "Build Apache module" option needs to be selected, which I did not have such an option any where.

Then one thread mentioned something about configuring php conf file. So, I opened Makefile for PHP55: # vim Makefile ------------------------------------- ... OPTIONS_DEFINE+=APACHE CLI CGI FPM... OPTIONS_DEFAULT=APACHE CLI CGI FPM...

Compiled PHP55 again: # make install config ===> php55-5.5.11 doesn't install the Apache module anymore: update your OPTIONS and build www/mod_php55 port instead. *** Error code 1

Aha! www/mod_php55. I wonder if php installation didn't install mod_php55 but now I know what I need to do: # cd /usr/local/www/mod_php55/ # make install clean ... --- Zend/zend_dtrace_gen.h dtrace: failed to compile script /usr/ports/www/mod_php55/work/php-5.5.11/Zend/zend_dtrace.d: line 30: failed to resolve INP_IPV4: Unknown variable name ...

Hmm... I wonder if this was causing php55 installation to fail creating libphp5.so. Well, another googling found a suggestion/solution to load the dtraceall module: # kldload dtraceall # echo 'dtraceall_load="YES"' >> /boot/loader.conf

Now, mod_php55 was successfully installed as well as libphp5.so!

Here is the whole steps to install apache, mysql, and php:

NOTE: The steps below are not suitable for production use. Be warned!

Disclaimer:
The information in this site is the result of my researches in the Internet and of my experiences. It is solely used for my purpose and may not be suitable for others. I will NOT take any responsibility of end result after following these steps (although I will try to help if you send me your questions/problems).

Apache 2.4 - Installation and Configuration:

# cd /usr/ports/www/apache24/ # make install clean

Edit /etc/rc.conf to make the Apache server will start automatically at system boot. # vim /etc/rc.conf ------------------------------------- apache24_enable="YES"

Test the Apache server installation using the following command: # /usr/local/etc/rc.d/apache24 start

MySQL - Installation and Configuration:

# cd /usr/ports/databases/mysql55-server/ # make install clean

Start MySQL # /usr/local/etc/rc.d/mysql-server onestart

Update /etc/rc.conf # vim /etc/rc.conf ------------------------------------- mysql_enable="YES"

Set root password # rehash # mysqladmin -uroot password '<password>'

Create my.cnf # cp /usr/local/share/mysql/my-small.cnf /etc/my.cnf

Restart mysql # /usr/local/etc/rc.d/mysql-server restart

PHP Installation and Configuration:

Here is the moment of truth. First, load the dtraceall kernel module, update the /boot/loader.conf file, and then install php55. # kldload dtraceall # echo 'dtraceall_load="YES"' >> /boot/loader.conf # cd /usr/ports/lang/php55 # make install clean

Check to see if libphp5.so is there # ls /usr/local/libexec/apache24/ httpd.exp mod_include.so mod_access_compat.so mod_info.so ...

Nope, it's not there. Then manually compile www/mod_php55/ # cd /usr/ports/www/mod_php55/ # make install clean

Now, check to see if libphp5.so is there again # ls /usr/local/libexec/apache24/ httpd.exp mod_include.so libphp5.so mod_info.so ...

Copy the PHP configuration file # cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini

Edit /usr/local/etc/apache24/httpd.conf file and add the following lines # vim /usr/local/etc/apache24/httpd.conf ------------------------------------- AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps

Add the following line under the LoadModule section if it's not there LoadModule php5_module libexec/apache24/libphp5.so

Edit the DirectoryIndex section DirectoryIndex index.php index.html

Now restart the apache server # /usr/local/etc/rc.d/apache24 restart

Let's see now if it can show a php page # vim /usr/local/www/apache24/data/index.php ------------------------------------- < ?php phpinfo(); ?>

VoilĂ ! It's working now!

phpinfo

That's all!
-gibb

Slackware64: Name-Based Web Sites on a Single IP Address (vhosts)

Configuring VirtualHost with Slackware64 13.37 is also relatively easy. This is my local setup.

Uncomment below from /etc/httpd/httpd.conf. This enables virtual host. Include /etc/httpd/extra/httpd-vhosts.conf

Edit /etc/httpd/extra/httpd-vhosts.conf

Note on access control. From Apache version 2.4, Options, Allow, and other directives are replaced by the Require directive. Neglecting to make this change could result in 403 Forbidden You don't have permission to access / on this server. or AH01630: client denied by server configuration... in the error log.

For more detailed information, upgrading overview document is useful. NameVirtualHost *:80 <virtualhost *:80> <directory "/home/ubyt3m3/www/siteA"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all Require all granted [Edit: To comply with Apache 2.4] </directory> ServerName siteA DocumentRoot "/home/ubyt3m3/www/siteA" ErrorLog "/var/log/httpd/siteA.err" CustomLog "/var/log/httpd/siteA.log" common </virtualhost> <virtualhost *:80> <directory "/home/ubyt3m3/www/siteB"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all Require all granted [Edit: To comply with Apache 2.4] </directory> ServerName siteB DocumentRoot "/home/ubyt3m3/www/siteB" ErrorLog "/var/log/httpd/siteB.err" CustomLog "/var/log/httpd/siteB.log" common </virtualhost>

Edit /etc/hosts so that the sites can be found by name: 127.0.0.1 siteA siteB

Restart the httpd process: /etc/rc.d/rc.httpd stop /etc/rc.d/rc.httpd start

That's all!
-gibb

Disclaimer:
Information in this page is the result of my researches in the Internet and of my experiences. It is solely used for my purpose and may not be suitable for others.