Ubuntu 18.04 安装 Apache, MySQL, PHP7, phpMyAdmin

1、准备

#更新软件源中的所有软件列表(必须)
sudo apt update

# 更新软件(建议)
sudo apt upgrade

# 更新系统版本(非必要时,不建议升级)
sudo apt dist-upgrade

2、安装Apache

sudo apt install apache2

3、安装PHP

sudo apt install php

4、安装MySQL

sudo apt install mysql-server php-mysql

5、配置MySQL

mysql -u root
use mysql;
update mysql.user set authentication_string=PASSWORD('你的密码'), plugin='mysql_native_password' where user='root';
flush privileges;
quit;
sudo service mysql stop
sudo service mysql start

6、附加安装

sudo apt install libapache2-mod-php php-mysql php-curl php-gd

7、安装phpMyAdmin

sudo apt install phpmyadmin

8、启用mod_rewrite模块

sudo a2enmod rewrite
sudo service apache2 restart

9、配置

#编辑apache2.conf,/var/www/路径可修改(如修改为/data/www/),启用RewriteEngine
<Directory /var/www>
	Options Indexes FollowSymLinks
	AllowOverride All
	Require all granted
	RewriteEngine On
</Directory>

#编辑 /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
	ServerName example.com
	ServerAlias www.example.com
	ServerAdmin service@example.com
	DocumentRoot /var/www/example
	<Directory />
		DirectoryIndex index.html index.php
		Options FollowSymLinks
		AllowOverride All
		RewriteEngine On
	</Directory>
	ErrorLog /var/log/apache2/example_error.log
	CustomLog /var/log/apache2/example_access.log combined
</VirtualHost>

10、权限设置

#改变/var/www/目录所有者为ubuntu(腾讯云Ubuntu默认用户)
sudo chown -R ubuntu /var/www/

#设置网站权限
chmod 755 /var/www/
chmod 777 /var/www/example/application
chmod 777 /var/www/example/uploads -R
chmod 777 /var/www/example/runtime -R

 

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页