简体   繁体   中英

How install and configure manually php and apache?

Installed PHP like this:

wget http://in1.php.net/distributions/php-5.3.28.tar.bz2 tar -xvf php-5.3.28.tar.bz2 cd php-5.3.28 ./configure make make install

Installed Apache2 like this:

sudo apt-get install apache2

So, how do I now link Apache to PHP?

PS - I know I can install PHP as a module which will be 100x easier, but I want to know how to link exactly these two in this way.

Thanks.

Edit your httpd.conf to load the PHP module. The path on the right hand side of the LoadModule statement must point to the path of the PHP module on your system. The make install from above may have already added this for you, but be sure to check.

LoadModule php5_module modules/libphp5.so

Tell Apache to parse certain extensions as PHP. For example, let's have Apache parse .php files as PHP. Instead of only using the Apache AddType directive, we want to avoid potentially dangerous uploads and created files such as exploit.php.jpg from being executed as PHP. Using this example, you could have any extension(s) parse as PHP by simply adding them. We'll add .php to demonstrate.

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

Or, if we wanted to allow .php, .php2, .php3, .php4, .php5, .php6, and .phtml files to be executed as PHP, but nothing else, we'd use this:

<FilesMatch "\.ph(p[2-6]?|tml)$">
    SetHandler application/x-httpd-php
</FilesMatch>

And to allow .phps files to be handled by the php source filter, and displayed as syntax-highlighted source code, use this:

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

And restart Apache

service httpd restart

You can read how do that in the php documentation

http://php.net/manual/en/install.unix.apache2.php

http://php.net/manual/en/install.unix.apache2.php#92797

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM