phpnginx安裝
A. linux怎麼快速安裝nginx和php,不用安裝資料庫
Linux下如果要搭建nginx和php環境,需要安裝三個軟體包:
nginx,php,php-fpm
比如說如果是centos的話:
yuminstallnginxphpphp-fpm
可能軟體包名有差別,這個查查就知道了。
然後配置nginx,修改nginx.conf,如果用sock就這樣寫,如果是埠就些埠:
location~.php${
fastcgi_passunix:/var/run/php-fpm/php-fpm.sock;
fastcgi_indexindex.php;
includefastcgi.conf;
}
然後啟動服務,以centos7為例:
systemctlstartnginx
systemctlstartphp-fpm
B. windows7配置Nginx+php+mysql的詳細操作是怎樣
在Windows下配置搭建PHP環境的步驟:
一、准備工作-下載所需軟體
Apache httpd-2.2.22-win32-x86-openssl-0.9.8t.msi
PHP php-5.3.10-Win32-VC9-x86.zip
MySQL mysql-5.5.20-win32.msi
二、安裝軟體
1、安裝Apache: 雙擊安裝,與安裝其他Windows軟體沒有什麼區別,在填Server Infomation時,並沒有特殊規定,只要輸入的信息符合格式即可。
安裝完成之後,在瀏覽器輸入http://localhost,如果顯示It Works!,表示Apache安裝成功。
2、安裝PHP:將php-5.3.10-Win32-VC9-x86.zip解壓到一個目錄即可。
3、安裝MySQL:雙擊答桐安裝,如果需要更改安裝目錄,則在Choose Setup Type選擇Custom
安裝完成後開肆舉迅始配置MySQL,全部保持默認選項即可,但最好把MySQL默認編碼改為utf8,在Modify Security Settings選項中設置密碼,輸入兩次密碼即可完成,最後點Execute完成配置。
三、整合Apache+PHP+MySQL
Apache : 首先修改Apache的配置文件,讓Apache支持解析裂此PHP文件。Apache配置文件在Apache安裝目錄的conf目錄下的httpd.conf。
1. 讓Apache可以解析php文件,在配置文件中找到
#LoadMole vhost_alias_mole moles/mod_vhost_alias.so
在下一行添加 (綠色的位置是根據PHP的所在目錄而定的)
LoadMole php5_mole "D:/Develop/PHP/php5apache2_2.dll"PHPIniDir "D:/Develop/PHP"AddType application/x-httpd-php .php .html .htm
2. 在配置文件中找到
DirectoryIndex index.html
改為
DirectoryIndex index.php index.html
3. 修改Apache站點目錄,在配置文件中找到(Apache安裝的目錄不同,顯示的值不一樣)
DocumentRoot "D:/Develop/Apache2.2/htdocs"
改為
DocumentRoot "D:/Workspace/PHP"
再找到
<Directory "D:/Develop/Apache2.2/htdocs">
改為
<Directory "D:/Workspace/PHP">
PHP : 把php.ini-development改名為php.ini,作為PHP的配置文件。修改php.ini
1. 設置PHP擴展包的具體目錄,找到
; On windows:; extension_dir = "ext"
改為 (值是ext文件夾的目錄)
; On windows: extension_dir = "D:/Develop/PHP/ext"
2. 開啟相應的庫功能,找到需要開啟的庫的所在行
;extension=php_curl.dll
;extension=php_gd2.dll
;extension=php_mbstring.dll
;extension=php_mysql.dll
;extension=php_xmlrpc.dll
去掉前面的分號(注釋),即改為
extension=php_curl.dll
extension=php_gd2.dll
extension=php_mbstring.dll
extension=php_mysql.dll
extension=php_xmlrpc.dll
3. 設置時區,找到
;date.timezone =
改為
date.timezone = Asia/Shanghai
配置完成,檢測一下配置是否成功。重啟Apache,在站點目錄下新建文件index.php,輸入內容。
C. 如何架設Nginx+Php Web伺服器
由於每個過程較繁瑣,所以這里說說具體步驟,每個步驟的具體內容可以網路搜索。
安裝步驟
一、 編譯安裝PHP5.2.9所需的支持庫
二、編譯安裝MySQL 5.1.34擴展庫
三、編譯安裝PHP(FastCGI模式)
四、修改php-fpm配置文件
五、創建www用戶組及www用戶
六、編譯安裝Nginx
七、創建fcgi.conf文件
八、編輯Nginx配置文件
九、配置開機自動啟動Nginx + PHP
十、優化Linux內核參數
D. ubuntu 14.04安裝nginx+php+mysql
本文將詳細指導如何在Ubuntu 14.04上搭建Nginx、PHP、MySQL環境,以解決舊資料可能帶來的困擾。操作步驟均通過命令行進行,確保環境的穩定性與高效性。
首先,為方便後續操作,切換到root許可權模式。
通過以下命令安裝系統所需的管理工具、添加Nginx與PHP的安裝源:
1. sudo su
2. apt-get install python-software-propertiesadd-apt-repository ppa:nginx/stableadd-apt-repository ppa:ondrej/php5
接著,更新系統軟體庫並安裝MySQL伺服器。
3. apt-get update
4. apt-get install mysql-server
隨後,安裝PHP及其相關的MySQL支持組件。
5. apt-get install php5 php5-fpm php5-mysql php-apc
針對實際需求,可以自選安裝PHP的各類功能模塊,包括:
6. apt-get install php-pear php5-dev php5-curl
7. apt-get install php5-gd php5-intl php5-imagick
8. apt-get install php5-imap php5-mcrypt php5-memcache
9. apt-get install php5-ming php5-ps php5-pspell
10. apt-get install php5-recode php5-snmp php5-sqlite
11. apt-get install php5-tidy php5-xmlrpc php5-xsl
完成PHP組件的安裝後,安裝Nginx作為Web伺服器。
12. apt-get install nginx
針對PHP配置文件進行調整,以優化Nginx與PHP-FPM的交互。
13. vi /etc/php5/fpm/php.ini
將cgi.fix_pathinfo=1更改為cgi.fix_pathinfo=0
然後,對Nginx的配置文件進行調整,以正確識別並處理PHP文件。
14. mkdir /www
15. chmod 755 /www
創建並設置許可權為755的/www目錄。
16. vi /etc/nginx/sites-enabled/default
將root路徑更改為root /www,並在index文件中增加index.php
17. 在location配置中,調整fastcgi參數,包括嘗試文件和fastcgi傳遞路徑,確保正確解析PHP文件。
18. 解決Nginx與PHP-FPM之間的小bug,通過在fastcgi_params配置文件中添加指定參數,以正確傳遞文件路徑。
19. 重啟所有相關服務,包括php5-fpm與nginx,以應用新配置。
20. vi /www/index.php,創建測試文件並添加PHP代碼,用於驗證環境配置。
21. 訪問http://localhost測試環境,如能正常輸出PHP環境信息,表明搭建成功。
E. centos5 婧愮爜瀹夎匩ginx + mysql + apache + php鐨勬柟娉
涓昏佷緷鐓х殑鏄寮犲寸殑涓綃囧崥鏂囥http://blog.s135.com/post/366/銆嬶紝瀹夎呯殑杞浠舵槸涔熸槸浠庝粬鎻愪緵鐨勫垪琛ㄤ腑涓嬭澆錛岃繖閲岄兘鏄痶ar.gz鏍煎紡錛屽傛灉鏇村笇鏈涙槸rpm鏍煎紡鐨勮瘽錛屾彁渚涗竴涓緗戝潃銆http://rpmfind.net/linux/rpm2html/search.php銆嬭繖閲屽垪鍑轟簡姣旇緝瀹屽叏鐨勪笅杞藉寘銆
鎴戝畨瑁呯殑緋葷粺錛欳entos5
1銆佷笅杞斤紱
鎴戝畨瑁呯殑涓嬭澆鏉ヨ嚜寮犲村崥鏂囦笅鐨勫湴鍧錛屼笅杞戒繚瀛樼殑鏄痟ome涓嬭嚜宸辯洰褰曠殑涓涓鏂囦歡澶逛笅錛
澶嶅埗浠g爜
浠g爜濡備笅:
cd /home/xuxx/software
wget http://blog.s135.com/soft/linux/nginx_php/nginx/nginx-0.7.51.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/php/php-5.2.8.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/phpfpm/php-5.2.8-fpm-0.5.10.diff.gz
wget http://blog.s135.com/soft/linux/nginx_php/mysql/mysql-5.1.33.zip
wget http://blog.s135.com/soft/linux/nginx_php/libiconv/libiconv-1.13.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/mcrypt/libmcrypt-2.5.8.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/mcrypt/mcrypt-2.6.8.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/memcache/memcache-2.2.5.tgz
wget http://blog.s135.com/soft/linux/nginx_php/mhash/mhash-0.9.9.9.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/pcre/pcre-7.8.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/eaccelerator/eaccelerator-0.9.5.3.tar.bz2
wget http://blog.s135.com/soft/linux/nginx_php/pdo/PDO_MYSQL-1.0.2.tgz
wget http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/imagick/imagick-2.2.2.tgz
2銆佸噯澶囩紪璇戝畨瑁呯幆澧冿紝闇瑕佺紪璇戞簮鐮佺敤鍒癵c++
寤鴻濡傛灉鏄鏂板畨瑁呯殑緋葷粺錛屼嬌鐢▂um upgrade鏇存柊涓嬬郴緇熴
澶嶅埗浠g爜
浠g爜濡備笅:
sudo -s
LANG=C
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel
glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel
openldap openldap-devel nss_ldap openldap-clients openldap-servers
娉ㄦ剰錛氳繖閲屾墍鏈夌殑鍛戒護鏄涓琛岀殑鑰屼笉鑳芥湁鎹㈣岀︼紝濡傛灉鏄痗opy鐨勬椂鍊欙紝娉ㄦ剰瑕佸幓澶勮ユ崲琛岀
紜淇濆畨瑁呮垚鍔燂紒鎵嶈兘姝g『浣跨敤緙栬瘧銆
3銆佸畨瑁咃細
涓銆佸畨瑁匬HP 5.2.8錛團astCGI妯″紡錛
1銆佺紪璇戝畨瑁匬HP 5.2.8鎵闇鐨勬敮鎸佸簱錛
1錛 libiconv搴
澶嶅埗浠g爜
浠g爜濡備笅:
tar zxvf libiconv-1.13.tar.gz
cd libiconv-1.13/
./configure --prefix=/usr/local
make
make install
make clean
make distclean
cd ../
make clean 鍜宮ake distclean閮芥槸鍒犻櫎瀹夎呰繃紼嬩腑鐢熸垚鐨勭紦瀛樻枃浠躲傚綋鐒跺傛灉浣犱笉浠嬫剰鏀劇潃涔熷彲浠ヨ煩榪囪繖涓ゆユ竻鐞嗘搷浣溿
2錛絣ibmcrypt搴
澶嶅埗浠g爜
浠g爜濡備笅:
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make
make install
make clean
make distclean
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
make clean
make distclean
cd http://www.cnblogs.com/
3] mhash搴
澶嶅埗浠g爜
浠g爜濡備笅:
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ../
4錛絤crypt搴
娉ㄦ剰錛氬洜涓鴻ュ簱鍜宭ibmcrypt鏈変緷璧栨э紝鎵浠ュ湪瀹夎呭墠蹇呴』鐭ラ亾libmcrypt錛屽惁鍒欑殑璇濅細鍑虹幇錛
閿欒
澶嶅埗浠g爜
浠g爜濡備笅:
checking for libmcrypt 鈥 version = 2.5.0鈥
*** 鈥榣ibmcrypt-config 鈥搗ersion鈥 returned 2.4.0, but LIBMCRYPT (2.5.8)
*** was found! If libmcrypt-config was correct, then it is best
*** to remove the old version of LIBMCRYPT. You may also be able to fix the error
*** by modifying your LD_LIBRARY_PATH enviroment variable, or by editing
*** /etc/ld.so.conf. Make sure you have run ldconfig if that is
*** required on your system.
*** If libmcrypt-config was wrong, set the environment variable LIBMCRYPT_CONFIG
*** to point to the correct of libmcrypt-config, and remove the file config.cache
*** before re-running configure
configure: error: *** libmcrypt was not found
鏄鍥犱負path鐨勯棶棰橈紝鎵浠ユ墽琛岋細
澶嶅埗浠g爜
浠g爜濡備笅:
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
鐒跺悗鍐嶅畨瑁咃細
澶嶅埗浠g爜
浠g爜濡備笅:
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../
浜屻佸畨瑁卪ysql
澶嶅埗浠g爜
浠g爜濡備笅:
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql xxx
unzip mysql-5.1.33.zip
cd mysql-5.1.33/
./configure --prefix=/usr/local/webserver/mysql/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables
--with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=innobase
make
make install
make clean
make distclean
chmod +w /usr/local/webserver/mysql
chown -R xxx:mysql /usr/local/webserver/mysql
cp support-files/my-medium.cnf.sh /usr/local/webserver/mysql/my.cnf
cd ../
娉ㄦ剰錛氳繖閲岀紪璇./configure鍛戒護鏄涓琛岀殑鑰屼笉鑳芥湁鎹㈣岀︼紝濡傛灉鏄痗opy鐨勬椂鍊欙紝娉ㄦ剰瑕佸幓澶勮ユ崲琛岀
鍦ㄦ渶鍚庝竴姝ユ嫹璐濈殑鏃跺欙紝鎴戝畨瑁呭畬鍦╯upport-files涓嬫病鏈塵y-medium.cnf鑰屽彧鏈塵y-medium.cnf.sh鎵浠ュ皢榪欎釜鏂囦歡鎷瘋礉榪囧幓銆
錛犲紶瀹村師鏂囷細
闄勶細浠ヤ笅涓洪檮鍔犳ラわ紝濡傛灉浣犳兂鍦ㄨ繖鍙版湇鍔″櫒涓婅繍琛孧ySQL鏁版嵁搴擄紝鍒欐墽琛屼互涓嬩袱姝ャ傚傛灉浣犲彧鏄甯屾湜璁㏄HP鏀鎸丮ySQL鎵╁睍搴擄紝鑳藉熻繛鎺ュ叾浠栨湇鍔″櫒涓婄殑MySQL鏁版嵁搴擄紝閭d箞錛屼互涓嬩袱姝ユ棤闇鎵ц屻
鈶犮佷互xxx鐢ㄦ埛甯愬彿鐨勮韓浠藉緩絝嬫暟鎹琛錛
澶嶅埗浠g爜
浠g爜濡備笅:
/usr/local/webserver/mysql/bin/mysql_install_db --basedir=/usr/local/webserver/mysql --datadir=/usr/local/webserver/mysql/data --user=xxx
鈶°佸惎鍔∕ySQL錛堟渶鍚庣殑琛ㄧず鍦ㄥ悗鍙拌繍琛岋級
澶嶅埗浠g爜
浠g爜濡備笅:
/bin/sh /usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/usr/local/webserver/mysql/my.cnf
3銆佺紪璇戝畨瑁匬HP錛團astCGI妯″紡錛
澶嶅埗浠g爜
浠g爜濡備笅:
tar zxvf php-5.2.8.tar.gz
gzip -cd php-5.2.8-fpm-0.5.10.diff.gz | patch -d php-5.2.8 -p1
cd php-5.2.8/
./configure --prefix=/usr/local/webserver/php --with-config-file-path=/usr/local/webserver/php/etc --with-mysql=/usr/local/webserver/mysql
--with-mysqli=/usr/local/webserver/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib
--with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem
--enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect
--enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap
--with-ldap-sasl
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-dist /usr/local/webserver/php/etc/php.ini
cd ../
娉ㄦ剰錛氳繖閲./configure鍛戒護鏄涓琛岀殑鑰屼笉鑳芥湁鎹㈣岀︼紝濡傛灉鏄痗opy鐨勬椂鍊欙紝娉ㄦ剰瑕佸幓澶勮ユ崲琛岀
4銆佺紪璇戝畨瑁匬HP5鎵╁睍妯″潡--鍙閫夊畨瑁
澶嶅埗浠g爜
浠g爜濡備笅:
tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
make clean
make distclean
cd ../
tar jxvf eaccelerator-0.9.5.3.tar.bz2
cd eaccelerator-0.9.5.3/
/usr/local/webserver/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
make clean
make distclean
cd ../
tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-pdo-mysql=/usr/local/webserver/mysql
make
make install
make clean
make distclean
cd ../
tar zxvf ImageMagick.tar.gz
cd ImageMagick-6.5.1-2/
./configure
make
make install
make clean
make distclean
cd ../
tar zxvf imagick-2.2.2.tgz
cd imagick-2.2.2/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
make clean
make distclean
cd ../
5銆佷慨鏀筽hp.ini鏂囦歡
STRONG鎵嬪伐淇鏀癸細/STRONG鏌ユ壘/usr/local/webserver/php/etc/php.ini涓鐨別xtension_dir = "./"
淇鏀逛負extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/"
騫跺湪姝よ屽悗澧炲姞浠ヤ笅鍑犺岋紝鐒跺悗淇濆瓨錛
extension = "memcache.so"
extension = "pdo_mysql.so"
extension = "imagick.so"
鍐嶆煡鎵緊utput_buffering = Off
淇鏀逛負output_buffering = On
6銆侀厤緗甧Accelerator鍔犻烶HP錛
mkdir -p /usr/local/webserver/eaccelerator_cache
vi /usr/local/webserver/php/etc/php.ini
鎸塻hift+g閿璺沖埌閰嶇疆鏂囦歡鐨勬渶鏈灝撅紝鍔犱笂浠ヤ笅閰嶇疆淇℃伅錛
澶嶅埗浠g爜
浠g爜濡備笅:
[eaccelerator]
zend_extension="/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="128"
eaccelerator.cache_dir="/usr/local/webserver/eaccelerator_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="300"
eaccelerator.shm_prune_period="120"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
淇鏀歸厤緗鏂囦歡錛
vi /etc/sysctl.conf
kernel.shmmax = 134217728
鐒跺悗鎵ц屼互涓嬪懡浠や嬌閰嶇疆鐢熸晥錛/sbin/sysctl -p
浠ヤ笅鐨勬ラゅ拰寮犲存ラや腑涓鏍烽厤緗錛屼笉鍐嶈禈璇