How To Install Apache with PHP, MySql, Ruby and Passenger

The goal is to create on the same machine, a multi-function web server that will execute HTML, PHP and Ruby / Rails applications with the possibility of connecting to a Mysql database. 

This server will be able to run simultaneously PHP applications like WordPress and Rails applications like Redmine.

For this we will install Apache on Debian with all necessary software:

  • MySQL
  • Apache
  • ImageMagick
  • PHP
  • PhpMyAdmin
  • Ruby, Ruby, Ruby on Rails
  • Bundler
  • Passenger

Install Mysql

apache install mysql-server mysql-common libmysqlclient-dev mysql-client

During the installation, you will need to enter the MySQL admin password.

Check the installation of version mysql -V. Warning, this is a capital “V”.

Installing Apache on Debian

By default, Apache installs with MPM-Worker but PHP requires the use of MPM-Prefork.
To avoid the complex settings of Apache with FastCGI to run PHP on MPM-Worker, we will install Apache directly with MPM-Prefork.

aptitude2 apache2-mpm-prefork apache2-prefork-dev libapr1-dev libaprutil1-dev libfcgi-dev libssl-dev zlib1g-dev libcurl4-openssl-dev

Check the installation of version apache2 -v.
And to check that it works: http: // ip_of_server.
It works!

Install ImageMagick

ImageMagick allows PHP and Ruby, among other things, to manipulate images.

aptitude install imagemagick libmagickwand-dev

Install PHP

We install PHP with the mod-php5 for Apache as well as the connector MySql.

aptitude install php5 libapache2-mod-php5 php5-mysql

To verify that PHP is working, we create a PHP file of test (a phpinfo that gives the configuration of PHP) in the documentroot of Apache.

Touch /var/www/phpinfo.php
Echo "<? php phpinfo ();?>" >> /var/www/phpinfo.php

And to see the result: http: //your_server_ip/phpinfo.php.

We then install the most common modules for PHP. This will avoid having to install them as applications demand them.

aptitude install php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

There, Aptitude may detect a conflict and propose to remove libgd2-noxpm. One answers “yes”, it is a priori without consequences.

Optional: Also install the PHP APC cache to speed up page rendering.

aptitude install php-apc

Install phpMyAdmin

aptitude install phpmyadmin

The installer asks for which web server it should install, Apache or Lighthttpd. Apache is checked. It then asks where the phpMyadmin configurations will be stored. In files or in a database, the easiest way is to take the file mode.
So we answer “no” to the question “Install dbconfig-common”.

PhpMyadmin is not visible in Apache’s root document, or in the “site-aviable” and “site-enabled” folders. It is declared in a vhost in the /etc/apache2/conf.d folder.

PhpMyadmin is available at http: //your_server_ip/ phpmyadmin

Install Ruby

We now add the entire Ruby environment to our server.
Ruby is required to install Redmine.

aptitude install ruby1.9.3 ruby-dev libruby rubygems libmysql-ruby

Check the installation of version ruby -v and gem -v.

Install Bundler

Bundler is a Gem that manages the dependencies of a project, including those of Rails applications such as Redmine.

gem install bundler

Install Passenger

Passenger allows Apache to drive and run a Ruby / Rails program.
Passenger is installed via Gem and not by Aptitude.

Gem install passenger

Once Passenger is installed, we install the module for Apache (which will be recompiled). Note that it takes a minimum of power and swap. The installer issues an alert if there is not at least 1GB of swap available.

Passenger-install-apache2-module

At the end of the compilation, the installer requests to edit 2 files and also gives an example of Apache vhost configuration for a Ruby application.

Create the file /etc/apache2/mods-available/passenger.load add the line LoadModule passenger_module /var/lib/gems/1.9.1/gems/passenger-4.0.14/buildout/apache2/mod_passenger.so

This tells Apache where the mod_passenger is located.

touch /etc/apache2/mods-available/passenger.load

echo "LoadModule passenger_module /var/lib/gems/1.9.1/gems/passenger-4.0.14/buildout/apache2/mod_passenger.so" >> /etc/apache2/mods-available/passenger.load

Create the file /etc/apache2/mods-available/passenger.confand add the lines PassengerRoot /var/lib/gems/1.9.1/gems/passenger-4.0.14, PassengerDefaultRuby /usr/bin/ruby1.9.1and PassengerDefaultUser www-data.

This last statement is important because it defines the user who is going to run mod_passenger. There is “www-data”, the Apache user by default. The two must be identical.

touch /etc/apache2/mods-available/passenger.conf

echo "PassengerRoot /var/lib/gems/1.9.1/gems/passenger-4.0.14" >> /etc/apache2/mods-available/passenger.conf

echo "PassengerDefaultRuby /usr/bin/ruby1.9.1" >> /etc/apache2/mods-available/passenger.conf

echo "PassengerDefaultUser www-data" >> /etc/apache2/mods-available/passenger.conf

The module is activated:

a2enmod passenger

It only remains to restart Apache:

service apache2 restart

The configuration is complete. The server is functional.
One can go to the Redmine system.

Lucid Kit

Related Posts
Leave a reply
Captcha Click on image to update the captcha .