當前位置:首頁 » 編程軟體 » nginx編譯支持php

nginx編譯支持php

發布時間: 2024-08-14 21:10:26

『壹』 如何在linux下使Nginx和Apache共存,並同時支持php

1、mysql,參考linux下源碼安裝mysql

2、php,參考linux下源碼安裝nginx + php筆錄

編譯參數:./configure --prefix=/usr/local/php --with-gd --enable-gd-native-ttf --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-mysql=/usr/local/mysql --enable-fastcgi --enable-fpm --with-mysqli=/usr/local/mysql/bin/mysql_config

3、nginx,參考linux下源碼安裝nginx + php筆錄

4、apache,

編譯參數:./cigure --prefix=/usr/local/apache2 --enable-so --enable-mods-shared=most

查看以前的編譯選項(如果以前安裝過的話):cat /usr/local/apache2/build/config.nice

http.conf添加以下兩行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

虛擬主機設置:

<VirtualHost 192.168.42.129>
ServerAdmin [email protected]
DocumentRoot /var/www/other-test
ServerName other-test.com
ErrorLog logs/www.other-test.com-error_log
CustomLog logs/www.other-test.com-access_log common
<Directory "/var/www/other-test">
Options Indexes FollowSymlinks MultiViews
AllowOverride None
DirectoryIndex index.html index.php
Order allow,deny
Allow from All
</Directory>
</VirtualHost>

5、重新編譯、安裝php是能夠在apache上運行,編譯參數:./configure --prefix=/usr/local/php --with-gd --enable-gd-native-ttf --with-freetype-dir --with-jpeg-dir --with-png-dir --with-mysql=/usr/local/mysql --with-zlib --enable-fastcgi --enable-fpm --with-apxs2=/usr/local/apache2/bin/apxs --with-mysqli=/usr/local/mysql/bin/mysql_config

cp php.ini-dist /usr/local/php/lib/php.ini

重啟apache,如果發現正斗錯誤「cannot restore segment prot after reloc: Permission denied」解決方案舉判磨:

1. chcon -t /usr/local/apache2/moles/libphp5.so
2. #vi /etc/sysconfig/selinux file 或者用 #gedit /etc/沖唯sysconfig/selinux file 修改SELINUX=disabled 重啟

『貳』 雲伺服器如何配置nginx支持php

[root@redhat7 ~]# wget http://am1.php.net/get/php-7.1.2.tar.gz/from/this/mirror
[root@redhat7 ~]# tar xzvf php-7.1.2.tar.gz
[root@redhat7 ~]# cd php-7.1.2/
[root@redhat7 ~]# ./configure --prefix=/usr/local/php --enable-fpm
[root@redhat7 php-7.1.2]# make&&make install
查看是否成功編譯安裝PHP
[root@redhat7 php-7.1.2]# php -v
PHP 7.1.2 (fpm-fcgi) (built: Apr 14 2017 20:21:53)
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies

編譯安裝完成後PHP不具備配置文件php.ini,此時只需復制php.ini-proction到 /usr/local/lib/php.ini即可,php.ini文件一般在/usr/local/lib/和/etc目錄下

[root@localhost php-7.1.2]# cp php.ini-proction /usr/local/lib/php.ini
[root@redhat7 php]# /usr/local/php/sbin/php-fpm
[14-Apr-2017 20:59:49] ERROR: failed to open configuration file '/usr/local/php/etc/php-fpm.conf': No such file or directory (2)
[14-Apr-2017 20:59:49] ERROR: failed to load configuration file '/usr/local/php/etc/php-fpm.conf'
[14-Apr-2017 20:59:49] ERROR: FPM initialization failed
啟動php-fpm發現缺乏配置文件/usr/local/php/etc/php-fpm.conf
此時只需復制php-fpm的配置文件在安裝php時提供的配置文件的模版/usr/local/php/etc/php-fpm.conf.default到相應/usr/local/php/etc/php-fpm.conf即可

[root@redhat7 etc]# /usr/local/php/sbin/php-fpm
[14-Apr-2017 21:14:32] WARNING: Nothing matches the include pattern '/usr/local/php/etc/php-fpm.d/﹡.conf' from /usr/local/php/etc/php-fpm.conf at line 125.
[14-Apr-2017 21:14:32] ERROR: No pool defined. at least one pool section must be specified in config file
[14-Apr-2017 21:14:32] ERROR: failed to post process the configuration
[14-Apr-2017 21:14:32] ERROR: FPM initialization failed

[root@redhat7 etc]# cp php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

[root@redhat7 etc]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
[root@redhat7 etc]# /etc/init.d/php-fpm
[14-Apr-2017 21:23:02] ERROR: unable to bind listening socket for address '127.0.0.1:9000': Address already in use (98)
[14-Apr-2017 21:23:02] ERROR: FPM initialization failed
[root@redhat7 etc]# netstat -nldp|grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 3721/php-fpm: maste
[root@redhat7 php-7.1.2]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@redhat7 php-7.1.2]# chmod a+x /etc/init.d/php-fpm
[root@redhat7 php-7.1.2]# ll /etc/init.d/php-fpm
-rwxr-xr-x 1 root root 2401 4月 14 21:26 /etc/init.d/php-fpm
[root@redhat7 php-7.1.2]# /etc/init.d/php-fpm start
Starting php-fpm [14-Apr-2017 21:28:09] ERROR: unable to bind listening socket for address '127.0.0.1:9000': Address already in use (98)
[14-Apr-2017 21:28:09] ERROR: FPM initialization failed
failed
[root@redhat7 php-7.1.2]# netstat -nldp |grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 3721/php-fpm: maste
[root@redhat7 php-7.1.2]# kill 3721
[root@redhat7 php-7.1.2]# netstat -nldp |grep 9000
[root@redhat7 php-7.1.2]# /etc/init.d/php-fpm start
Starting php-fpm done
[root@redhat7 php-7.1.2]# service php-fpm status
php-fpm (pid 3927) is running...
[root@redhat7 php-7.1.2]# chkconfig --add php-fpm
[root@redhat7 php-7.1.2]# chkconfig php-fpm --level 345 on

配置nginx支持PHP
修改nginx的配置文件,支持php文件的解析,找到location的添加位置,在後面添加下面這個location
location ~ .php$ {
root /usr/share/nginx/html; #指定php的根目錄
fastcgi_pass 127.0.0.1:9000;#php-fpm的默認埠是9000
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

『叄』 nginx配置支持php

nginx本身不支持php解析,需要配合php-fpm來配置。

location~.php${
root/var/www;#指定php的根目錄
fastcgi_pass127.0.0.1:9000;#php-fpm的默認埠是9000
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
includefastcgi_params;
}

centos下安裝php-fpm (php及其它組件已經安裝過的情況)

yuminstallphp-fpm

啟動php-fpm 並設置開機啟動 (centos 7)

systemctlstartphp-fpm
systemctlenablephp-fpm
熱點內容
動態規劃01背包演算法 發布:2024-11-05 22:17:40 瀏覽:849
nasm編譯器如何安裝 發布:2024-11-05 22:01:13 瀏覽:181
登錄密碼在微信的哪裡 發布:2024-11-05 22:00:29 瀏覽:739
c防止反編譯工具 發布:2024-11-05 21:56:14 瀏覽:248
安卓虛擬機怎麼用 發布:2024-11-05 21:52:48 瀏覽:344
php時間搜索 發布:2024-11-05 20:58:36 瀏覽:479
燕山大學編譯原理期末考試題 發布:2024-11-05 20:13:54 瀏覽:528
華為電腦出現臨時伺服器 發布:2024-11-05 20:05:08 瀏覽:408
斗戰神免費挖礦腳本 發布:2024-11-05 19:53:25 瀏覽:665
網吧伺服器分別是什麼 發布:2024-11-05 19:45:32 瀏覽:392