How to install the PHP environment in Ubuntu under Apache

Source: Internet
Author: User

Recently you need to run PHP on a apache+tomcat server, so you have to let Apache support PHP. In addition, the environment is now generally PHP will even MySQL and PostgreSQL, so the installation of the need to be MySQL and PostgreSQL functions plus. Between Apache and PHP I choose module mode directly, not using FASTCGI management.

1. Install Apache

This one's not going to work. I can use a key script: http://download.chekiang.info/apache/ubuntu_apache.sh

can refer to this article http://www.111cn.net/sys/linux/42130.htm

2. Installation dependence

The most common dependencies are put on and start the installation.

Apt-get Install libpq5 Libpq-dev #为了支持postgresql
Apt-get Install Zlib1g-dev libbz2-dev libcurl4-gnutls-dev libjpeg-dev libpng12-dev libfreetype6-dev Libmcrypt-dev Libxml2-dev

3. Compile and install PHP

Select the latest PHP 5 source pack to download the decompression.

wget http://cn2.php.net/distributions/php-5.5.36.tar.gz
Tar zxvf php-5.5.36.tar.gz

Compile

CD php-5.5.36
./configure--prefix=/usr/local/php--with-config-file-path=/usr/local/php/etc--with-apxs2=/usr/local/apache2/ Bin/apxs--with-bz2--with-curl--with-jpeg-dir--with-gd--enable-shared--enable-mbstring--with-mcrypt--enable-fpm --enable-bcmath--with-zlib--enable-zip--enable-ftp--with-gettext--enable-sockets-- With-iconv-dir--with-png-dir--with-libxml-dir=/usr--enable-xml--disable-rpath--disable-rpath-- Disable-rpath--enable-sysvsem--enable-inline-optimization--enable-mbregex--enable-gd-native-ttf--with-openssl- -with-mhash--enable-pcntl--with-xmlrpc--enable-soap--disable-fileinfo--with-mysql=mysqlnd --with-pdo-mysql=mysqlnd--with-pdo-pgsql--with-pgsql

Installation

Make && make install

After the installation is complete, you can see that the Apache Profile httpd.conf module adds a similar line to the following:

LoadModule Php5_module modules/libphp5.so

4, modify the PHP configuration

CP Php.ini-production/usr/local/php/etc/php.ini
Sed-i ' s/post_max_size = 8m/post_max_size = 50m/g '/usr/local/php/etc/php.ini
Sed-i ' s/upload_max_filesize = 2m/upload_max_filesize = 50m/g '/usr/local/php/etc/php.ini
Sed-i ' s/;d ate.timezone =/date.timezone = prc/g '/usr/local/php/etc/php.ini
Sed-i ' S/short_open_tag = Off/short_open_tag = On/g '/usr/local/php/etc/php.ini
Sed-i ' s/; Cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g '/usr/local/php/etc/php.ini
Sed-i ' s/; Cgi.fix_pathinfo=0/cgi.fix_pathinfo=0/g '/usr/local/php/etc/php.ini
Sed-i ' s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g '/usr/local/php/etc/php.ini
Sed-i ' s/max_execution_time = 30/max_execution_time = 300/g '/usr/local/php/etc/php.ini
Sed-i ' s/disable_functions =.*/disable_functions = Passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc _open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_ Socket_server/g '/usr/local/php/etc/php.ini

First copy the Php.ini-production file to the PHP configuration directory, and then modify several common parameters. Reference military Brother's PHP installation script.

5, modify Apache restart

Add the following, or Apache does not recognize the file at the end of PHP.

<ifmodule mime_module>
AddType application/x-httpd-php. php
AddType Applicaiton/x-httpd-php-source. Phps
</IfModule>

And finally, don't forget to add index.php to the DirectoryIndex.

<ifmodule dir_module>
DirectoryIndex index.html index.php
</IfModule>
Everything's fine, you can access the PHP project after restarting Apache.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.