Ubuntu 19.04 安装 Apache, MySQL, PHP, phpMyAdmin

本文详细介绍在Ubuntu19.04上安装和配置LAMP环境的步骤,包括Apache、MySQL、PHP及phpMyAdmin的安装,以及mod_rewrite模块的使用和虚拟主机配置,最后还介绍了redis-server和pip的安装。

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> 密码
  1. 如果安装过程中没有跳转到root用户密码设置界面,则需要查看这篇博客:MySQL安装、安装时未提示输入密码、如何修改密码小结 以及这篇:Ubuntu18.04安装mysql5.7
    update mysql.user set authentication_string=PASSWORD('123456'), plugin='mysql_native_password' where user='root';
  2. 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

mysql官网上下载mysql-server_5.7.21-1ubuntu14.04_amd64.deb-bundle.tar,然后进行离线安装,解压该安装包,会出现11个依赖包,按照顺序依次使用sudo dpkg -i 进行安装,中间会报错,显示缺少相应的依赖,具体如下: *******@ubuntu:/opt/mysql$ sudo dpkg -i mysql-community-client_5.7.21-1ubuntu14.04_amd64.deb Selecting previously unselected package mysql-community-client. (Reading database ... 208518 files and directories currently installed.) Preparing to unpack mysql-community-client_5.7.21-1ubuntu14.04_amd64.deb ... Unpacking mysql-community-client (5.7.21-1ubuntu14.04) ... dpkg: dependency problems prevent configuration of mysql-community-client: mysql-community-client depends on libaio1 (>= 0.3.93); however: Package libaio1 is not installed. dpkg: error processing package mysql-community-client (--install): dependency problems - leaving unconfigured Processing triggers for man-db (2.6.7.1-1ubuntu1) ... Errors were encountered while processing: mysql-community-client 和 ********@ubuntu:/opt/mysql$ sudo dpkg -i mysql-community-server_5.7.21-1ubuntu14.04_amd64.deb Selecting previously unselected package mysql-community-server. (Reading database ... 208598 files and directories currently installed.) Preparing to unpack mysql-community-server_5.7.21-1ubuntu14.04_amd64.deb ... Unpacking mysql-community-server (5.7.21-1ubuntu14.04) ... dpkg: dependency problems prevent configuration of mysql-community-server: mysql-community-server depends on libmecab2 (>= 0.996-1.1); however: Package libmecab2 is not installed. dpkg: error processing package mysql-community-server (--install): dependency problems - leaving unconfigured Processing triggers for man-db (2.6.7.1-1ubuntu1) ... Processing triggers for ureadahead (0.100.0-16) ... ureadahead will be reprofiled on next reboot Errors were encountered while processing: mysql-community-server 附上依赖包安装顺序: 1.mysql-common_5.7.21-1ubuntu14.04_amd64.deb 2.libmysqlclient20_5.7.21-1ubuntu14.04_amd64.deb 3.libmysqlclient-dev_5.7.21-1ubuntu14.04_amd64.deb 4.libmysqld-dev_5.7.21-1ubuntu14.04_amd64.deb
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值