CentOS7安装配置LEMP(Nginx/PHP-FPM 5.6/MySQL 5.5)网站环境过程
![]() | ![]() | ![]() | ![]() |
| 【性价之王】 | 【线路之王】 | 【价格之王】 | 【配置之王】 |
| 【免费之王】 | 【香港首推】 | 【梯子之王】 | 【独服之王】 |

一般大型的网站建站环境都会采用Nginx系统环境架构,相对而言比Apache承受承载的线程和压力更大,不过对于一般的博客、网站来说,Apache环境也足够使用。在之前的相关文章中,无论是LNMP一键安装包、还是LEMP一键包、以及AMH等WEB面板,都是采用NGINX搭建的网站环境。
在这篇文章中,蜗牛整理一篇基于最新的CentOS7系统,搭建和应用Nginx/PHP-FPM 5.6/MySQL 5.5适用的网站环境,如果你也喜欢折腾,可以尝试下面的内容,文章是从海外翻译过来的,且进行过测试是完整的。
第一、安装EPEL和REMI库文件
rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-2.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
第二、安装Nginx
yum install nginx -y
启动和设置开机启动
systemctl start nginx
systemctl enable nginx
设置防火墙开启80端口
firewall-cmd –zone=public –add-port=80/tcp –permanent$ sudo firewall-cmd –reload
这里我们已经安装完毕NGINX,我们可以打开IP地址浏览器中,可以看到成功的NGINX安装界面提示。
第三、安装MariaDB 5.5
yum –enablerepo=remi,remi-php56 install mariadb-server mariadb -y
启动和设置开机启动
systemctl start mariadb
systemctl enable mariadb
设置数据库的安全
/usr/bin/mysql_secure_installation
执行上面脚本,根据提示我们需要设置一遍数据库的安全,删除匿名用户等。
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we\\’ll need the current
password for the root user. If you\\’ve just installed MariaDB, and
you haven\\’t set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
… Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
… Success!
Normally, root should only be allowed to connect from \\’localhost\\’. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
… Success!
By default, MariaDB comes with a database named \\’test\\’ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
– Dropping test database…
… Success!
– Removing privileges on test database…
… Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
… Success!
Cleaning up…
All done! If you\\’ve completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
第四、安装PHP-fpm 5.6
yum –enablerepo=remi,remi-php56 install php-fpm php-common php-mysql php-opcache php-pear php-gd php-devel php-mbstring php-mcrypt php-cli php-pdo php-xml -y
启动和开机启动
service php-fpm start
chkconfig php-fpm on
第五、配置Nginx
到这里我们已经安装完毕nginx, mariadb, 以及php-fpm,我们需要对Nginx进行配置
A – 配置/etc/nginx/nginx.conf文件
user nginx;
worker_processes 1;
worker_processes表示当前VPS/服务器的CPU核心数,我们可以通过grep ^processor /proc/cpuinfo | wc -l检测和修改。
B – 检查启动sendfile, tcp_nopush, gzip,以及添加INDEX.PHP文件
sendfile on;
tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
index index.php index.html index.htm;
第六、添加站点和设置文件
vi /etc/nginx/conf.d/laozuo_org.conf
添加站点的时候,我们最好以域名来定,这样好检查和记忆。
server {
listen your_public_ip_address:80;
server_name www.laozuo.org;
root /var/www/www.laozuo.org;
index index.php index.html index.htm;
charset utf-8;
location / {
}
location = /robots.txt { allow all; access_log off; log_not_found off; }
location = /favicon.ico { allow all; access_log off; log_not_found off; }
error_page 401 /401.html;
error_page 403 /403.html;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location ~ \\\\.php$ {
root /var/www/www.laozuo.org;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_buffer_size 4K;
fastcgi_buffers 128 4k;
fastcgi_connect_timeout 50;
fastcgi_send_timeout 40;
fastcgi_read_timeout 40;
try_files $uri =404;
fastcgi_split_path_info ^(.+\\\\.php)(/.+)$;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache\\’s document root
# concurs with nginx\\’s one
#
# location ~ /\\\\.ht {
# deny all;
# }
}
输入对应的配置文件。
如果没有/var/www/www.laozuo.org文件夹,我们需要给予设置添加和配置权限。
mkdir /var/www/www.laozuo.org
chmod 777 /var/www/www.laozuo.org
最后,我们启动Nginx
systemctl restart nginx
如果无法启动,可以用\\”systemctl status nginx.service\\”检查到底是哪里的问题然后相应修改。
总结,这样我们可以在已经创建的文件夹中上传程序。如果需要有MYSQL等数据库的,我们单独再安装,我们也可以参考\\”Debian安装LEMP(Linux/Nginx/MySQL/PHP)搭建站点建站环境\\”文章安装。
[centos7]历史优惠活动内容
猜你可能想看的VPS
- 眉字右边中间有一团云样的气体是什么成语?全球[VPS测评]
- 魔方云(CUBECLOUD)香港 VPS 大带宽主机上新设备推出全场 K香港VPS[主机]
- 八月优惠 RAKsmart→美国 CN 直连服务器降至 399 元 月 美国VPS[主机]
- smarthost→大硬盘 VPS 每 T 硬盘$4 月 洛杉矶 拉斯维全球[VPS测评]
- js 数字比较大小的注意事项→10 以上的数字必须转换类型全球[VPS测评]
- 桔子 VPS 五一大促,美国 cn2gia 带宽升级+赠送流量+五折,看美国VPS[主机]
- DMIT→洛杉矶 CN2 GIA 线路 1GB 10GB 1TB 年付 全球[VPS测评]
- HengHost 恒创科技→国庆放价 五折促销 香港 CN2 服务器 香香港VPS[主机]
- 膛肚两个字中间有一把刀是什么成语?全球[VPS测评]
- 299 元 年 1G 内存 15G SSD 2Mbps 不限量 XEN 香港VPS[主机]
- 便宜 VPS $1.64 每月 512M 内存 10G SSD 2T 月全球[VPS测评]
- 流量吃紧 费用上涨网络大波动情况下 那些还值得“试试”的美国“cn2 g美国VPS[主机]
- 腾讯云 2020 年 1 月促销:国内香港云服务器 2 核 4G6M14香港VPS[主机]
- 大前端 WordPress 主题 DUX 6.4 优化版 无限制 无后门全球[VPS测评]
- WordPress隐藏后台登录地址的最简单方法全球[VPS测评]
- 磐逸云怎么样?1核1G香港安畅CN2 VPS带宽5M年付128元香港VPS[主机]
- CombCloud,香港沙田cn2vps终身七折起,高质量网络稳定低延迟香港VPS[主机]
- 阁天互联怎么样?香港cn2云服务器 圣何塞cn2vps仅20/月香港VPS[主机]
- 恒创科技怎么样?香港美国云服务器/独服/高防全场2.5折起美国VPS[主机]
- HTML5绿色有机食品电商网站模板 - Organtio全球[VPS测评]
- 如何根据业务需求选择合适的云服务器配置?全球[VPS测评]
- 74块钱一年的云服务器可以用来做什么?全球[VPS测评]
- 恒创主机优惠码85折_服务器优惠券8折_恒创科技优惠_代金券全球[VPS测评]
- 麻花云:香港CN2VPS月付19元起,安徽移动8核/16G/20M独服2香港VPS[主机]
- 向日葵-漏洞科普:海外云服务器三种漏洞修复方法快收藏起来!全球[VPS测评]
- 六一云:香港CN2/洛杉矶高防/CDN,“返利+折扣”双优惠,折上折送实香港VPS[主机]
- 空空云怎么样?香港CN2-GIA VPS,带宽2M,月付15元香港VPS[主机]
- TmhHost:1核/1G/40G SSD/3Mbps/香港三网CN2 香港VPS[主机]
- 极光KVM:1核/1G/40G/100Mbps/美国GIA,年付199元美国VPS[主机]
- 向日葵-漏洞科普:海外云服务器三种漏洞修复方法快收藏起来!全球[VPS测评]
转载请注明原文地址:http://140.238.13.167:12355/read-143489.html











