您好,登錄后才能下訂單哦!
這篇文章主要介紹了CentOS7 下nginx與PHP如何安裝以及配置,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
下載Nginx
1.在服務(wù)器上新建文件夾 /home/soft/ ;
2.cd /home/soft/ => 執(zhí)行命令下載Nginx wget http://nginx.org/download/nginx-1.7.4.tar.gz ;
3.解壓下載后的壓縮包到/opt/software/ => tar -zvxf nginx-1.7.4.tar.gz -C /opt/software/ ;
4.cd /opt/software/nginx-1.7.4/ => ./configure --prefix=/usr/local/nginx/ ;
5.make && make install ;
6.啟動(dòng)nginx => /usr/local/nginx/sbin/nginx
7.打開瀏覽器訪問此機(jī)器的 IP,如果瀏覽器出現(xiàn) Welcome to nginx! 則表示 Nginx 已經(jīng)安裝并運(yùn)行成功。
8. 重啟:/usr/local/nginx/sbin/nginx –s reload
停止:/usr/local/nginx/sbin/nginx –s stop
測試配置文件是否正常:/usr/local/nginx/sbin/nginx –t
強(qiáng)制關(guān)閉:pkill nginx
下載php
1. cd /home/soft/ 下載php:wget https://www.php.net/distributions/php-7.2.25.tar.gz ;
2. 解壓php-7.2.25.tar.gz => tar -zvxf php-7.2.25.tar.gz -C /opt/software/ ;
3. cd /opt/software/php-7.2.25/;
4. 先安裝php所需的依賴:
yum update
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel MySQL pcre-devel
yum -y install curl-devel
yum -y install libxslt-devel
yum install openssl openssl-devel
5. ./configure --prefix=/usr/local/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-xmlrpc --with-xsl --with-zlib --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-xml --enable-zip
6. make && make install
7. php做配置信息:
cp /opt/software/php-7.2.25/php.ini-development /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp -R /opt/software/php-7.2.25/sapi/fpm/php-fpm /etc/init.d/php-fpm
* 需要注意的是php7中www.conf這個(gè)配置文件配置phpfpm的端口號(hào)等信息,如果你修改默認(rèn)的9000端口號(hào)需在這里改,再改nginx的配置
Ngin解析php:
1.更改nginx的配置文件 => vim /usr/local/nginx/etc/nginx/nginx.conf
location ~ \.php$ {
root /usr/share/nginx/html; #指定php的根目錄
fastcgi_pass 127.0.0.1:9000; #php-fpm的默認(rèn)端口是9000
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #路徑
include fastcgi_params;
}
2.php 配置開機(jī)自啟動(dòng):
vim /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=php
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/php/sbin/php-fpm
ExecStop=/bin/pkill -9 php-fpm
PrivateTmp=true
[Install]
WantedBy=multi-user.target
3. killall /etc/init.d/php-fpm
4. 啟動(dòng)php
systemctl restart php-fpm.service
systemctl enable php-fpm.service
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“CentOS7 下nginx與PHP如何安裝以及配置”這篇文章對大家有幫助,同時(shí)也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。