One can install PHP with apache2 in two ways, either by compiling from source code or from repositories by using a package manager. Both ways are discussed below.
Installing from repositories : This is very simple and straight forward method to install PHP. Open the terminal and type
sudo yum install php php-mysql
PHP installation will start and prompt you to confirm install. Give a positive response and you are done in a while.
Compiling from source : To compile PHP from source, follow the following steps :
1. download PHP source from PHP Websitehttp://php.net/downloads.php You can choose to download it in one of the three formats available .tar.bz2 or .tar.gz or .tar.xz
2. Extract it. Execute,
tar -xvf <path to archive>
The extraction command can vary depending on the format of archive downloaded.
3. Create a MakeFile in extracted source code directory. Paste following contents in it :
./configure \
--with-apxs2=/usr/local/apache/bin/apxs \
--with-mysql \
--prefix=/usr/local/apache/php \
--with-config-file-path=/usr/local/apache/php \
--enable-force-cgi-redirect \
--disable-cgi \
--with-zlib \
--with-gettext
What we just did?, Lets see one by one,
Only required lines in above snippet are --with-apxs2 and prefix lines.
--with-mysql is needed to add MySQL (which is the default choice for DBMS in almost all applications).
Note : You need to specify the directory if it's in a unusual location (e.g., --with-mysql=/usr/local)
--with-config-file moves the php.ini file location
--disable-cgi disables the CGI version (Since it is not necessary while using Apache modules).
--with-zlib allows use of gzip-type compression,
--with-gettext is for internationalization
For more information about configure, visit PHP website.
4. Use the created Makefile to make PHP
make
5. Once make executed successfully, install PHP using
make install
If it fails, try again as root.
Make install-su
6. Check whether libphp5 exists and is updated. If not, copy it from libs to apache module directory. Type
cp -p .libs/libphp5.so /usr/local/apache/modules
7. Install php.ini
cp -p php.ini-recommended /usr/local/apache/php/php.ini
8. Check for the following directives in /usr/local/apache/conf/httpd.conf . If not present add them,
LoadModule php5_module modules/libphp5.so
AddHandler php5-script .php
DirectoryIndex index.html index.php
AddType application/x-httpd-php-source phps
9. Restart apache
sudo service httpd restart
0 Comment(s)