Project

General

Profile

Support #432

Updated by Daniel Curtis almost 10 years ago

{{>toc}} 

 Here is a procedure to install a FAMP, FreeBSD with Apache, MariaDB and PHP, server. The following setup runs Apache 2.4, MariaDB 5.5, and PHP 5 on FreeBSD 9.2-RELEASE. If any version of the packages needs to be changed, replace the versions in the commands accordingly. 

 h1. h2. Pre-Installation Tasks 

 * Before installation of the components, make sure the ports tree and packages are up to date using the following command: 
 <pre> 
 pkg update && pkg upgrade 
 && portsnap fetch extract 
 </pre> 

 h1. h2. Apache 2.4 & PHP – Installation and Configuration 

 * Install Apache 2.4 with mod_php5 
 <pre> 
 pkg install apache24 php5 mod_php5 php5-xml php5-dom libgpg-error php5-xmlreader php5-simplexml php5-ctype php5-fileinfo php5-openssl php5-hash php5-filter openldap-client xproto xextproto libXau libXdmcp libpthread-stubs kbproto libICE freetype2 png jpeg printproto php5-exif curl php5-json php5-sqlite3 php5-pdo php5-mysql php5-mysqli php5-pdo_mysql oniguruma4 php5-iconv mp3info php5-zlib php5-zip php5-bz2 php5-session libgcrypt php5-wddx php5-ldap libxcb libSM php5-curl php5-pdo_sqlite php5-mbstring libxslt libX11 libXt php5-xsl libXext libXp libXmu libXpm libXaw t1lib php5-gd 
 </pre> 

 NOTE: This installs a few PHP extensions, add or remove as needed. 

 * Edit the apache configuration file, i.e. @/usr/local/etc/apache24/httpd.conf@, and make the following changes: 
 <pre> 
 ServerRoot "/usr/local" 
 ServerAdmin you@your.address 
 ServerName www.example.com:80 
 DocumentRoot "/usr/local/www" 
 Listen :80 
 NameVirtualHost *:80 

 <Directory "/usr/local/www"> 
     Options Indexes FollowSymLinks 

     AllowOverride None 

     Order allow,deny 
     Allow from all 
 </Directory> 

 Include etc/apache22/Includes/*.conf 
 </pre> 

 * Then create /usr/local/etc/apache24/Includes/mod_php5.conf: 
 <pre> 
 vi /usr/local/etc/apache24/Includes/mod_php5.conf 
 </pre> 
 #* And add the following: 
 <pre> 
 <IfModule dir_module> 
     DirectoryIndex index.php index.html 
 </IfModule> 

 <FilesMatch "\.php$"> 
     SetHandler application/x-httpd-php 
 </FilesMatch> 
 <FilesMatch "\.phps$"> 
     SetHandler application/x-httpd-php-source 
 </FilesMatch> 
 </pre> 

 * Edit the @/etc/hosts@ file and add the following line: 
 > <ip-address>                    <hostname>.<domain> 
 #* eg: 
 > 192.168.1.1                 www.example.com 

 * (Optional) Create a file named /boot/loader.conf or edit it if it is already present and add the following line: 
 > accf_http_load="YES" 
 * (Optional) Create a file named /usr/local/etc/apache24/Includes/no-accf.conf or edit it if it is already present and add the following lines to disable ACCF (I do this since I am in a jail that does not have the reuired kernel module): 
 <pre> 
 <IfDefine NOHTTPACCEPT> 
    AcceptFilter http none 
    AcceptFilter https none 
 </IfDefine> 
 </pre> 

 * Run the following line to enable apache24 to start at boot: 
 <pre> 
 echo 'apache24_enable="YES"' >> /etc/rc.conf 
 </pre> 

 * Test the apache server installation using the following command: 
 <pre> 
 service apache24 start 
 </pre> 

 h2. MariaDB – Installation and Configuration 

 * Install MariaDB 5.5 Server and Client 
 <pre> 
 pkg install mariadb55-{server,client} 
 </pre> 

 * Enable MariaDB to start at boot: 
 <pre> 
 echo 'mysql_enable="YES"' >> /etc/rc.conf 
 </pre> 

 * Start MariaDB 
 <pre> 
 service mysql-server start 
 </pre> 

 * Do some basic security to harden the MariaDB server: 
 <pre> 
 mysql_secure_installation 
 </pre>  

 h3. Configure MariaDB 

 * Use the following command: 
 <pre> 
 cp /usr/local/share/mysql/my-small.cnf /usr/local/etc/my.cnf 
 </pre> 

 * Restart mysql using the following commands: 
 <pre> 
 service mysql-server restart 
 </pre> 

 h2. PHP – Installation and Configuration 

 * Install PHP5 and other supporting packages: 
 <pre> 
 pkg install php5 php5-extensions 
 </pre> 

 * Copy the PHP configuration file using the following command 
 <pre> 
 cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini 
 </pre> 

 * Configure the mysql module for PHP: 
 <pre> 
 pkg install php5-mysql php5-mysqli php5-pdo_mysql 
 </pre> 

 * Install the php5-session package 
 <pre> 
 pkg install php5-session 
 </pre> 

 * Install and configuring apache module for PHP: 
 <pre> 
 pkg install mod_php5 
 </pre> 

 * Edit @/usr/local/etc/apache24/httpd.conf@ file and add the following lines: 
 <pre> 
 LoadModule php5_module          libexec/apache24/libphp5.so 
 </pre> 

 * Once completed, a simple call to the apachectl command for a graceful restart is needed to load the PHP module: 
 <pre> 
 service apache24 graceful 
 </pre> 

 For future upgrades of PHP, the make config command will not be required; the selected OPTIONS are saved automatically by the FreeBSD Ports framework. 

 The PHP support in FreeBSD is extremely modular so the base install is very limited. It is very easy to add support using the _lang/php5-extensions_ port. This port provides a menu driven interface to PHP extension installation. Alternatively, individual extensions can be installed using the appropriate port. 

 * Now restart the apache server by using the following command: 
 <pre> 
 service apache24 restart 
 </pre> 

 h2. h3. Install the Phusion Passenger module 

 Install and compile Phusion Passenger 
 <pre> 
 pkg install rubygem-passenger 
 passenger-install-apache2-module 
 </pre> 
 #* Then add the module in @/usr/local/etc/apache24/httpd.conf@: 
 <pre> 
 LoadModule passenger_module /usr/ports/www/rubygem-passenger/work/passenger-4.0.41/buildout/apache2/mod_passenger.so 
 <IfModule mod_passenger.c> 
   PassengerRoot /usr/ports/www/rubygem-passenger/work/passenger-4.0.41 
   PassengerDefaultRuby /usr/local/bin/ruby19 
 </IfModule> 
 </pre> 
 #* And now ruby web applications can be used by using the following template: 
 <pre> 
 <VirtualHost *:80> 
    ServerName www.yourhost.com 
    # !!! Be sure to point DocumentRoot to 'public'! 
    DocumentRoot /usr/local/www/rubyapp/public     
    <Directory /usr/local/www/rubyapp/public> 
       # This relaxes Apache security settings. 
       AllowOverride all 
       # MultiViews must be turned off. 
       Options -MultiViews 
    </Directory> 
 </VirtualHost> 
 </pre> 

 --- 
 h1. MariaDB – Installation and Configuration 

 * Install MariaDB 5.5 Server and Client 
 <pre> 
 pkg install mariadb55-{server,client} 
 </pre> 

 * Enable MariaDB to start at boot: 
 <pre> 
 echo 'mysql_enable="YES"' >> /etc/rc.conf 
 </pre> 

 * Start MariaDB 
 <pre> 
 service mysql-server start 
 </pre> 

 * Do some basic security to harden the MariaDB server: 
 <pre> 
 mysql_secure_installation 
 </pre>  

 h2. Configure MariaDB 

 * Use the following command: 
 <pre> 
 cp /usr/local/share/mysql/my-small.cnf /usr/local/etc/my.cnf 
 </pre> 

 * Restart mysql using the following commands: 
 <pre> 
 service mysql-server restart 
 </pre> 

 h3. Install and configure phpMyAdmin 

 * Install phpmyadmin: 
 <pre> 
 pkg install phpmyadmin 
 </pre> 

 * Setup phpMyAdmin for Apache 2.4 by creating @/usr/local/etc/apache24/Includes/phpmyadmin.conf@ and add the following: 
 <pre> 
 Alias /phpmyadmin "/usr/local/www/phpMyAdmin/" 
 
 <Directory "/usr/local/www/phpMyAdmin/"> 
     Options none 
     AllowOverride Limit 
     Order Deny,Allow 
     Require ip 127.0.0.1 
     Require ip ::1 
     #Require ip 192.168.1.0/255.255.255.0 
 </Directory> 
 </pre> 

 Now its time to configure phpMyAdmin. Do this by creating the file @/usr/local/www/phpMyAdmin/config.inc.php@, the basic configuration file for phpMyAdmin. Traditionally, users have manually created or modified @/usr/local/www/phpMyAdmin/config.inc.php@, but now phpMyAdmin includes a nice setup script, making it much easier to create this file with the settings you want.  

 * Start by creating the directory /usr/local/www/phpMyAdmin/config and make it writable by the phpMyAdmin setup script: 
 <pre> 
 mkdir /usr/local/www/phpMyAdmin/config 
 chmod o+w /usr/local/www/phpMyAdmin/config 
 </pre> 

 * Then make @/usr/local/www/phpMyAdmin/config.inc.php@ readable by the phpMyAdmin setup script: 
 <pre> 
 chmod o+r /usr/local/www/phpMyAdmin/config.inc.php 
 </pre> 

 * Now open your web browser and navigate to http://www.example.com/phpmyadmin/setup where you will see the phpMyAdmin setup _Overview_ page.  
 #* I use SSH tunnels for sensitive tasks like this: 
 <pre> 
 ssh -L 8081:localhost:80 www.example.com 
 </pre> 
 #* NOTE: This will make connections sent to the local computer on port 8081 be sent over SSH and appear as connections from the server itself. Since the above config has @Require ip 127.0.0.1@, all connections will be forbidden except from 127.0.0.1. 

 * Select *New Server* and then select the *Authentication* tab.  
 *# Under the *Authentication type* choose +http+ from the drop-down list (using HTTP-Auth to sign-in into phpMyAdmin will avoid storing login/password credentials directly in config.inc.php) 
 *# And remove +root+ from the *User for config auth*. 

 * Now select *Apply* and you will be returned you to the Overview page where you should see a new server listed.  

 * Select *Save* again in the Overview page to save your configuration as @/usr/local/www/phpMyAdmin/config/config.inc.php@.  

 * Now move that file up one directory to @/usr/local/www/phpMyAdmin@ where phpMyAdmin can make use of it. 
 <pre> 
 mv /usr/local/www/phpMyAdmin/config/config.inc.php /usr/local/www/phpMyAdmin   
 </pre>  

 * Now let’s try out phpMyAdmin to make sure it works. Point your web browser to http://www.example.com/phpmyadmin where you will be presented with a pop-up box requesting you to log in.  
 Use “root” and the MySQL password you set up previously, then you should be directed to the phpMyAdmin administration page.  

 * We no longer need the /usr/local/www/phpMyAdmin/config directory so let’s remove it, and the read permission we added previously to /usr/local/www/phpMyAdmin/config.inc.php: 
 <pre> 
 rm -r /usr/local/www/phpMyAdmin/config 
 chmod o-r /usr/local/www/phpMyAdmin/config.inc.php 
 </pre> 

 * And wrap up by restarting the Apache and MySQL servers: 
 <pre> 
 service apache24 restart 
 service mysql-server restart 
 </pre> 

 h2. *(Extra)* Easily deploying web applications 

 Now that the FAMP stack is operational, web applications can be run from this server. This can be done a number of ways, like using VHosts. However, if you want a single web application dedicated for the server, then FreeBSD already has a number of PHP/MySQL web applications in either the ports tree or pkg that allow for easy installation and upgrading.  

 * Start by creating a database using phpMyAdmin, or command line. 

 * Next, remove the original Apache data directory: 
 <pre> 
 rm -rf /usr/local/www/apache24/data 
 </pre> 

 h3. Deploy a web application 

 The following is a list of useful open source web applications that I use: 

 * Install ownCloud 
 <pre> 
 rm /usr/local/www/apache24/data 
 pkg install owncloud 
 chown -R www:www /usr/local/www/owncloud/ 
 ln -s /usr/local/www/owncloud /usr/local/www/apache24/data 
 </pre> 

 * Install WordPress 
 <pre> 
 rm /usr/local/www/apache24/data 
 pkg install wordpress 
 chown -R www:www /usr/local/www/wordpress/ 
 ln -s /usr/local/www/wordpress /usr/local/www/apache24/data 
 </pre> 

 * Install Magento 
 <pre> 
 rm /usr/local/www/apache24/data 
 pkg install magento 
 chown -R www:www /usr/local/www/magento/ 
 ln -s /usr/local/www/magento /usr/local/www/apache24/data 
 </pre> 

 * Install Piwik 
 <pre> 
 rm /usr/local/www/apache24/data 
 pkg install piwik 
 chown -R www:www /usr/local/www/piwik/ 
 ln -s /usr/local/www/piwik /usr/local/www/apache24/data 
 </pre> 

 * Install Redmine (Not PHP; read Passenger install above) 
 <pre> 
 rm /usr/local/www/apache24/data 
 pkg install redmine 
 chown -R www:www /usr/local/www/redmine/ 
 ln -s /usr/local/www/redmine/public /usr/local/www/apache24/data 
 </pre> 

 h2. Resources 

 * http://fosskb.wordpress.com/2014/04/10/famp-installing-apache2-4-mysql-php-on-freebsd-10/

Back