Personalize this online document.
Replace the generic LOGIN
by the value specific to you.
Linux Configuration
Please be aware that many of the configuration choices we make in the installation of Apache/Php are intended for a single user on a system intended primarily for development purposes. If this is system were to be deployed for public usage and/or with multiple users, various security considerations would cause us to make many different configuration changes.
In many situations you will need to edit system configuration files (as root). Here are some possibilities for doing so:$ sudo gedit <SOME CONFIG FILE> graphical $ sudo vim <SOME CONFIG FILE> non-graphical $ sudo nano <SOME CONFIG FILE> non-graphicalAlso be aware that the symbol "~" represents the your home directory.
Apache
Install these packages, more than our immediate needs, but useful later:$ sudo apt-get install apache2 apache2-doc libapache2-mod-php5 \ php5 php5-cli php5-cgi php5-mysql php5-gd php5-curl php5-sqliteUbuntu maintains two differently compiled versions of Apache, only one of which is compatible with the Php installation. The key files and directories for Apache are these:
/etc/apache2/ config files, modules, etc. /etc/apache2/apache2.conf main config file /etc/httpd/conf.d/*.conf additional statup scripts /etc/apache2/modules-* available/enabled config files for modules /etc/apache2/sites-* available/enabled site definitions /var/www/ Apache root /etc/init.d/apache2 control script /usr/lib/apache2/ Apache modulesMost likely the Apache Web service will start automatically, but if not, start it by:
$ sudo service apache2 startIf Apache complains about lack of a host name (on a local system), edit /etc/apache2/httpd.conf and add the (only) line:
ServerName localhostWhenever you do an editing change to any configuration file (such as installing Web-related modules, etc.) you need to reload the server to pick up the changes. In Ubuntu, this operation is:
$ sudo service apache2 reload
Basic Test of the Apache installation
Open up an internet browser and enter the URL for your local site: You should see the Apache default root page. If for some reason this doesn't appear, the Apache Server may need to be started. For Windows, as usual, consider rebooting the computer if it doesn't work.Create a default URL
Apache on Linux systems can readily be configured to support the association of the URLhttp://localhost/~LOGINto a specific directory on your system. By default, this directory is
~/public_htmlTypically this directory needs to be created:
$ mkdir ~/public_htmlCheck the permissions on your home directory to ensure that Apache can pass through it:
$ ls -ld ~If what you see is
drwxr-xr-xthen Apache can pass through. In contrast, if you see
drwx------then you need to modify the permissions like this:
$ chmod 751 ~
Apache configuration changes
The first step is to permit user directories in the "usual" sense. Enable the Apache userdir module by doing:$ sudo a2enmod userdir $ sudo service apache2 reloadAfter reloading, Apache will permit access to public_html via the URL: Being the system admin, you will want to augment the default capabilities assigned to user we sites. Create the file
/etc/apache2/conf.d/local.confwith this content:
<Directory "/home/LOGIN/public_html"> AllowOverride All Options All Order allow,deny Allow from all </Directory>
Make your home site the URL /default
This is optional. For convenience of exposition, it is often easier to use a URL name that does not refer to a specific user login. If you want to make your home site respond to the URL:
/default
it can be done simply by adding the line to /etc/apache2/conf.d/local.conf:
Alias /default "/home/LOGIN/public_html"
Php
Php can be used in one of three variants:- as an Apache module
- as an Web-based CGI programming language; especially in conjuction with FastCGI
- as a command-line interpreter
/etc/php5/ all config files /etc/php5/apache2/php.ini main config file for Apache /etc/php5/cli/php.ini main config file for command-line /etc/php5/conf.d added config files (for both) /usr/bin/php the command-line interpreter /usr/lib/apache2/libphp5.so the Apache Php module /usr/lib/php5/20__________/ the Php plugin modules
Modifications to Apache
As of Ubuntu version 10.04, it is necessary to make a modification of a basic configuration file to permit Php to work in user directories. You have to edit/etc/apache2/mods-enabled/php5.confThe installation file looks like this:
<IfModule mod_php5.c> <FilesMatch "\.ph(p3?|tml)$"> SetHandler application/x-httpd-php </FilesMatch> <FilesMatch "\.phps$"> SetHandler application/x-httpd-php-source </FilesMatch> # To re-enable php in user directories comment the following lines # (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it # prevents .htaccess files from disabling it. <IfModule mod_userdir.c> <Directory /home/*/public_html> php_admin_value engine Off </Directory> </IfModule> </IfModule>
#<IfModule mod_userdir.c> # <Directory /home/*/public_html> # php_admin_value engine Off # </Directory> #</IfModule>
Edit the Php configuration file
The file to edit is/etc/php5/apache2/php.iniThis config file is rather large, and so it is often easiest to use a find utility in the editor to locate the relevant configuration setting. Look for and modify these settings:
-
Default Timezone.
Setting this in the config file will simplify coding and avoid warnings for time access
functions. Search for the "date.timezone" and make the setting
(suitable for the Middle Atlantic region):
date.timezone = "America/New_York"
- Error display settings.
In a production environment, error display should always be turned off
so as to avoid the inadvertent revealing of server error information.
However, error display is
extremely convenient for debugging in a development environment.
Search for display_errors
and verify that it is on (if not, change the value):
display_errors = On
You'll also want to look (in the section just above) for the error_reporting setting. We want it to be the default valueerror_reporting = E_ALL & ~E_NOTICE
Probably the simplest thing to do is to comment out whatever the setting may be, e.g.:;error_reporting = E_ALL & ~E_STRICT
We want to turn off a variety of notices given by Php. These notices are somewhat annoying but can be useful for debugging your Php code. If necessary, you can adjust the error reporting settings directly in your Php code.
Install MySQL and test Php/MySQL
We will refer you to the document MySQL on Ubuntu Linux. You need to go through the MySQL Installation section in full. After a successful installation, start up a command shell (it doesn't have to be administrative) and execute these commands to get the setup necessary for our test program:> mysql -u root mysql> create database if not exists test; mysql> select user from mysql.user; (verify absence of "guest" user) mysql> create user guest@localhost; (if necessary) mysql> grant all on test.* to guest@localhost; mysql> quit;