多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
这部分文档主要讲述了如何在本地VMware虚拟机中配置开发环境,包括部署Ubuntu + Apache + PHP + MySQL的本地服务器环境,项目本地测试成功后,便可以同步至云服务器。同时,还要下载和安装相应的IDE进行Java、Python和PHP的开发。 实际上我的项目均Ubuntu 18.04 LTS系统上实现的,但是在该文档中我还是会讲述Ubuntu 16.04的相关配置,因为我最初是在Ubuntu 16上进行操作的,是由于存在应用安装的问题,最终采用了Ubuntu 18系统。需要注意的是,两者的配置在有些细节上是有差异的。 ![Ubuntu桌面][1] ## 开始:下载和安装Ubuntu 16.04/18.04 LTS镜像 下载Ubuntu镜像,可以使用国内,诸如清华的源: https://mirrors.tuna.tsinghua.edu.cn/ubuntu-releases/ 在虚拟机中安装Ubuntu系统 ( 比如VMware ) ,当然在真机中安装也是可以的。 在虚拟机中安装完成后,启动Ubuntu系统,将软件源切换至中国,我选在了阿里云的站点。 ![软件源站点的切换][2] 在 **语言支持(Language Support)** 中添加中文支持。 在命令行窗口输入 `# ibus-setup` 进入ibus的设置界面。然后依次找到 Pinyin mode > add Chinese-Pinyin. 重启Ubuntu系统,然后为中文添加ibus-pinyin ![ibus-pinyin][3] 在Ubuntu 16中,如果你发现用鼠标选中某一段文字进行编辑时,再次点击这段选中的文字,文字会消失,你可以通过如下的配置来修正这个问题: # ibus-setup 关闭选项 `Embed preedit text in application window`,然后你就能解决这个问题。 如果你使用的是Ubuntu18,则上述的配置方法不管用了,你可以直接将`ibus-pinyin`切换成`intelligent-pinyin`即可。 ## 1 PHP + Apache + MySQL 环境配置 在命令行以管理员账户登录 $ sudo su 安装Apache服务器 # apt-get install apache2 安装完成后你可以在浏览器中打开网址 http://localhost 或者 http://127.0.0.1。如果显示如下的测试页面,说明你安装成功了。 ![apache-ubuntu][4] 在安装MySQL之前,请确认一下该平台是够支持相应版本的MySQL数据库 https://www.mysql.com/support/supportedplatforms/database.html ![MySQL支持的平台][5] ### 在Ubuntu 16中安装MySQL # apt-get install mysql-server mysql-client 在弹出的窗口中设置root账户的密码即可。 ### 在Ubuntu 18中安装MySQL https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-18-04 ``` # mysql_secure_installation mysql > SELECT user,authentication_string,plugin,host FROM mysql.user; mysql > ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; mysql > FLUSH PRIVILEGES; mysql> set global validate_password_policy=0; mysql> SHOW VARIABLES LIKE 'validate_password%'; ``` ### 将MySQL设置编码格式为utf8,在Ubuntu16/18中的设置是一样的 Vim mysql.cnf ``` # vim /etc/mysql/conf.d/mysql.cnf ###在 [mysql]标签下添加如下的代码### default-character-set=utf8 ``` Vim mysqld.cnf ``` # vim /etc/mysql/mysql.conf.d/mysqld.cnf ###在 [mysqld]标签下添加如下的代码### character-set-server=utf8 ``` 重启MySQL,查看编码配置是否成功: # systemctl restart mysql # mysql -uroot -p mysql > show variables like '%character%'; 如下图所示,所有的编码都是uft8,成功! ![mysql-coding][6] 安装php和php的拓展 ( 我的项目需要 php-mysql, php-curl) # apt-get install php libapache2-mod-php php-gd php-mysql php-curl 重启Apache服务 # systemctl restart apache2 ## 2 配置Java环境 ( oracle ) 添加ppa源 ``` # add-apt-repository ppa:webupd8team/java # apt-get update ``` 安装oracle-java-installer ``` # apt-get install oracle-java8-installer ``` 设置系统默认的jdk ``` # update-java-alternatives -s java-8-oracle ``` 测试java的安装是否成功 ``` # java -version # javac -version ``` ## 3 Python的切换配置 如果使用的是Ubuntu16,则我们可以安装python3,而python2是默认安装的。 # apt-get install python3 如果使用的是Ubuntu18,则系统中默认安装py3而没有py2,因此我们可以先安装py2,以备不时之需。 # apt-get install pyhton ![python-usr-bin][7] 使用Ubuntu的update-alternatives 来实现py2和py3的自由切换。 # update-alternatives --list python 如果显示 `update-alternatives: error: no alternatives for python` ,这说明python的替代版本还不能别`update-alternatives`命令识别。我们需要使用`update-alternatives`命令来配置py2和py3 ``` # update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1 # update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2 ``` *--install* 命令的参数详解 --install <link> <name> <path> <priority> 列出所有可替代python版本 ``` # update-alternatives --list python /usr/bin/python2.7 /usr/bin/python3.5 ``` 对 python的版本进行选择 # update-alternatives --config python 检查python的版本 # python --version 其他一些有用的命令:移除update-alternatives 的配置 # update-alternatives --remove-all python # ln -s /usr/bin/<python2.7|python3.5> /usr/bin/python ## 4 用于开发的工具 所有 **表1** 中的软件都可以在**Ubuntu Software**中安装,是不是相当方便,只需要搜索相应的软件名即可安装下载。 |名字 | 简介 | 版本 | |--------------|------------------| -------------| |Intellij IDEA Community | Java集成开发环境 | 2018.3.4 | |Pycharm CE | Python集成开发环境 | 2018.3.4| |Sublime Text | 代码、文本编辑器 | 3176| |Chromlum | 浏览器 | 71.0.3578.98 | |Workbench | MySQL可视化管理工具 | | |Android Studio | Android的集成开发环境 | | :-: 表1 .软件列表 ![mysql-workbench][8] ## 5 遇到的问题 因为python3的错误,而不能将Ubuntu16升级到Ubuntu18 ``` # do-release-upgrade Checking package manager Can not upgrade Your python3 install is corrupted. Please fix the '/usr/bin/python3' symlink. ``` 解决方法可以参看 https://askubuntu.com/questions/1104192/unable-to-upgrade-to-ubuntu-18-04-from-ubuntu-17-10 需要 `/usr/bin/python` 直接指向 `/usr/bin/python3.5` ,而不能采用update-alternatives配置 ## 6 一些常用指令的笔记 ``` //mysql mysqldump -u -p <database> > example.sql mysql -u -p <database> < example.sql //ssh and sftp ssh <ip> sftp <ip> get put cd,lcd ls,lls pwd,lpwd //apt-get apt-get install apt-get remove //other do-release-upgrade strace //chmod, chown chmod -R 777 <dictionary> //change file's permission chmod 777 <file> chown -R <user>:<user group> <folder> //change file's owner //systemctl systemctl restart apache2 systemctl restart mysql systemctl restart networking //hosts file //tar tar -xzvf example.tar.gz //x-unpack and z-decompress, v-show info, f-file name tar -czvf newName.tar.gz folderName //c-pack and z-compress tar -cvf newName.tar folderName //c-pack not z-compress //git git clone git rm -r --cached <folderName/Filename> git commit -m 'Add you own description' git add . #. can match all pattern of files git pull origin master git push -u origin master ``` [1]: https://blog-1252789527.cos.ap-shanghai.myqcloud.com/article/Configure%20developing%20environment%20in%20Ubuntu%2016.04%20LTS%20/ubuntu-desktop.jpg [2]:https://blog-1252789527.cos.ap-shanghai.myqcloud.com/article/Configure%20developing%20environment%20in%20Ubuntu%2016.04%20LTS%20/source-download-site.png [3]: https://blog-1252789527.cos.ap-shanghai.myqcloud.com/article/Configure%20developing%20environment%20in%20Ubuntu%2016.04%20LTS%20/ibus-pinyin.png [4]: https://blog-1252789527.cos.ap-shanghai.myqcloud.com/article/Configure%20developing%20environment%20in%20Ubuntu%2016.04%20LTS%20/ubuntu-apache.png [5]: https://blog-1252789527.cos.ap-shanghai.myqcloud.com/article/Configure%20developing%20environment%20in%20Ubuntu%2016.04%20LTS%20/supported%20platform.png [6]: https://blog-1252789527.cos.ap-shanghai.myqcloud.com/article/Configure%20developing%20environment%20in%20Ubuntu%2016.04%20LTS%20/mysql-coding.png [7]: https://blog-1252789527.cos.ap-shanghai.myqcloud.com/article/Configure%20developing%20environment%20in%20Ubuntu%2016.04%20LTS%20/python-usr-bin.png [8]: https://blog-1252789527.cos.ap-shanghai.myqcloud.com/article/Configure%20developing%20environment%20in%20Ubuntu%2016.04%20LTS%20/mysql-workbench.png