安裝好Ubuntu16.04后萎坷,是一臺空白的Ubuntu稀余。
目的是搭建LAMP環(huán)境国葬,順便搭一個python-Django環(huán)境及舍。
基本設置
1.配置網(wǎng)絡環(huán)境
管理員給分配了一個靜態(tài)IP未辆,所以還需要進一步配置網(wǎng)絡環(huán)境
- 配置DNS:右上角網(wǎng)絡連接->編輯鏈接->有線連接1->IPv4設置->DNS服務器:202.112.80.106->保存
- 登陸網(wǎng)關:對于校園網(wǎng)用戶來說,登陸網(wǎng)關才能訪問外網(wǎng)
- 測試:
ping www.baidu.com
2.設置root密碼
sudo passwd
- 切換到root用戶:
su
或su -
或su root
- 切換到普通用戶:
su 用戶名
或logout
3.更新源
sudo apt-get update
源保存的文件為:
/etc/apt/sources.list
安裝常用軟件
1.SSH
sudo apt-get install openssh-server
查看狀態(tài):
service ssh status/start/stop/restart
- 或:
/etc/init.d/ssh status/start/stop/retsrt
實際上锯玛,service命令就是執(zhí)行/etc/init.d腳本咐柜,二者功能是一樣的
2.Vim
sudo apt-get install vim
3.Tree
sudo apt-get install tree
4.Git
sudo apt-get install git
正式搭建LAMP
1.安裝Apache
sudo apt-get install apache2
- 測試: 瀏覽器訪問
http://Ubuntu公網(wǎng)IP地址
,出現(xiàn)It Works!網(wǎng)頁攘残。- 查看狀態(tài):
service apache2 status/start/stop/restart
- 默認Web目錄:
/var/www
- 安裝目錄:
/etc/apache2/
- 全局配置:
/etc/apache2/apache2.conf
- 監(jiān)聽端口:
/etc/apache2/ports.conf
- 虛擬主機:
/etc/apache2/sites-enabled/000-default.conf
2.安裝MySQL
sudo apt-get install mysql-server mysql-client
- 測試:
mysql -u root -p
- 查看狀態(tài):
service mysql status/start/stop/retart
- 查看監(jiān)聽端口的情況:
netstat -tunpl
或netstat -tap
3.安裝PHP
sudo apt-get install php7.0
- 測試:
php7.0 -v
4.安裝其他模塊
sudo apt-get install libapache2-mod-php7.0
sudo apt-get install php7.0-mysql
- 重啟服務
service apache2 restart
service mysql restart
- 測試Apache能否解析PHP
vim /var/www/html/phpinfo.php
- 文件中寫:
<?php echo phpinfo();?>
- 瀏覽器訪問:
http://Ubuntu公網(wǎng)IP地址/phpinfo.php
拙友,出現(xiàn)PHP Version網(wǎng)頁
5.修改權限
sudo chmod 777 /var/www
6.安裝phpMyAdmin
sudo apt-get install phpmyadmin
- 安裝:選擇apache2,點擊確定歼郭。下一步選擇是要配置數(shù)據(jù)庫遗契,并輸入密碼。
- 創(chuàng)建phpMyAdmin快捷方式:
sudo ln -s /usr/share/phpmyadmin /var/www/html
- 啟用Apache
mod_rewrite
模塊:sudo a2enmod rewrite
- 重啟服務:
service php7.0-fpm restart
service apache2 restart
- 測試:瀏覽器訪問:
http://Ubuntu公網(wǎng)IP地址/phpmyadmin
7.配置Apache
vim /etc/apache2/apache2.conf
- 添加:
AddType application/x-httpd-php .php .htm .html
AddDefaultCharset UTF-8
- 重啟Apache服務
安裝python包
1.pip
sudo apt-get install python-pip
2.Django
pip install django
- 測試:
import django
3.MySQL-python
pip install MySQL-python
- 測試:
import MySQLdb
常見問題
1.Secure SSH Client連接出錯
- 錯誤:
algorithm negotiation failed
- 解決:
- 修改sshd的配置文件:
vim /etc/ssh/sshd_config
- 在配置文件中添加:
Ciphers aes128-cbc,aes192-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr,3des-cbc,arcfour128,arcfour256,arcfour,blowfish-cbc,cast128-cbc
MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-sha1-96,hmac-md5-96
KexAlgorithms diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group1-sha1,curve25519-sha256@libssh.org
- 重啟sshd服務:
service ssh restart
2.Xshell或Xftp中文亂碼
- Xshell:文件->屬性->終端->編碼->UTF-8>
- Xftp:文件->屬性->選項->選中使用UTF-8編碼
3.安裝MySQL出錯
- 錯誤:
- 下列軟件包有未滿足的依賴關系:
mysql-client : 依賴: mysql-client-5.5 但是它將不會被安裝
mysql-server : 依賴: mysql-server-5.5 但是它將不會被安裝
E: 無法修正錯誤病曾,因為您要求某些軟件包保持現(xiàn)狀牍蜂,就是它們破壞了軟件包間的依賴關系漾根。
- 解決:兩種解決方法
- 使用Ubuntu自帶的下載源,不要使用其他源(如網(wǎng)易)
- 手動安裝
- 下載MySQL:http://dev.mysql.com/downloads/mysql/
- 使用FTP工具上傳到Ubuntu
- 解壓:
tar -xvf mysql-server_5.7.13-1ubuntu16.04_i386.deb-bundle.tar
- 安裝:
sudo dpkg -i libmysqlclient20_5.7.15-1ubuntu16.04_amd64.deb libmysqlclient-dev_5.7.15-1ubuntu16.04_amd64.deb libmysqld-dev_5.7.15-1ubuntu16.04_amd64.deb mysql-common_5.7.15-1ubuntu16.04_amd64.deb mysql-community-source_5.7.15-1ubuntu16.04_amd64.deb mysql-community-client_5.7.15-1ubuntu16.04_amd64.deb mysql-client_5.7.15-1ubuntu16.04_amd64.deb mysql-community-server_5.7.15-1ubuntu16.04_amd64.deb mysql-server_5.7.15-1ubuntu16.04_amd64.deb
4.安裝pip出錯
- 解決:可改用如下命令:
sudo apt-get install python-pip python-dev build-essential
sudo pip install --upgrade pip
sudo pip install --upgrade virtualenv
5.安裝Django超時報錯
- 解決
設置超時時間:sudo pip install django --default-timeout 100
或者使用其他下載源:pip install web.py -i
6.安裝MySQL-python報錯
- 錯誤:
EnvironmentError: mysql_config not found
- 解決:
sudo apt-get install libmysqld-dev
- 安裝MySQL-python:
pip install MySQL-python
7.更新Python庫
pip install --upgrade 庫名