CentOS 7 快速部署 LAMP环境 Apache Nginx MySQL PHP

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS MySQL,高可用系列 2核4GB
简介:

如果安装NGINX 那么修改如下 

如果没有nginx.repo就新建一个 

1
2
3
cd  /etc/yum .repos
touch  nginx.repo
vi  /etc/yum .repos.d /nginx .repo

修改为:

1
2
3
4
5
  [nginx]
name=nginx repo
baseurl=http: //nginx .org /packages/centos/ $releasever/$basearch/
gpgcheck=0
enabled=1

接下来安装apache nginx php mysql

1
2
3
4
yum  install  nginx
#yum install httpd httpd-devel
yum  install  mariadb*
yum  install  php php-devel php-gd php-xml php-mbstring php-session php-pecl-memcache php-fpm php-pdo php-pear php-mysql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
[root@localhost~] # mysql_secure_installation
/usr/bin/mysql_secure_installation : line 379: find_mysql_client:  command  not found
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 ] <– 回车
New password: <– 输入ROOT密码
Re-enter new password: <– 再输入一次ROOT密码
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 ] <– 回车
… 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 ] <– 回车
… 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 ] <– 回车
– 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 ] <– 回车
… 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!
[root@localhost ~] #

开启服务并永久通过防火墙 CentOS的防火墙改变了 是用firewall

1
2
3
4
5
6
7
8
9
10
systemctl stop httpd.service
systemctl disable httpd.service
systemctl  enable  nginx.service
systemctl start nginx.service
systemctl  enable  php-fpm.service
systemctl start php-fpm.service
 
firewall-cmd –permanent –zone=public –add-service=http
firewall-cmd –permanent –zone=public –add-service=https
firewall-cmd –reload

APC是一个自由和开放的PHP操作码来缓存和优化PHP的中间代码。它类似于其他PHP操作码cachers,如eAccelerator和XCache。强烈建议有这些安装,以加快您的PHP页面。

从PHP PECL库中安装的APC。 PECL要求CentOS开发工具beinstalled编译APC包。

确认安装了开发包  如果没有安装

1
yum groupinstall ‘Development Tools’

命令 pecl install apc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@localhost ~] # pecl install apc
downloading APC-3.1.13.tgz …
Starting to download APC-3.1.13.tgz (171,591 bytes)
…………….. done : 171,591 bytes
55  source  files, building
running: phpize
Configuring  for :
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
Enable internal debugging  in  APC [no] : <– 回车
Enable per request  file  info about files used from the APC cache [no] : <– 回车
Enable spin locks (EXPERIMENTAL) [no] : <– 回车
Enable memory protection (EXPERIMENTAL) [no] : <– 回车
Enable pthread mutexes (default) [no] : <–回车
Enable pthread  read /write  locks (EXPERIMENTAL) [ yes ] : <– 回车
building  in  /var/tmp/pear-build-rootVrjsuq/APC-3 .1.13

然后打开 /etc/php.ini 并设置 cgi.fix_pathinfo=0:

1
vi  /etc/php .ini


然后再在PHP.INI添加如下:

1
2
[APC]
extension=apc.so

然后编辑/etc/nginx/conf.d/default.conf

把厦门的注释去掉 并改为如下:

1
2
3
4
5
6
7
8
    location ~ .php$ {
         root            /usr/share/nginx/html ;
         try_files $uri =404;
         fastcgi_pass   127.0.0.1:9000;
         fastcgi_index  index.php;
         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
         include        fastcgi_params;
     }

默认情况下监听端口 9000 。 另外,也可以使PHP-FPM使用Unix套接字,这避免了TCP的开销。要做到这一点,打开 /etc/php-fpm.d/www.conf

1
vi  /etc/php-fpm .d /www .conf

… 修改后如下:

1
2
3
4
[...]
;listen = 127.0.0.1:9000
listen =  /var/run/php-fpm/php5-fpm .sock
[...]

然后重新加载 PHP-FPM:

1
systemctl restart php-fpm.service

接下来通过你的nginx的配置和所有的虚拟主机和改线 fastcgi_pass 127.0.0.1:9000; to fastcgi_pass unix:/tmp/php5-fpm.sock;,像这样:

1
2
3
4
5
6
7
8
9
vi  /etc/nginx/conf .d /default .conf
     location ~ .php$ {
         root            /usr/share/nginx/html ;
         try_files $uri =404;
         fastcgi_pass   unix: /var/run/php-fpm/php5-fpm .sock;
         fastcgi_index  index.php;
         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
         include        fastcgi_params;
     }

最后重新加载 nginx:

1
systemctl restart nginx.service




      本文转自flyingzf  51CTO博客,原文链接:http://blog.51cto.com/flyingzf/1638244,如需转载请自行联系原作者




相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
5月前
|
Linux 网络安全 Apache
CentOS 7.2配置Apache服务httpd(上)
CentOS 7.2配置Apache服务httpd(上)
431 1
|
4月前
|
Oracle 关系型数据库 MySQL
Centos7下图形化部署单点KFS同步工具并将Oracle增量同步到KES
Centos7下图形化部署单点KFS同步工具并将Oracle增量同步到KES
Centos7下图形化部署单点KFS同步工具并将Oracle增量同步到KES
|
5月前
|
前端开发 JavaScript 应用服务中间件
使用nginx部署网站
使用nginx部署网站
|
5月前
|
JavaScript 应用服务中间件 nginx
nginx部署vue项目
本文介绍了将Vue项目部署到Nginx的步骤,包括构建Vue项目、上传dist文件夹到服务器、安装Nginx、配置Nginx代理静态文件以及重启Nginx,确保了Vue应用可以通过域名或IP地址访问。
285 1
|
5月前
|
Linux PHP Apache
CentOS 7.2配置Apache服务httpd(下)
CentOS 7.2配置Apache服务httpd(下)
77 1
|
5月前
|
前端开发 JavaScript 应用服务中间件
linux安装nginx和前端部署vue项目(实际测试react项目也可以)
本文是一篇详细的教程,介绍了如何在Linux系统上安装和配置nginx,以及如何将打包好的前端项目(如Vue或React)上传和部署到服务器上,包括了常见的错误处理方法。
1677 0
linux安装nginx和前端部署vue项目(实际测试react项目也可以)
|
5月前
|
监控 应用服务中间件 网络安全
部署Django应用:使用Gunicorn和Nginx构建高效的生产环境
部署Django应用:使用Gunicorn和Nginx构建高效的生产环境
321 0
|
3月前
|
存储 人工智能 大数据
The Past, Present and Future of Apache Flink
本文整理自阿里云开源大数据负责人王峰(莫问)在 Flink Forward Asia 2024 上海站主论坛开场的分享,今年正值 Flink 开源项目诞生的第 10 周年,借此时机,王峰回顾了 Flink 在过去 10 年的发展历程以及 Flink社区当前最新的技术成果,最后展望下一个十年 Flink 路向何方。
445 33
The Past, Present and Future of Apache Flink
|
5月前
|
SQL Java API
Apache Flink 2.0-preview released
Apache Flink 社区正积极筹备 Flink 2.0 的发布,这是自 Flink 1.0 发布以来的首个重大更新。Flink 2.0 将引入多项激动人心的功能和改进,包括存算分离状态管理、物化表、批作业自适应执行等,同时也包含了一些不兼容的变更。目前提供的预览版旨在让用户提前尝试新功能并收集反馈,但不建议在生产环境中使用。
1114 13
Apache Flink 2.0-preview released
|
5月前
|
存储 缓存 算法
分布式锁服务深度解析:以Apache Flink的Checkpointing机制为例
【10月更文挑战第7天】在分布式系统中,多个进程或节点可能需要同时访问和操作共享资源。为了确保数据的一致性和系统的稳定性,我们需要一种机制来协调这些进程或节点的访问,避免并发冲突和竞态条件。分布式锁服务正是为此而生的一种解决方案。它通过在网络环境中实现锁机制,确保同一时间只有一个进程或节点能够访问和操作共享资源。
196 3

热门文章

最新文章