phalcon environment setup method under nginx server of centos7 system
- 2021-06-28 14:40:52
- OfStack
This paper describes how to set up phalcon environment under nginx server in centos7 system.Share it for your reference, as follows:
Previously, we used Apache server, but the response per second can only reach 2000, I heard nginx can easily break thousands,
So try nginx instead.
phalcon's official website has examples of nginx rewriting rules, but they are different from apache's and have been puzzled for a long time.
1. Add nginx Source
vi /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
2. Modify the configuration of nginx
vi /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost.dev;
index index.php index.html index.htm;
root /var/www/html;
location / {
root /var/www/html; #phalcon On the official website is public Directory, if you use this directory and apache Configuration is not 1 Okay
index index.php index.html index.htm;
# Return this file directly if it exists
* if (-f $request_filename) {
break;
}
# Redirect to if it doesn't exist public/index.php
if (!-e $request_filename) {
rewrite ^(.+)$ /public/index.php?_url=$1 last;
break;
}
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root /var/www/html/public;
}
location ~ /\.ht {
deny all;
}
}
3. Configuration of php-fpm
vi /etc/php-fpm.d/www.conf
Modify to Users and Groups
; RPM: apache Choosed to be able to access some dir as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx
4. User Group Modifications
chown -R nginx:nginx /var/lib/php/session/
chown -R nginx:nginx /var/www/html/
Restart nginx, php-fpm,
systemctl restart nginx
systemctl restart php-fpm
Optimize for Step 1 and Wait Later
I hope that the description in this article will be helpful for everyone to operate centos server.