首先介绍一下我如何安装PHP,Apache和一些Apache模块:
# apt-get -y install php5 php-pear libapache2-mod-php5 php-apc php5-mysql php5-mcrypt php5-xmlrpc php5-curl php5-imagick php5-gd php5-imap php5-pspell # apt-get -y install apache2 apache2-doc apache2-utils # a2enmod setenvif headers deflate filter expires rewrite include
而我的httpd.conf文件看起来像这样(即我已经基本禁用.htaccess,并具有在httpd.conf中的所有规则):
<Directory /var/www/example.com/public> AllowOverride None [...] </Directory>
考虑到它会给你一个如何设置我的networking服务器的基本想法,我想继续问问题:
Apache在安装PHP的静态内容方面比较慢,这是真的吗? ( 我猜 )
比方说,我的网站的根目录是'/var/www/example.com/public',我在'/var/www/example.com/public/uploads中有所有的静态内容(CSS,JS,图片) “; 如何克服问题(1),而不必将所有静态内容移动到没有安装PHP的服务器?
这取决于你如何configurationApache与PHP,你如何优化你的configuration。 如果phpconfiguration了CGI接口,那么apache只会将某些types的文件从外部传递到php(例如,与nginx相同),所以对其他文件的影响是0,如果是模块,可能会更快dynamic页面,因为它不是在外部调用PHP,但可能会慢其他人,因为PHP模块始终加载Apache,尽pipe它仍然只对某些types的文件(根据MIMEtypes)活动。
是/否
使用mod_fcgid与PHP
configuration为模块的php示例,仅parsing.php文件(RHEL5 / 6,Fedora):
[root@main ~]# cat /etc/httpd/conf.d/php.conf # # PHP is an HTML-embedded scripting language which attempts to make it # easy for developers to write dynamically generated webpages. # <IfModule prefork.c> LoadModule php5_module modules/libphp5.so </IfModule> <IfModule worker.c> LoadModule php5_module modules/libphp5-zts.so </IfModule> # # Cause the PHP interpreter to handle files with a .php extension. # AddHandler php5-script .php AddType text/html .php # # Add index.php to the list of files that will be served as directory # indexes. # DirectoryIndex index.php # # Uncomment the following line to allow PHP to pretty-print .phps # files as PHP source code: # AddType application/x-httpd-php-source .phps
刚刚发现。 通过在你的httpd.conf文件中添加如下内容,可以禁用目录中的PHP处理(以及其子目录):
<Directory "/var/www/example.com/public/uploads"> # Turn PHP parsing off php_flag engine off # Make .htaccess ineffective in the said directory AllowOverride None # Make index.php ineffective DirectoryIndex Off # (Optional) Show content of PHP files in browser (as if it were a text file) AddType text/plain .php .php3 .php4 .php5 .php6 .phtml RewriteEngine On # Return '403 Forbidden' for PHP files RewriteRule \.php$ - [F,L] </Directory>
如果使用.htaccess文件,请在您的静态内容目录(在我的案例“/var/www/example.com/public/uploads”)中放入一个以下条目:
# Turn PHP parsing off php_flag engine off # Make index.php ineffective DirectoryIndex Off # (Optional) Show content of PHP files in browser (as if it were a text file) AddType text/plain .php .php3 .php4 .php5 .php6 .phtml RewriteEngine On # Return '403 Forbidden' for PHP files RewriteRule \.php$ - [F,L]
另外,我刚刚意识到,如果你的应用程序已经使用了一个caching层,像Varnish,例如,在Apache服务caching页面和静态内容之前的Varnish,你不需要做任何事情!