nginx phalcon

tech2023-09-12  92

nginx phalcon

Back in January, I made it one of my New Year’s resolutions to walk 4000 kilometers for the sake of fitness. I’ve been documenting this virtual journey (which is taking place on a DIY treadmill desk), on a Ghost deployed blog.

一月份,为了健身,我走了4000公里 ,这是我新年的一项决议。 我一直在Ghost部署的博客上记录这个虚拟旅程(在DIY跑步机上进行)。

My Ghost subscription has since expired, and due to a severe lack of even the most basic CMS features, and their lack of PayPal support, I redeployed my own instance on DigitalOcean. You might be wondering why I’m writing about Ghost on a PHP oriented channel – this series will be a showdown of all the various PHP based CMS’ I can find, benchmarked against each other and against Ghost, as I look for the next best alternative.

此后,我的Ghost订阅已过期,并且由于严重缺乏最基本的CMS功能,并且缺少PayPal支持,因此我在DigitalOcean上重新部署了自己的实例。 您可能想知道为什么我要在面向PHP的频道上写有关Ghost的内容-本系列将展示我可以找到的所有基于PHP的所有CMS,彼此之间进行比较,并与Ghost进行比较 ,以寻求更好的结果替代。

设置 (The setup)

Since my DigitalOcean droplet already runs Nginx as a reverse proxy for the blog, I’ll also be deploying all the CMS’ on that same installation, each on its own subdomain. If I, for example, try out WordPress (I won’t be – WP is the only one I won’t be testing), it will be accessible live at wp.4kk.me. The default www subdomain will still serve the Ghost-based blog.

由于我的DigitalOcean Droplet已经将Nginx作为博客的反向代理运行,因此,我还将在同一安装上部署所有CMS,每个CMS都部署在其自己的子域中。 例如,如果我尝试WordPress(我不会-WP是我将要测试的唯一一个),它将可以在wp.​​4kk.me上进行实时访问 。 默认的www子域仍将提供基于Ghost的博客。

The server will also have TLS enabled, because it makes sense. I’ll be making sure I optimize all the installations to the best of my knowledge, and will be taking input from everyone on what else to do to to milk the apps for all they’ve got. Using app performance monitors like NewRelic and AppDynamics isn’t out of the question either, and all finished integrations will be perfomance audited. I intend to make this a community effort, and would like tips and input from as many sources as possible.

该服务器还将启用TLS,因为这很有意义 。 我将确保尽我所能优化所有安装,并将从每个人那里获得其他建议,以便为他们拥有的所有应用挤奶。 使用诸如NewRelic和AppDynamics之类的应用程序性能监视器也不是没有问题,并且所有完成的集成都将通过性能审核 。 我打算将此作为社区的工作,并希望从尽可能多的来源获得提示和意见。

I’ll be using Nginx on Ubuntu 12.04, with PHP 5.5. Note that as soon as PHP updates to 5.6, the environment will be updated – there’s no point in using outdated software. Likewise, as soon as Ubuntu 14.04 is released, and is properly vetted by people capable of properly vetting it, we’ll be moving to that LTS version instead of 12.04. The upgrade procedure will be thoroughly documented when time comes.

我将在带有PHP 5.5的Ubuntu 12.04上使用Nginx。 请注意,一旦PHP更新到5.6,环境将被更新–使用过时的软件毫无意义。 同样,Ubuntu 14.04发布后,只要有能力适当地对其进行过审核,我们就会转向该LTS版本,而不是12.04。 时间到了,升级过程将得到详细记录。

The actual benchmarking will happen on my local SSD-powered machine, in a separate instance of an identical Vagrant box for each installation. This is so the tests can be performed on an identical server under identical conditions every time. Apache Benchmark will be used as the request bombing app. The first benchmarks will happen when we have at least 5 CMS installed and running both live and locally.

实际的基准测试将在我的本地SSD驱动的计算机上进行,在每个安装的相同Vagrant盒的单独实例中。 这样一来,每次可以在相同的条件下,在一台相同的服务器上执行测试。 Apache Benchmark将用作请求轰炸应用程序。 当我们至少安装了5个CMS并在本地和实时运行时,就会出现第一个基准测试。

I’ll also be writing a custom data importer for all my 4kk posts for every CMS, so the full data is there and doesn’t need to be faked. These importers will be open sourced and you’ll be able to use them to export your Ghost data into any CMS we cover here.

我还将为每个CMS的所有4kk帖子编写一个自定义数据导入器,因此完整的数据就在那里,无需伪造。 这些导入器将是开源的,您将能够使用它们将Ghost数据导出到我们在此介绍的任何CMS中。

If you’d like to fully follow along on your own DigitalOcean droplet, feel free to open an account via my referral link. Then, pick the basic server with Ubuntu 12.04. I picked a tier 2 droplet, the one with 1GB of RAM, purely due to the fact that we’ll be running so many apps on one server. If you don’t intend to follow along with every CMS, feel free to pick the smallest one.

如果您想继续使用自己的DigitalOcean小滴,请随时通过我的引荐链接开设帐户。 然后,使用Ubuntu 12.04选择基本服务器。 我选择了第2层液滴,其中一个具有1GB的RAM,这完全是因为我们将在一台服务器上运行如此多的应用程序。 如果您不想跟着每个CMS一起去,请随意选择最小的CMS。

If you’d like to install Ghost as well, you should follow this tutorial. Apply it to the most up to date version of Ghost, everything else remains the same.

如果您还想安装Ghost,则应遵循本教程 。 将其应用于最新版本的Ghost,其他所有内容均保持不变。

在Nginx上安装PHP (Installing PHP on Nginx)

On Ubuntu, we use the ondrej PPA to install the latest PHP without having to build from source. Ondrej’s versions are always at most one minor version away from the latest (e.g. 5.5.9 vs 5.5.10) and much simpler to install than the fully manual procedure.

在Ubuntu上,我们使用ondrej PPA来安装最新PHP,而不必从源代码进行构建。 Ondrej的版本始终离最新版本(例如5.5.9与5.5.10)最多只有一个次要版本,并且比完全手动的过程更容易安装。

sudo add-apt-repository ppa:ondrej/php5 sudo apt-get update sudo apt-get upgrade sudo apt-get install php5-fpm php5-dev

Modify your php.ini file for timezone, upload file size settings, etc. Don’t forget to activate OpCache at the end of the INI file if you’re using PHP 5.5+ like I am. It makes a world of difference, performance-wise.

修改时区的php.ini文件,上传文件大小设置等。如果像我一样使用PHP 5.5+,请不要忘记在INI文件末尾激活OpCache。 在性能方面,它带来了与众不同的世界。

Let’s define a subdomain to test our PHP on now. We’ll make sure the URL dev.4kk.me outputs phpinfo();. Naturally, you should replace all further instances of 4kk with your own domain name, or the IP address of your droplet if that’s what you’re using for testing.

现在定义一个子域来测试我们PHP。 我们将确保URL dev.4kk.me输出phpinfo(); dev.4kk.me 。 自然,您应该用自己的域名或4kk的IP地址替换所有其他4kk实例,如果这是用于测试的内容。

在子域上设置虚拟主机 (Setting up a virtual host on a subdomain)

I have created a non-root user for my droplet. DigitalOcean uses root as the default, but I tend to disable both root login and all password logins when using SSH, and instead create a key-only user through which I can then perform sudo commands on my server. I’ll assume you’ll do the same – for security’s sake, you should. Make a new user on your server, and follow this tutorial but for that user – not for root. You don’t want to be remotely logging in as root, ever.

我为我的Droplet创建了一个非root用户。 DigitalOcean使用root作为默认值,但是在使用SSH时,我倾向于同时禁用root登录和所有密码登录,而是创建仅密钥用户,然后可以通过该用户在服务器上执行sudo命令。 我假设您会做同样的事情–为了安全起见,您应该这样做。 在您的服务器上创建一个新用户,然后按照本教程进行操作,但是针对该用户-不是root用户。 您永远都不想以root用户身份远程登录。

In my case, this user is called “swader”, so I’ll be putting all the PHP apps we’ll be building in this series into the /home/swader/apps/php parent folder. Create it if it doesn’t exist, and add another subfolder: dev. Apply your own username to the path in all examples below.

在我的情况下,此用户称为“ swader”,因此我将把本系列要构建的所有PHP应用程序放入/home/swader/apps/php父文件夹。 如果不存在,请创建它,然后添加另一个子文件夹: dev 。 在下面的所有示例中,将您自己的用户名应用于路径。

mkdir -p ~/apps/php/dev

mkdir -p ~/apps/php/dev

In this folder, create the standard phpinfo() file. Call it index.php:

在此文件夹中,创建标准phpinfo()文件。 称之为index.php :

<?php phpinfo();

Now we need to create a new virtualhost for Nginx that looks for PHP files in that folder. This is just a copy of the default Nginx Vhost template, we’ll be fine tuning Nginx later.

现在,我们需要为Nginx创建一个新的虚拟主机,以在该文件夹中查找PHP文件。 这只是默认Nginx Vhost模板的副本,我们稍后将对Nginx进行微调。

server { listen dev.4kk.me:80; ## listen for ipv4; this line is default and implied listen [::]:80 default_server ipv6only=on; ## listen for ipv6 root /home/swader/apps/php/dev; index index.php index.html index.htm; # Make site accessible from dev.4kk.me server_name dev.4kk.me; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ /index.html; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rules } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /home/swader/apps/php/dev; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # With php5-cgi alone: #fastcgi_pass 127.0.0.1:9000; # With php5-fpm: fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\.ht { deny all; } }

Accessing http://dev.4kk.me will now produce the phpinfo() screen:

现在访问http://dev.4kk.me将产生phpinfo()屏幕:

Our main domain now displays Ghost, and our subdomain displays the PHP content of the subdomain’s folder.

现在,我们的主域显示Ghost,子域显示子域文件夹PHP内容。

hal (Phalcon)

Seeing as one of the CMS we’ll be testing will be PhalconEye, we’ll need to install Phalcon as well. Best get it out of the way immediately. We’ll make a tools directory in the home folder of our user, and download and install from there:

视我们将要测试的CMS之一为PhalconEye ,我们还需要安装Phalcon。 最好立即将其清除。 我们将在用户的主文件夹中创建一个tools目录,然后从该目录下载并安装:

mkdir ~/tools cd ~/tools

Then, we follow the standard installation procedure.

然后,我们遵循标准的安装过程。

git clone --depth=1 git://github.com/phalcon/cphalcon.git cd cphalcon/build sudo ./install

After you add the line extension=phalcon.so to your php.ini file(s), don’t forget to restart php5-fpm, as it’s running as a separate process in the case of Nginx, not as an Apache submodule which restarts every time Apache does, too:

在您将extension=phalcon.so行添加到php.ini文件后,不要忘记重启php5-fpm,因为在Nginx的情况下,它作为单独的进程运行,而不是作为重新启动的Apache子模块运行每次Apache也会这样做:

sudo service php5-fpm restart sudo service nginx restart

Phalcon should now be installed and you should be able to find it on the previous phpinfo dump.

Phalcon现在应该已安装,您应该可以在以前的phpinfo转储中找到它。

结论 (Conclusion)

In this part, we configured our DigitalOcean droplet, linked to some Ghost installation tutorials, and installed PHP and Phalcon. We also set up a subdomain on which to test our initial PHP file, to make sure everything works as intended. If you’d like a more in-depth look at how HTTPS was set up, please comment below – I’d be happy to write a dedicated tutorial to getting HTTPS running on Nginx. In the next part, we’ll be looking at our first CMS candidate.

在这一部分中,我们配置了DigitalOcean Droplet,并链接到一些Ghost安装教程,并安装了PHP和Phalcon。 我们还设置了一个子域来测试我们的初始PHP文件,以确保一切正常。 如果您想更深入地了解HTTPS的设置方式,请在下面评论–我很乐意编写专门的教程来使HTTPS在Nginx上运行。 在下一部分中,我们将研究第一个CMS候选人。

翻译自: https://www.sitepoint.com/cms-showdown-nginx-ghost-php-phalcon/

nginx phalcon

相关资源:yona-cms, 基于模块化结构的Phalcon PHP框架.zip
最新回复(0)