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

本文涉及的产品
RDS MySQL DuckDB 分析主实例,集群系列 4核8GB
简介:

如果安装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,如需转载请自行联系原作者




相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。 &nbsp; 相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/mysql&nbsp;
相关文章
|
3月前
|
安全 关系型数据库 MySQL
CentOS 7 yum 安装 MySQL教程
在CentOS 7上安装MySQL 8,其实流程很清晰。首先通过官方Yum仓库来安装服务,然后启动并设为开机自启。最重要的环节是首次安全设置:需要先从日志里找到临时密码来登录,再修改成你自己的密码,并为远程连接创建用户和授权。最后,也别忘了在服务器防火墙上放行3306端口,这样远程才能连上。
699 16
|
4月前
|
存储 关系型数据库 MySQL
在CentOS 8.x上安装Percona Xtrabackup工具备份MySQL数据步骤。
以上就是在CentOS8.x上通过Perconaxtabbackup工具对Mysql进行高效率、高可靠性、无锁定影响地实现在线快速全量及增加式数据库资料保存与恢复流程。通过以上流程可以有效地将Mysql相关资料按需求完成定期或不定期地保存与灾难恢复需求。
413 10
|
8月前
|
关系型数据库 MySQL Linux
CentOS 7系统下详细安装MySQL 5.7的步骤:包括密码配置、字符集配置、远程连接配置
以上就是在CentOS 7系统下安装MySQL 5.7的详细步骤。希望这个指南能帮助你顺利完成安装。
2129 26
|
Linux 网络安全 Apache
CentOS 7.2配置Apache服务httpd(上)
CentOS 7.2配置Apache服务httpd(上)
822 1
|
8月前
|
关系型数据库 MySQL Linux
查看Linux、Apache、MySQL、PHP版本的技巧
以上就是查看Linux、Apache、MySQL、PHP版本信息的方法。希望这些信息能帮助你更好地理解和使用你的LAMP技术栈。
425 17
|
安全 关系型数据库 MySQL
Linux(CentOS6)安装MySQL5.6
Linux(CentOS 6)系统上安装MySQL 5.6版本的详细步骤,包括准备数据存放目录、创建用户、下载安装包、初始化数据库、配置服务脚本、设置环境变量等操作。
921 1
|
11月前
|
安全 关系型数据库 MySQL
CentOS7仅安装部署MySQL80客户端
通过上述步骤,你可以在CentOS 7上成功安装并配置MySQL 8.0客户端。这个过程确保你能够使用MySQL客户端工具连接和管理远程的MySQL数据库,而不需要在本地安装MySQL服务器。定期更新MySQL客户端可以确保你使用的是最新的功能和安全修复。
1066 16
|
SQL DataWorks 关系型数据库
阿里云 DataWorks 正式支持 SelectDB & Apache Doris 数据源,实现 MySQL 整库实时同步
阿里云数据库 SelectDB 版是阿里云与飞轮科技联合基于 Apache Doris 内核打造的现代化数据仓库,支持大规模实时数据上的极速查询分析。通过实时、统一、弹性、开放的核心能力,能够为企业提供高性价比、简单易用、安全稳定、低成本的实时大数据分析支持。SelectDB 具备世界领先的实时分析能力,能够实现秒级的数据实时导入与同步,在宽表、复杂多表关联、高并发点查等不同场景下,提供超越一众国际知名的同类产品的优秀性能,多次登顶 ClickBench 全球数据库分析性能排行榜。
630 6
|
关系型数据库 MySQL Linux
在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,并与使用 RPM 包安装进行了对比
本文介绍了在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,并与使用 RPM 包安装进行了对比。通过具体案例,读者可以了解如何准备环境、下载源码、编译安装、配置服务及登录 MySQL。编译源码安装虽然复杂,但提供了更高的定制性和灵活性,适用于需要高度定制的场景。
681 3
|
关系型数据库 MySQL Linux
在 CentOS 7 中通过编译源码安装 MySQL 数据库的详细步骤,并与使用 RPM 包安装进行了对比。
本文介绍了在 CentOS 7 中通过编译源码安装 MySQL 数据库的详细步骤,并与使用 RPM 包安装进行了对比。内容涵盖准备工作、下载源码、编译安装、配置服务、登录设置及实践心得,帮助读者根据需求选择最适合的安装方法。
541 2