玩转服务器之环境篇:PHP和Python环境安排指南
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">前几篇<span style="color: black;">文案</span>中讲解了<span style="color: black;">怎样</span>搭建docker和Java Web环境的<span style="color: black;">办法</span>,本篇<span style="color: black;">文案</span>来教<span style="color: black;">大众</span>搭建一个好的PHP和Python环境,<span style="color: black;">能够</span><span style="color: black;">帮忙</span><span style="color: black;">研发</span>和运行PHP和Python应用程序,使其更加<span style="color: black;">有效</span>和稳定。</p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">1、</span> PHP环境介绍</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">好的<span style="color: black;">研发</span>环境无疑会大大<span style="color: black;">提高</span>编码效率,<span style="color: black;">近期</span>钻研了一下Python环境安装的问题,稍加总结分享一下。本文以轻量云主机(CenTOS 7.6系统)为例,介绍<span style="color: black;">怎样</span>搭建PHP环境。</p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;">1.1、前置准备</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">正式<span style="color: black;">起始</span><span style="color: black;">安排</span>前,您需完成如下的准备工作:</p>开通京东云账户,若您还未注册京东云账号,可在京东云官网进行注册;账户开通后,需要进行实名认证;购买一台或多台云主机<span style="color: black;">或</span>轻量云主机<span style="color: black;">制品</span>;登录轻量云主机,复制下面<span style="color: black;">过程</span>中的命令进行执行操作;<h1 style="color: black; text-align: left; margin-bottom: 10px;">1.2、搭建PHP环境</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">这次</span>安装的是PHP7,有些linux版本的yum默认是安装的5,需要做如下更改</p>rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">安装PHP</p>yum -y install php72w
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">安装PHP扩展</p>yum -y install php72w-common php72w-fpm php72w-opcache php72w-gd php72w-mysqlnd php72w-mbstring php72w-pecl-redis php72w-pecl-memcached php72w-devel<h1 style="color: black; text-align: left; margin-bottom: 10px;">1.3、安装Apache</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">安装Apache</p>yum install -y httpd
systemctl start httpd<h1 style="color: black; text-align: left; margin-bottom: 10px;">1.4、测<span style="color: black;">实验</span>证</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">新建info.php文件</p>cd /var/www/html
vi info.php
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在文件中输入 下面内容,并<span style="color: black;">保留</span>文件</p><?php phpinfo(); ?>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/54e38b2aa91349cfa8ce46ce5536291d~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728207512&x-signature=%2BdHypREEzUF2HxV%2FQW0Mdkcfeo4%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在浏览器中输入 http://ip/info.php查看效果</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p26-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/c0846ffc484b423bbb750bc49e95db6c~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728207512&x-signature=aANNL3mcXoEAkLwSap9saQNyF0w%3D" style="width: 50%; margin-bottom: 20px;"></div>
<h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">2、</span> Python环境介绍</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Python是一种面向对象的解释型语言,可应用于<span style="color: black;">各样</span><span style="color: black;">行业</span>,<span style="color: black;">包含</span>但不限于网站、游戏<span style="color: black;">研发</span>、<span style="color: black;">设备</span>人,人工智能,大数据等。 CentOS系统本身默认安装有python2.x,版本x<span style="color: black;">按照</span><span style="color: black;">区别</span>系统版本有所<span style="color: black;">区别</span>,可<span style="color: black;">经过</span> python --V 或 python --version 查看系统自带的python版本。</p>本文以轻量云主机(CenTOS 7.6系统)为例,介绍<span style="color: black;">怎样</span><span style="color: black;">安排</span>python3.6环境。
<h1 style="color: black; text-align: left; margin-bottom: 10px;">2.1、前置准备</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">正式<span style="color: black;">起始</span><span style="color: black;">安排</span>前,您需完成如下的准备工作:</p>开通京东云账户,若您还未注册京东云账号,可在京东云官网进行注册;账户开通后,需要进行实名认证;购买一台或多台云主机<span style="color: black;">或</span>轻量云主机<span style="color: black;">制品</span>;登录轻量云主机,复制下面<span style="color: black;">过程</span>中的命令进行执行操作;<h1 style="color: black; text-align: left; margin-bottom: 10px;">2.2、搭建Python3.6环境</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">查看<span style="color: black;">能够</span>安装的python3版本</p>yum -y list python3*
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/1215ed2a0df1493985ff21ddf85936b5~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728207512&x-signature=39xJW4m3f9Y8ElqPrAj7UzKUg60%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">安装python3.6</p>yum -y install python36
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/784a2937e73143659aaa1d9c9a6732ee~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728207512&x-signature=NBVJIObsLAw8q4dlgdarL90mdnw%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">验证phthon3.6 <span style="color: black;">是不是</span>安装成功</p>python3 -V
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/7cbf8f1d4b3b473887b0d13b5f4ffd7c~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728207512&x-signature=4ci6Gd3nq%2FxTW14QJvojB%2FDAOVA%3D" style="width: 50%; margin-bottom: 20px;"></div>
<h1 style="color: black; text-align: left; margin-bottom: 10px;">2.3、安装PIP3</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">安装pip3</p>yum install python3-pip<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/3b035afd0d2748c79369a2312b18dfba~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728207512&x-signature=b18ZfG3lY3JV%2BUAp0Isor75GVuU%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">更新pip3</p>pip3 install -U pip -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host http://pypi.tuna.tsinghua.edu.cn
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">修改pip3软件源</p>sudo pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple<h1 style="color: black; text-align: left; margin-bottom: 10px;">2.4、测<span style="color: black;">实验</span>证</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">测试pip3<span style="color: black;">运用</span></p>pip3 install lxml
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/967aab9393d74dc6b325c8a76067a007~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728207512&x-signature=ojRf4AyUZTh%2Bvkf7uUMM3%2FOPEes%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">创建一个hello.py文件</p>vi hello.py
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/03c52e10b0ac4ed18e00f8cc12109bb2~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728207512&x-signature=P%2Fn8oge%2B6JsXqifAp1a1GW51nlY%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在文件中输入 print("hello world") , 并<span style="color: black;">保留</span>文件</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/2cf30e9b1a4a45a1a6c1cd1d9de79b17~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728207512&x-signature=RQRUdiZMMzIuo56bheSQYTw9Txs%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">执行python脚本,输出hello world</p>python3 ./hello.py
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/94d059d4b577491b89c937a3fcbd2336~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728207512&x-signature=UGNwXJYbwIEtdchw5EkekP5WFQE%3D" style="width: 50%; margin-bottom: 20px;"></div>
对于这个问题,我有不同的看法... 感谢你的精彩评论,带给我新的思考角度。 论坛外链网http://www.fok120.com/ 一看到楼主的气势,我就觉得楼主同在社区里灌水。
页:
[1]