阿里云 Ubuntu PHP7 Nginx Mysql 开发环境搭建
来源:SegmentFault
时间:2023-01-26 10:11:35 184浏览 收藏
知识点掌握了,还需要不断练习才能熟练运用。下面golang学习网给大家带来一个数据库开发实战,手把手教大家学习《阿里云 Ubuntu PHP7 Nginx Mysql 开发环境搭建》,在实现功能的过程中也带大家重新温习相关知识点,温故而知新,回头看看说不定又有不一样的感悟!
记录下在阿里云搭建 PHP7 开发环境
安装 nginx
sudo apt-get update sudo apt-get install nginx 安装完成后会自动开启,通过命令查看 # ps -aux |grep nginx root 7921 0.0 0.0 14232 972 pts/0 S+ 21:25 0:00 grep --color=au to nginx root 27770 0.0 0.0 117084 1444 ? Ss 20:39 0:00 nginx: master p rocess /usr/sbin/nginx -g daemon on; master_process on; www-data 27771 0.0 0.0 117404 3084 ? S 20:39 0:00 nginx: worker p rocess www-data 27772 0.0 0.1 117692 5120 ? S 20:39 0:00 nginx: worker p rocess 浏览器打开 http://x.x.x.x.com/ 可以看到 nginx 的欢迎页面

安装 PHP7
sudo apt-get install python-software-properties software-properties-common sudo add-apt-repository ppa:ondrej/php sudo apt-get install php7.0-fpm php7.0-cli php7.0-mcrypt php7.0-mysql php7.0-mbstring php7.0-xml php7.0-curl 开启OPcache apt-get install php70-php-opcache.x86_64 sudo service php7.0-fpm restart
配置 nginx 解析 PHP
vi /etc/nginx/sites-available/default
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
#root 为项目代码所在目录
root /var/www/html;
index index.php index.html index.htm;
#填写购买的阿里云外网IP或者自己已经解析备案的域名
server_name http://x.x.x.x/;
#更改未被注释一行
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
#添加下面代码
location ~ \.php$ {
try_files $uri $uri/ =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
sudo vi /etc/php/7.0/fpm/php.ini
cgi.fix_pathinfo=0
sudo phpenmod mcrypt
sudo service php7.0-fpm restart
sudo service nginx restart
vi test.php
<?php phpinfo();

安装 MySQL
# 默认安装 MySQL 5.7 sudo apt-get install mysql-server mysql-client #设置好密码后登陆 mysql -u root -p
安装 redis
sudo apt-get install git
git clone -b php7 https://github.com/phpredis/phpredis.git
mv phpredis/ /etc/
cd /etc/phpredis
sudo apt install php7.0-dev
#生成编译文件
phpize
sudo ./configure
make && make install
find / -name redis.so
/etc/phpredis/.libs/redis.so
/etc/phpredis/modules/redis.so
/usr/lib/php/20151012/redis.so
vim /etc/php/7.0/apache2/php.ini
extension=/etc/phpredis/modules/redis.so
sudo service php7.0-fpm restart
ps -aux |grep redis
root 7981 0.0 0.0 14232 1024 pts/0 S+ 21:40 0:00 grep --color=auto redis
redis 30952 0.0 0.1 40136 6716 ? Ssl 20:59 0:02 /usr/bin/redis-server 127.0.0.1:6379
redis-cli
127.0.0.1:6379> info
# Server
redis_version:3.0.6
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:687a2a319020fa42
redis_mode:standalone
os:Linux 4.4.0-79-generic x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:5.3.1
process_id:30952
run_id:056f34665607470e822036784d93cbbe079080a7
tcp_port:6379
uptime_in_seconds:2792
uptime_in_days:0
vi test.php
<?php //连接本地Redis服务
$redis=new Redis();
$redis->connect('127.0.0.1','6379');
上传代码
scp -r . root@x.x.x.x:/var/www/html
参考
阿里云Ubuntu14+PHP7+Nginx+Mysql环境搭建
在阿里云上部署Laravel应用
阿里云ECS部署Laravel+PHP7+Nginx
Nginx配置https访问
理论要掌握,实操不能落!以上关于《阿里云 Ubuntu PHP7 Nginx Mysql 开发环境搭建》的详细介绍,大家都掌握了吧!如果想要继续提升自己的能力,那么就来关注golang学习网公众号吧!
声明:本文转载于:SegmentFault 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
-
499 收藏
-
286 收藏
-
244 收藏
-
235 收藏
-
157 收藏
最新阅读
更多>
-
117 收藏
-
411 收藏
-
420 收藏
-
264 收藏
-
266 收藏
-
392 收藏
-
333 收藏
-
234 收藏
-
448 收藏
-
416 收藏
-
225 收藏
-
145 收藏
课程推荐
更多>
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 立即学习 543次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 立即学习 516次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 立即学习 500次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 立即学习 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 立即学习 485次学习