生產環境:操作系統使用Centos6.5、服務器選擇Nginx
0.准備安裝介質
Nginx選擇穩定版本:http://nginx.org/download/nginx-1.16.1.tar.gz
Nginx安裝:
1.下載好的nginx移動到/usr/local下並解壓,然后重命名為nginx
2.進入nginx目錄執行./configure命令
執行make命令
執行make install命令
3.啟動nginx
執行./sbin/nginx
Php選擇版本較老(5.6):https://www.php.net/distributions/php-5.6.40.tar.gz
PHP安裝:
1.先安裝依賴包
yum -y install libxml2
yum -y install libxml2-devel
yum -y install openssl
yum -y install openssl-devel
yum -y install curl
yum -y install curl-devel
yum -y install libjpeg
yum -y install libjpeg-devel
yum -y install libpng
yum -y install libpng-devel
yum -y install freetype
yum -y install freetype-devel
yum -y install pcre
yum -y install pcre-devel
yum -y install libxslt
yum -y install libxslt-devel
yum -y install bzip2
yum -y install bzip2-devel
2.進入php目錄
執行
./configure --prefix=/data/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip
3.執行make
4.執行make install
PS:Nginx比較好裝,Php相對難一些,有較多的前置模塊需要安裝,安裝到哪一步報錯就自行百度加裝模塊
1.Php配置;php主要配置兩個文件php.ini、php-fpm.conf
(1)php.ini文件:該文件在php安裝根目錄下,有對應的模板php.ini-development php.ini-production,這兩個文件對應了開發和生產環境;將其中一個復制到php根目錄下的etc目錄下面;PS:小白基本上不用動這個配置
(2)php-fpm.conf文件:該文件在php根目錄的etc目錄下,有對應模板php-fpm.conf.default;拷貝一下成php-fpm.conf;PS:小白基本也不動它
(3)啟動php-fpm:php安裝根目錄下執行./sbin/php-fpm PS:可以加上 -y php-fpm配置文件地址(用於配置多個實例,多實例需要復制出多個php-fpm.conf文件,通過修改監聽的端口、區分不同實例)默認端口是9000 PS:小白基本用默認配置耍耍
2.Nginx配置;nginx的配置在安裝目錄的conf下,nginx.conf文件
#其他我也沒動,小白一個 #注意的是root 路徑設置好,以后PHP項目就放到這里了 #location 照着復制過去就行 = = #9090端口是我誰便取的 #127.0.0.1:9000這里有些講究,端口和php-fpm.conf中的監聽端口保持#一致,若沒改conf配置,默認還是9000 #location正則和fastcgi_split_path_info 需要注意配置對 server{ listen 9090; root /data/www; location / { index index.php index.html index.htm; } location ~ .+\.php($|/) { fastcgi_pass 127.0.0.1:9000; fastcgi_split_path_info ^((?U).+.php)(/?.+)$; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
PS:可能會出現nginx和php-fpm用戶不匹配問題,需要統一用戶(Nginx在配置文件首行指定用戶、php-fpm.conf中搜索user、group指定用戶)