ubuntu 16.04 搭建lamp的苦逼经历

标签: ubuntu php lamp apache
3474人阅读 评论(0) 收藏 举报
分类:

大致流程:

apache安装:

edemon@linux:~$ sudo apt install apache2

php安装:

edemon@linux:~$ sudo apt install php7.0-cli
……
Creating config file /etc/php/7.0/cli/php.ini with new version

mysql安装:

edemon@linux:~$ sudo apt install mysql-server
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Checking if update is needed.
This installation of MySQL is already upgraded to 5.7.12, use –force if you still need to run mysql_upgrade
Setting up mysql-server (5.7.12-0ubuntu1) …

其他模块:

edemon@linux:~$ sudo apt-get install libapache2-mod-php7.0

检测php:

edemon@linux:~$ cat /etc/apache2/mods-enabled/php7.0.load
# Conflicts: php5
LoadModule php7_module /usr/lib/apache2/modules/libphp7.0.so

测试并开启服务:

edemon@linux:~sudoservicemysqlrestartedemon@linux:  sudo service apache2 restart
edemon@linux:~$ sudo vim /var/www/html/phpinfo.php

<?php
        echo phpinfo();
?>

URL: 
http://localhost/phpinfo.php

这里写图片描述

查看mysql服务:

edemon@linux:~$ service mysql status
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since 二 2016-06-07 09:37:40 CST; 8min ago
Process: 29705 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exited, status=0/SUCCESS)
Process: 29701 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 29704 (mysqld)
CGroup: /system.slice/mysql.service
└─29704 /usr/sbin/mysqld

6月 07 09:37:39 linux systemd[1]: Starting MySQL Community Server…
6月 07 09:37:40 linux systemd[1]: Started MySQL Community Server.

安装phpmyadmin:

edemon@linux:~sudochmod777/var/www[sudo]passwordforedemon:edemon@linux:  sudo apt install phpmyadmin

sudo apt install php-mbstring
sudo apt install php-gettext

建立var/www/html/phpmyadmin软链接:

sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin

php配置文件php.ini:

edemon@linux:/etc/php/7.0/apache2$ ls
conf.d php.ini

display_errors = On(显示错误日志)
extension=php_mbstring.dll (开启mbstring)

这里写图片描述

重启apache:

sudo /etc/init.d/apache2 restart

因为默认安装phpmyadmin时会安装apahce和php等依赖包,由于是16.04系统,会默认安装php7.0,php7.0又没有默认自带php-mbstring,php-gettext这两个包,所以会报错。

重要的查找和命令:

phpmyadmin相关文件:
/var/lib/dpkg/info/phpmyadmin.postinst

mysql相关文件:
edemon@linux:~$ whereis mysql
mysql: /usr/lib/mysql /etc/mysql /usr/share/mysql

edemon@linux:/etc/mysql$ ls
conf.d debian-start my.cnf.fallback mysql.conf.d
debian.cnf my.cnf mysql.cnf

edemon@linux:/usr/lib/mysql$ ls
lz4_decompress plugin resolve_stack_dump zlib_decompress

edemon@linux:/usr/share/mysql$ ls
bulgarian magic
charsets my-default.cnf
czech mysqld_multi.server
danish mysql-log-rotate
debian_create_root_user.sql mysql_security_commands.sql
debian-start.inc.sh mysql_sys_schema.sql
dictionary.txt mysql-systemd-start
docs mysql_system_tables_data.sql
dutch mysql_system_tables.sql
echo_stderr mysql_test_data_timezone.sql
english norwegian
errmsg-utf8.txt norwegian-ny
estonian polish
fill_help_tables.sql portuguese
french romanian
german russian
greek serbian
hungarian slovak
innodb_memcached_config.sql spanish
install_rewriter.sql swedish
italian ukrainian
japanese uninstall_rewriter.sql
korean

查找文件:

edemon@linux:~$ sudo find / -name filename

关于apparmor:
http://manpages.ubuntu.com/manpages/xenial/en/man7/apparmor.7.html

后来发现这样命令安装的后果是mysql根本不能正常使用,可能是自己的系统升级后,原来的mysql没啦,但是残余软件还在,导致安装出现了问题。所以最后还是老老实实的用安装包安装吧

换用安装包安装 

安装顺序:
mysql-common_5.7.13-1ubuntu16.04_amd64.deb
mysql-community-client_5.7.13-1ubuntu16.04_amd64.deb
mysql-client_5.7.13-1ubuntu16.04_amd64.deb
mysql-community-server_5.7.13-1ubuntu16.04_amd64.deb
安装mysql server时产生软件依赖问题:
mysql-community-server depends on apparmor; however:
Package apparmor is not installed.
mysql-community-server depends on libmecab2 (>= 0.996-1.2ubuntu1); however:
Package libmecab2 is not installed.
那就先安装上:
sudo apt -f install apparmor libmecab2
然后mysql-community-server,mysql-server就能正常使用了。

mysql -u root -p

mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2016-06-08 11:42:47 |
+---------------------+
1 row in set (0.00 sec)
mysql> exit;
Bye

使用root账户登录phpmyadmin:
这里写图片描述

解决原则

安装软件和之前的产生冲突——删除所有的残余文件!
什么文件不能正常使用——删除!
软件依赖——缺啥装啥!

—————————————————————————————————————————————————————————————————————————-

幕后:

后期mysql安装出现各种错误,所以尝试过使用官网安装源:http://dev.mysql.com/downloads/repo/apt/
使用方法:http://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/
为了保证顺利安装,删除所有的mysql残余文件。
sudo find / -name mysql
sudo rm -r filename

使用安装源的注意事项:
Note
Once the MySQL APT repository is enabled on your system, you will no longer be able to install any MySQL packages from your platform’s native software repositories until the MySQL APT repository is disabled.

输入密码的注意事项:
Important
Make sure you remember the root password you set. Users who want to set a password later can leave the passwordfield blank in the dialogue box and just press OK; in that case, root access to the server will be authenticated by The Socket Peer-Credential Authentication Plugin for connections using a Unix socket file. You can set the root password later using the program mysql_secure_installation.

edemon@linux:~$ sudo service mysql status
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: en
Active: inactive (dead)
# MySQL systemd service file

我发现这并没有什么×用

/lib/systemd/system/mysql.service的内容:

[Unit]
Description=MySQL Community Server
After=network.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql
PermissionsStartOnly=true
ExecStartPre=/usr/share/mysql/mysql-systemd-start pre
ExecStart=/usr/sbin/mysqld
ExecStartPost=/usr/share/mysql/mysql-systemd-start post
TimeoutSec=600
Restart=on-failure
RuntimeDirectory=mysqld
RuntimeDirectoryMode=755

——————————————————————————————————————————————————————————————————————————–

其他参考

删除mysql:
删除mysql
1.sudo apt-get autoremove –purge mysql-server-5.5
2.sudo apt-get remove mysql-common
清理残留数据
dpkg -l |grep ^rc|awk ‘{print $2}’ |sudo xargs dpkg -P
重新安装mysql
1.sudo apt-get install mysql-server
2.sudo apt-get install mysql-client
3.sudo apt-get install php5-mysql

ubuntu16.04 LAMP环境搭建URL:

http://www.tuicool.com/articles/2Evyq2V

常见依赖问题

正在设置 mysql-server-5.5 (5.5.27-0ubuntu2) …start: Job failed to startinvoke-rc.d: initscript mysql,
action “start” failed.dpkg: error processing mysql-server-5.5 (–configure): 子进程 已安装 post-installation 脚本 返回了错误号 1dpkg: dependency problems prevent configuration of mysql-server: mysql-server 依赖于 mysql-server-5.5;然而: 软件包 mysql-server-5.5 尚未配置。dpkg: error processing mysql-server (–configure): 依赖关系问题 - 仍未被配置因为错误消息指示这是由于上一个问题导致的错误,没有写入 apport 报告。
在处理时有错误发生: mysql-server-5.5 mysql-serverE: Sub-process /usr/bin/dpkg returned an error code (1)
这个问题刚好之前我遇到过,一段时间一直困扰着我,但是经过我的研究,慢慢摸索,也查阅了相关的资料,终于把这个问题顺利解决了,现在我就把这个问题的解决办法分享给大家,让更多的人知道。
在删除mysql前 需要先删除一下 /var/lib/mysql 还有 /etc/mysql
需要输入以下几条命令:
sudo rm /var/lib/mysql/ -Rsudo rm /etc/mysql/ -R
sudo apt-get autoremove mysql* –purge
sudo apt-get remove apparmor
sudo apt-get install mysql-server mysql-common
从上到下依次输入命令敲回车,等这些命令都执行完之后,会重新装Mysql数据库,到重新安装出现输入密码的操作的时候说明你的问题已经解决了!

配置 MySQL 的管理员密码:

sudo mysqladmin -u root password newpassword

查看评论

ubuntu 16.04 搭建LAMP开发环境

Ubuntu上搭建LAMP开发环境
  • dfydn
  • dfydn
  • 2017-04-15 21:14:25
  • 3830

Ubuntu16.04下编译spice-gtk

安装依赖包 sudo apt-get install libgkt-3-dev
  • rebackhua
  • rebackhua
  • 2017-02-17 15:59:13
  • 1003

速度之王 — LZ4压缩算法(一)

LZ4是一个快速的无损压缩算法,单核的压缩速度超过400MB/s,单核的解压速度超过1GB/s。 LZ4也适用于多核的情况,压缩速度能成倍的提高,解压速度几乎达到RAM的速度限制。 文本主要分析LZ4...
  • zhangskd
  • zhangskd
  • 2013-12-19 17:35:55
  • 57404

解决/bin/sh: lz4c: 未找到命令

安装lz4: apt-get update apt-get install liblz4-tool 重新编译 ok
  • mls805379973
  • mls805379973
  • 2017-11-22 16:19:05
  • 578

ubuntu16 mysql配置文件my.cnf中没有bind-address

使用ubuntu16安装mysql时,发现mysql的配置文件/etc/mysql/my.cnf 里面基本没有什么东西:# # The MySQL database server configurat...
  • qq_33935254
  • qq_33935254
  • 2016-12-23 15:23:35
  • 1670

Ubuntu16.06 禁用ipv4流量只用ipv6

知识储配 所有个人安装的软件,在用户的主目录下有一个.config的隐藏文件,其中包含用户安装软件的一些信息(包含个人配置文件) Transmisson默认不开启ipv4流量禁用 步骤 进入配置文件的...
  • Bleachswh
  • Bleachswh
  • 2016-05-04 10:33:34
  • 1960

phpmyadmin 出现The mbstring extension is missing

我在centos6.4中安装phpmyadmin之后,浏览报错The mbstring extension is missing yum install php-mbstring...
  • momo_mutou
  • momo_mutou
  • 2014-09-17 16:04:22
  • 2860

Changes Affecting Upgrades to MySQL 5.7

2.11.1.1 Changes Affecting Upgrades to MySQL 5.7 Before upgrading to MySQL 5.7, review the chang...
  • shaochenshuo
  • shaochenshuo
  • 2016-09-20 17:55:17
  • 475

Ubuntu 16.04安装Mysql和安装时出现错误解决

安装MySQL过程中出错,部分内容如下:update-alternatives: 使用 /etc/mysql/mysql.cnf 来在自动模式中提供 /etc/mysql/my.cnf (my.cnf...
  • Gethin_H
  • Gethin_H
  • 2017-07-13 18:54:21
  • 1683

ubuntu16.04搭建LAMP环境以及遇到的问题

搭建顺序为Apache,Mysql,PHP以及phpmyadmin 1.安装Apache 在命令行输入 sudo apt-get install apache2 输入管理员密码 并选择Y 安装完...
  • whd526
  • whd526
  • 2017-04-03 19:27:44
  • 1301
    个人资料
    持之以恒
    等级:
    访问量: 37万+
    积分: 9440
    排名: 2419
    我的链接
    最新评论