- 导入Remi源
## Remi Dependency on CentOS 7 and Red Hat (RHEL) 7 ##
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
## CentOS 7 and Red Hat (RHEL) 7 ##
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
## Remi Dependency on CentOS 6 and Red Hat (RHEL) 6 ##
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
## CentOS 6 and Red Hat (RHEL) 6 ##
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
- 导入Nginx源
vim /etc/yum.repos.d/nginx.repo
#### centos
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
###########
#### RHEL
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/rhel/$releasever/$basearch/
gpgcheck=0
enabled=1
###########
- 安装nginx、php7和php-fpm
yum --enablerepo=remi,remi-php72 install nginx php-fpm php-common
- 安装php扩展
yum --enablerepo=remi,remi-php72 install php-opcache php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pecl-redis php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml
- 设置nginx和php-fpm自启动
## CentOS/RHEL 7 ##
systemctl start nginx.service
systemctl enable nginx.service
systemctl start php-fpm.service
systemctl enable php-fpm.service
## CentOS/RHEL 6 ##
service nginx start ## use restart after update
chkconfig nginx on
service php-fpm start
chkconfig php-fpm on
- 最后根据自己服务器的实际情况设置nginx的虚拟主机,网上很多这样的资料,主要就是以下的设置项目
server {
server_name testsite.local;
access_log /srv/www/testsite.local/logs/access.log;
error_log /srv/www/testsite.local/logs/error.log;
root /srv/www/testsite.local/public_html;
location / {
index index.html index.htm index.php;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
参考:Install Nginx/PHP-FPM on Fedora 29/28, CentOS/RHEL 7.5/6.10
本文介绍如何在CentOS/RHEL上安装并配置Nginx和PHP-FPM,包括导入Remi源、安装Nginx、PHP7及扩展,并设置自启动。最后给出了一个Nginx虚拟主机配置示例。
4665

被折叠的 条评论
为什么被折叠?



