Menu
You can configure your PHP environment using a.htaccess file.htaccess is an Apache configuration file that can be used to set up directory-related rules.
This chapter explains how to install and test Oracle Database and PHP environment. It has the following topics:
What You Need
To install your Oracle Database and PHP environment, you need:
- Oracle Database Server which includes the sample data for this tutorial
- Oracle Database Client libraries are included with the Oracle Database software or can be installed using Oracle Instant Client
- Apache HTTP Server which is typically already installed on Linux computers
- PHP - PHP Hypertext Preprocessor
- A text editor for editing PHP code. A code editor such as Oracle JDeveloper with the optional PHP Extension can also be used.
Installing Oracle Database
You should install Oracle Database Server on your computer. The sample data used in this tutorial is installed by default. It is the HR component of the Sample Schemas.
Throughout this tutorial Oracle SQL Developer is the graphical user interface used to perform Database tasks. Oracle SQL Developer is a free graphical tool for database development.
See Also:
- Oracle Database Sample Schemas guide for information about the
HR
sample schema. - Oracle SQL Developer web page
Unlocking the HR User
The PHP application connects to the database as the HR user. You may need to unlock the
HR
account as a user with DBA privileges. To unlock the HR
user:- Open SQL Developer and open a connection to your Oracle database.
- Login to your Oracle database as system.
- Open SQL Worksheet or SQL*Plus and run the following SQL statement:
Description of the illustration chap2_unlock.gif
For further information about unlocking an Oracle Database account, see Chapter 6, 'Managing Users and Security,' in the Oracle Database 2 Day DBA guide.
See Also:
- Oracle Database documentation
Installing Apache HTTP Server
You should install Apache before you install PHP. Apache is typically installed by default on Linux computers. See Testing the Apache Installation on Linux before downloading the Apache software.
Perform the following steps to obtain Apache HTTP Server for Windows or Linux:
- Enter the following URL in your Web browser:
- For Windows, click the apache_2.2.12-win32-x86-no_ssl.msi. For Linux, click httpd-2.2.12.tar.bz2.
- Save the downloaded file in a temporary directory, such as
c:tmp
on Windows ortmp
on Linux.
Installing Apache on Windows
This section describes how to install Apache HTTP Server on Windows.
The file name and extraction directory are based on the current version. Throughout this procedure, ensure you use the directory name for the version you are installing.
You must be the administrator user to install Apache.
To install Apache, double-click the file and follow the wizards.
The default installation directory is likely to be
C:Program FilesApache Group
. This is the directory that is assumed for the tutorial exercises. If you install to a different directory, you need to note the directory so you can change the path used in the tutorials.Starting and Stopping Apache on Windows
You can use the Start menu option to start Apache. This opens a console window showing any error messages. Error messages may also be written to
C:Program FilesApache GroupApache2logserror.log
.You can also use the ApacheMonitor utility to start Apache. It will appear as an icon in your System Tray, or navigate to the Apache
bin
directory and double click ApacheMonitor.exe
. In a default installation, Apache bin
is located at c:Program FilesApache GroupApache2bin
.You can also use the Windows Services to start Apache. You access Windows Services from the Windows Start menu at Start > Control Panel > Administrative Tools > Services. Select the Standard tab. Right click the Apache2 HTTP Server and then select Restart
If you have errors, double check your
httpd.conf
and php.ini
files.Testing the Apache Installation on Windows
To test the Apache HTTP Server installation:
- Start your Web browser on the computer on which you installed Apache.
- Enter the following URL:Your Web browser will display a page similar to the following:
Description of the illustration chap2_test_install_013.gifIf this page does not appear check your Apache configuration. Common problems are that Apache is not running, or that it is listening on a non-default port.
Installing Apache on Linux
This section describes how to install Apache HTTP Server on Linux.
The file name and extraction directory are based on the current version. Throughout this procedure, ensure you use the directory name for the version you are installing.
Apache is typically already installed on Linux. If you find it is not installed after Testing the Apache Installation on Linux, perform the following steps to install the Apache HTTP Server:
- Go to the directory where you downloaded the
httpd-2.2.12.tar.bz2
file. - Log in as the root user and execute these commands:The option
--enable-module=so
allows PHP to be compiled as a Dynamic Shared Object (DSO). The--prefix=
option sets the Apache installation directory used by the commandmake install
Starting and Stopping Apache on Linux
You use the apachectl script to start and stop Apache.
Start Apache with the
apachectl
script:Stop Apache with the
apachectl
script:When you start Apache, you must have ORACLE_HOME defined. Any other required Oracle environment variables must be set before Apache starts too. These are the same variables set by the
$ORACLE_HOME/bin/oracle_env.sh
or the /usr/local/bin/oraenv
scripts.For convenience, you could create a script to start Apache as follows:
Testing the Apache Installation on Linux
To test the Apache HTTP Server installation:
- Start your Web browser on the host on which you installed Apache, and enter the following URL:Your Web browser will display a page similar to the following:
Description of the illustration chap2_install_001.gifIf this page does not appear, check your Apache configuration. Common problems are that Apache is not running, or that it is listening on a non default port. - In the default Apache HTTP Server configuration file, set up a public virtual directory as
public_html
for accessing your PHP files. Use your preferred editor to open the Apache configuration file/etc/httpd/conf/httpd.conf
(the directory may be different in your installation of Linux), and remove the pound sign (#) at the start of the following line:In this example, your Apachehttpd.conf
file contains the following lines:This enables the Web browser to make an HTTP request using a registered user on the system and to serve files from the$HOME/public_html
directory of the user. For example: - To use the new Apache configuration file, in a command window, restart Apache by entering the following commands:
Description of the illustration chap2_install_002.gifIf the Apache HTTP Server does not start, check the error log files to determine the cause. It may be a configuration error. - In the command window, log in (not root) and create a
public_html
subdirectory in the$HOME
directory with the following command:
Description of the illustration chap2_install_003.gif
Installing PHP
Perform the following steps to obtain PHP for Windows or Linux:
- Enter the following URL in your Web browser:
- For Windows, click the 5.2.10 zip package under Windows Binaries. For Linux, click php-5.2.10.tar.bz2 under Complete Source Code.
- Save the downloaded file in a temporary directory, such as
c:tmp
on Windows ortmp
on Linux.
Installing PHP on Windows
This section describes how to install PHP on Windows.
The file name and extraction directory are based on the current version. Throughout this procedure, ensure you use the directory name for the version you are installing.
You must be the administrator user to install PHP. To install PHP, perform the following steps:
- In Windows Explorer, go to the directory where you downloaded the PHP 5.2.10 zip file.
- Unzip the PHP package to a directory called
C:php-5.2.10
- Copy
php.ini-recommended
toC:Program FilesApache GroupApache2confphp.ini
- Edit php.ini to make the following changes:
- Change
extension_dir
toC:php-5.2.10ext
, which is the directory containingphp_oci8.dll
and the other PHP extensions. - Remove the semicolon from the beginning of the lineextension=php oci8.dll
- Set the PHP directive,
display_errors
, toOn
. For testing it is helpful to see any problems in your code.
- Edit the file
httpd.conf
and add the following lines. Make sure you use forward slashes '/' and not back slashes ': - Restart the Apache Server so that you can test your PHP installation.You can use the Start menu option to start Apache. This opens a console window showing any error messages. Error messages may also be written to
C:Program FilesApache GroupApache2logserror.log
.You can also use the ApacheMonitor utility to start Apache. It will appear as an icon in your System Tray, or navigate to the Apachebin
directory and double clickApacheMonitor.exe
. In a default installation, Apachebin
is located atc:Program FilesApache GroupApache2bin
.You can also use the Windows Services to start Apache. You access Windows Services from the Windows Start menu at Start > Control Panel > Administrative Tools > Services. Select the Standard tab. Right click the Apache2 HTTP Server and then select RestartIf you have errors, double check yourhttpd.conf
andphp.ini
files.
Installing PHP on Linux
This section describes how to install PHP on Linux.
The file name and extraction directory are based on the current version. Throughout this procedure, ensure you use the directory name for the version you are installing.
Perform the following steps to install PHP:
- Go to the directory where you downloaded the
php-5.2.10.tar.bz2
file. - Log in as the root user and execute these commands:Check the value for ORACLE_HOME to ensure it reflects your Oracle version and installation.If you are behind a firewall, you may need to set the environment variable
http_proxy
to your proxy server before runningmake install
. This enables PHP's PEAR components to be installed. - Copy PHP's supplied initialization file:For testing it is helpful to edit
php.ini
and set the PHP directive,display_errors
, toOn
so you can see any problems in your code. - Edit Apache's configuration file /usr/local/apache/conf/httpd.conf and add the following lines:If a LoadModule line was not inserted by the PHP install, add it with:
- Restart the Apache Server to test your PHP installation with the following:If there are errors, they will display on your screen. They may also be written to
/usr/local/apache/logs/error_log
. If you have problems, double check yourhttpd.conf
andphp.ini
files.
Testing the PHP Installation
To test the PHP installation:
- Create a subdirectory called
chap2
. To create a directory for your application files, and to change to the newly created directory, enter the following commands in a command window:On Windows:On Linux:If you create files in a different location, you must change the steps for file editing and execution to match your working directory name and URL. - Create a file called
hello.php
that contains the following HTML text: - Open a Web browser and enter the following URL in your browser:On Windows:On Linux:The line 'Hello, world!' appears in the browser.
Description of the illustration chap2_hello_001.gif
Active8 months ago
I can find the php5 mod in the mods-available directory, but I'm not sure how to get it into the mods-enabled directory.
Also, I just wanted to check that this is the way to enable php on my device...I know that PHP is installed, but another dev has disabled it (and is uncontactable)!
Rocket Hazmat178k3535 gold badges259259 silver badges305305 bronze badges
SE_1991SE_1991
3 Answers
You can use
a2enmod
or a2dismod
to enable/disable modules by name.From terminal, run:
Patrick MoorePatrick Mooresudo a2enmod php5
to enable PHP5 (or some other module), then sudo service apache2 reload
to reload the Apache2 configuration.11.3k44 gold badges2828 silver badges5757 bronze badges
If anyone gets
ERROR: Module phpX.X does not exist!
just install the module for your current php version:
JHoerbstJHoerbst
You have two ways to enable it.
First, you can set the absolute path of the php module file in your httpd.conf file like this:
Second, you can link the module file to the mods-enabled directory:
Lucas MendesLucas Mendes