您好,登錄后才能下訂單哦!
這篇文章主要講解了“怎么在centos下安裝nginx和php ”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“怎么在centos下安裝nginx和php ”吧!
sudo systemctl start php-fpm
sudo yum -y install nginx 啟動nginx,在本機瀏覽器訪問nginx頁面,檢查服務是否啟動成功 sudo systemctl start nginx 訪問url:http://ip:80
#!/bin/bash echo 'start install nginx...' wget http://nginx.org/download/nginx-1.10.2.tar.gz tar -xvf nginx-1.10.2.tar.gz cd nginx-1.10.2 yum -y install gcc pcre-devel openssl-devel ./configure make make install echo 'install nginx successful.' fi
sudo yum -y install php php-fpm
啟動php-fpm服務
sudo systemctl start php-fpm
下面是nginx.conf 的配置文件
核心代碼就是 location.php 這一段
# For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; server { listen 8008 default_server; #listen [::]:80 default_server; server_name _; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; #fastcgi服務端口,將http請求代理到此端口 fastcgi_index index.php; #fastcgi服務默認頁面 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #設置請求的腳本文件路徑 include fastcgi_params; } location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } # Settings for a TLS enabled server. # # server { # listen 443 ssl http2 default_server; # listen [::]:443 ssl http2 default_server; # server_name _; # root /usr/share/nginx/html; # # ssl_certificate "/etc/pki/nginx/server.crt"; # ssl_certificate_key "/etc/pki/nginx/private/server.key"; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 10m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # # # Load configuration files for the default server block. # include /etc/nginx/default.d/*.conf; # # location / { # } # # error_page 404 /404.html; # location = /40x.html { # } # # error_page 500 502 503 504 /50x.html; # location = /50x.html { # } # } }
nginx -t sudo systemctl reload nginx
下面幾種nginx 的重啟方法
在重啟之前 先加入配置
判斷Nginx配置是否正確命令如下:
nginx -t -c /etc/nginx/nginx.conf
nginx -s reload
------------------------------------------------------------------------------------------------------------------------------
2 編譯安裝
安裝一些編譯工具和依賴包等
sudo yum -y install gcc automake autoconf libtool make unzip gcc-c++ glibc gd-devel sudo yum -y install libmcrypt-devel mhash-devel libxslt-devel \ libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel \ zlib zlib-devel 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
下載官方軟件包
wget http://nginx.org/download/nginx-1.4.2.tar.gz
解壓
tar -xvf nginx-1.4.2.tar.gz
創建安裝目錄
sudo mkdir /usr/local/nginx
編譯安裝
cd nginx-1.4.2./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --user=nginx --group=nginx sudo make && sudo make install
起服務
cd /usr/local/nginx/sbin/ sudo ./nginx
出現 make[1]: Leaving directory `/home/xxx/nginx-1.4.2',不用管。
下載官方軟件包
wget http://cn2.php.net/distributions/php-5.6.39.tar.gz
解壓
tar -xvf php-5.6.39.tar.gz
創建安裝目錄
sudo mkdir /usr/local/php
編譯安裝
./configure --prefix=/usr/local/php \ --with-config-file-path=/usr/local/php/etc \ --enable-fpm --with-mcrypt \ --enable-mbstring --disable-pdo --with-curl --disable-debug --disable-rpath \ --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets \ --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex \ --with-mhash --enable-zip --with-pcre-regex --with-mysql --with-mysqli \ --with-gd --with-jpeg-dir sudo make all install
進行php-fpm的用戶設置
sudo groupadd www sudo useradd www -g www -s /sbin/nologin cd /usr/local/php sudo cp etc/php-fpm.conf.default etc/php-fpm.conf sudo vi etc/php-fpm.conf #修改以下兩個參數user = www group = www
起服務
sudo /usr/local/php/sbin/php-fpm
在http{}的server{}里添加
vim /usr/local/nginx/conf/nginx.conf index index.html index.htm index.php;location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; #fastcgi服務端口,將http請求代理到此端口 fastcgi_index index.php; #fastcgi服務默認頁面 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #設置請求的腳本文件路徑 include fastcgi_params; }
vim /usr/local/nginx/html/index.php<?phpphpinfo();?>
cd /usr/local/nginx/sbin/ sudo ./nginx
http://ip:80/index.php
可能會遇到以下問題
錯誤為:./configure: error: the HTTP rewrite module requires the PCRE library.
安裝pcre-devel解決問題
yum -y install pcre-devel
還有可能出現:
錯誤提示:./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library. You can either disable the module by using
--without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
--with-http_ssl_module --with-openssl=<path> options.
解決辦法:
yum -y install openssl openssl-devel
感謝各位的閱讀,以上就是“怎么在centos下安裝nginx和php ”的內容了,經過本文的學習后,相信大家對怎么在centos下安裝nginx和php 這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。