1. 程式人生 > >Ubuntu搭建LAMP開發環境

Ubuntu搭建LAMP開發環境

tun enable 開發環境 sites -c site chmod php7.0 搭建lamp

1、安裝Apache

sudo apt-get install apache2

測試: 瀏覽器訪問 (如:http://localhost),出現It Works!網頁。

查看狀態: service apache2 status/start/stop/restart
Web目錄:/var/www
安裝目錄: /etc/apache2/
全局配置: /etc/apache2/apache2.conf
監聽端口: /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
查看狀態:service mysql status/start/stop/retart
查看監聽端口的情況: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 

測試
vim /var/www/html/phpinfo.php
文件中寫:<?php echo phpinfo();?>
瀏覽器訪問:http://地址/phpinfo.php(即http://localhost/phpinfo.php),出現PHP Version網頁

5.修改權限

sudo chmod 777 /var/www

6.安裝phpMyAdmin

sudo apt-get install phpmyadmin

安裝:選擇apache2,點擊確定。下一步選擇是要配置數據庫,並輸入密碼。
創建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://地址/phpmyadmin(即http://localhost/phpmyadmin)

7.配置Apache

vim /etc/apache2/apache2.conf

添加:

AddType application/x-httpd-php .php .htm .html 
AddDefaultCharset UTF-8 

重啟Apache服務

service apache2 restart

Ubuntu搭建LAMP開發環境