Ubuntu 19.04 安装 Apache, MySQL, PHP, phpMyAdmin
1. 准备
sudo apt-get update
2. 安装Apache
sudo apt-get install apache2
3. 安装PHP
sudo apt-get install php
默认安装的是php7
4. 安装MySQL
sudo apt-get install mysql-server mysql-client libmysqlclient-dev php-mysql
默认安装的是5.7版本
MySQL添加新用户、为用户创建数据库、为新用户分配权限
5. 配置MySQL普通用户
$ mysql -u root -p
mysql> 密码
mysql> use mysql;
mysql>mysql> create user 'test'@'localhost' identified by '123456';
mysql> flush privileges;
mysql> exit;
$ #退出后,用新账户登陆一下
$ mysql -u test -p
mysql> 密码
- 如果安装过程中没有跳转到root用户密码设置界面,则需要查看这篇博客:MySQL安装、安装时未提示输入密码、如何修改密码小结 以及这篇:Ubuntu18.04安装mysql5.7
update mysql.user set authentication_string=PASSWORD('123456'), plugin='mysql_native_password' where user='root';
- root用户创建database后,对其他用户进行授权参考这篇博客:MySQL添加用户、删除用户与授权
6. 安装服务器php模块
sudo apt-get install libapache2-mod-php php-mysql php-curl php-gd
7. 安装phpMyAdmin
sudo apt-get install phpmyadmin
安装完后浏览器打开:http://localhost/phpmyadmin即可,细节可参考在Ubuntu下快速安装phpmyadmin
8. 用mod_rewrite模块
sudo a2enmod rewrite
sudo service apache2 restart
9. 配置
#编辑apache2.conf,/var/www/路径可修改(如修改为/home/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. 安装redis-server
sudo apt-get install redis-server
11. 安装pip
sudo apt-get install python-pip