您的位置:首页 > 其它

记一次LAMP环境搭建

2018-09-08 11:36 736 查看
环境:
centos_7_x86_64_1804
mysql-5.7.23
httpd-2.4.34
apr-1.6.3
apr-util-1.6.1
php-5.6.37

centos下载地址:linuxdown.net
mysql下载地址:https://www.oracle.com/cn/mysql/resources.html
httpd、apr、apr-util下载地址:httpd.apache.org
php下载地址:www.php.net

安装mysql数据库
1.解压安装包
[root@localhost soft]# tar -zxvf mysql-5.7.23-el7-x86_64.tar.gz
2.解压的文件夹复制为/usr/local/mysql-5.7
[root@localhost soft]# cp -r mysql-5.7.23-el7-x86_64 /usr/local/mysql-5.7
3.初始化数据库
[root@localhost soft]# mkdir -p /data/mysql
[root@localhost soft]# cd /usr/local/mysql-5.7/bin/
[root@localhost bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql-5.7 --datadir=/data/mysql
2018-09-08T02:30:39.620042Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-09-08T02:30:43.513954Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-09-08T02:30:43.805205Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-09-08T02:30:43.871052Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 2f90f45a-b30f-11e8-b3bd-080027e98963.
2018-09-08T02:30:43.873135Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-09-08T02:30:43.873814Z 1 [Note] A temporary password is generated for root@localhost: SUIiuhu)G3fQ
执行完毕,最后一行末尾有初始化的root用户密码:SUIiuhu)G3fQ
4.修改配置文件
vim /etc/my.cnf
datadir=/data/mysql 修改这一行
pid-file=/var/run/mariadb/mariadb.pid 这一行注释掉
!includedir /etc/my.cnf.d 这一行注释掉

[root@localhost bin]# cp ../support-files/mysql.server /etc/init.d/mysqld
vim /etc/init.d/mysqld

basedir=/usr/local/mysql-5.7

datadir=/data/mysql
conf=/etc/my.cnf 修改这三行

5.启动数据库
[root@localhost bin]# service mysqld start
Starting MySQL. SUCCESS!

[root@localhost bin]# mysql -u root -p'SUIiuhu)G3fQ'
ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords.
登录数据库,提示密码过期。

修改密码:
先停库
[root@localhost bin]# service mysqld stop
Shutting down MySQL.. SUCCESS!

[root@localhost bin]# /usr/local/mysql-5.7/bin/mysqld_safe --skip-grant-tables &
[1] 3213
[root@localhost bin]# 2018-09-08T02:36:25.438825Z mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
2018-09-08T02:36:25.470298Z mysqld_safe Starting mysqld daemon with databases from /data/mysql 跳过密码验证启动数据库

[root@localhost bin]# mysql -u root 使用root直接登录,不用密码
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.23 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MySQL [mysql]> select * from user where user='root' \G;
*************************** 1. row ***************************
Host: localhost
User: root
Select_priv: Y
Insert_priv: Y
Update_priv: Y
Delete_priv: Y
Create_priv: Y
Drop_priv: Y
Reload_priv: Y
Shutdown_priv: Y
Process_priv: Y
File_priv: Y
Grant_priv: Y
References_priv: Y
Index_priv: Y
Alter_priv: Y
Show_db_priv: Y
Super_priv: Y
Create_tmp_table_priv: Y
Lock_tables_priv: Y
Execute_priv: Y
Repl_slave_priv: Y
Repl_client_priv: Y
Create_view_priv: Y
Show_view_priv: Y
Create_routine_priv: Y
Alter_routine_priv: Y
Create_user_priv: Y
Event_priv: Y
Trigger_priv: Y
Create_tablespace_priv: Y
ssl_type:
ssl_cipher:
x509_issuer:
x509_subject:
max_questions: 0
max_updates: 0
max_connections: 0
max_user_connections: 0
plugin: mysql_native_password
authentication_string: *23AE809DDACAF96AF0FD78ED04B6A265E05AA257
password_expired: Y
password_last_changed: 2018-09-07 23:22:58
password_lifetime: NULL
account_locked: N
1 row in set (0.00 sec)

MySQL [mysql]> update user set password_expired='N' where user='root'; 设置root密码永不过期
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0

MySQL [mysql]> update user set authentication_string=password('123') where user='root'; 设置一个新的root密码
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1

MySQL [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MySQL [mysql]> exit
Bye
[root@localhost bin]# killall mysqld 关闭数据库
2018-09-08T02:43:34.127030Z mysqld_safe mysqld from pid file /data/mysql/localhost.localdomain.pid ended

[1]+ 完成 /usr/local/mysql-5.7/bin/mysqld_safe --skip-grant-tables

[root@localhost ~]# service mysqld start

Starting MySQL.. SUCCESS!
[root@localhost ~]# mysql -u root -p'123'
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.23 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)

MySQL [(none)]> exit
Bye
[root@localhost bin]#
mysql数据库安装完毕。

安装httpd
httpd依赖于apr和apr-util,所以要先装apr和apr-util-1
安装apr
[root@localhost apr-1.6.3]# tar -zxvf apr-1.6.3.tar.gz
[root@localhost apr-1.6.3]# cd apr-1.6.3/
[root@localhost apr-1.6.3]# ./configure --prefix=/usr/local/apr
rm: cannot remove 'libtoolT': No such file or directory 安装时遇见次错误。
网上搜索解决方法:
编辑configure文件
找到$RM "$cfgfile"这一行,将这一行注释掉。
再次执行configure命令成功
[root@localhost apr-1.6.3]# make && make install
安装apr-util
[root@localhost soft]# tar -zxvf apr-util-1.6.1.tar.gz
[root@localhost soft]# cd apr-util-1.6.1/
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.6.1]# make
xml/apr_xml.c:35:19: 致命错误:expat.h:没有那个文件或目录
编译时遇见此错误,网上搜索,缺少expat库,安装expat-devel包,重新编译成功
[root@localhost apr-util-1.6.1]# make install
安装httpd
[root@localhost soft]# tar -zxvf httpd-2.4.34.tar.gz
[root@localhost soft]# cd httpd-2.4.34/
[root@localhost httpd-2.4.34]# ./configure --prefix=/usr/local/httpd --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/ 遇见错误,缺少pcre库,安装pcre-devel包,重新配置,配置成功
[root@localhost httpd-2.4.34]# make
[root@localhost httpd-2.4.34]# make install
apache到此安装完成

安装PHP
[root@localhost soft]# tar -zxvf php-5.6.37.tar.gz
[root@localhost soft]# cd php-5.6.37/
[root@localhost php-5.6.37]# ./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/httpd/bin/apxs --with-config-file-path=/usr/local/php5/etc --with-mysql=/usr/local/mysql-5.7 --with-pdo-mysql=/usr/local/mysql-5.7 --with-mysqli=/usr/local/mysql-5.7/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif

configure: error: xml2-config not found. Please check your libxml2 installation.
遇见此错误,缺少xml2库,安装libxml2-devel包。安装完之后重新配置。

configure: error: Cannot find OpenSSL's <evp.h>
缺少openssl库,安装openssl-devel包,重新执行configure命令

configure: error: Please reinstall the BZip2 distribution
缺少bzip2库,安装bzip2-devel包

configure: error: jpeglib.h not found.
安装libjpeg-turbo-devel包

configure: error: png.h not found.
安装libpng-devel包

configure: error: freetype-config not found
安装freetype-devel包。

configure: error: mcrypt.h not found. Please reinstall libmcrypt.
缺少libmcrypt库,在系统镜像中没有找到libmcrypt包,网上下载
下载网址:ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz
源码安装libmcrypt
tar -zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure --prefix=/usr/local/libmcrypt
make && make install
修改php安装选项 --with-mcrypt=/usr/local/libmcrypt,重新配置

configure: error: Cannot find libmysqlclient_r under /usr/local/mysql-5.7.
Note that the MySQL client library is not bundled anymore!
没有找到libmysqlclient_r.so文件。mysql数据库默认的文件是libmysqlclient.so
php默认的是找libmysqlclient_r.so文件,所以提示找不到文件。进入mysql数据库安装目录,建立软连接
cd /usr/local/mysql-5.7/lib
[root@localhost lib]# ls
libmysqlclient.a libmysqlclient.so.20 libmysqld.a libmysqlservices.a pkgconfig
libmysqlclient.so libmysqlclient.so.20.3.10 libmysqld-debug.a mecab plugin
[root@localhost lib]# ln -s libmysqlclient.so.20.3.10 libmysqlclient_r.so
[root@localhost lib]# ls -l
总用量 923956
-rw-r--r-- 1 mysql mysql 20675802 9月 7 23:17 libmysqlclient.a
lrwxrwxrwx 1 root root 25 9月 8 02:16 libmysqlclient_r.so -> libmysqlclient.so.20.3.10
lrwxrwxrwx 1 mysql mysql 20 9月 7 23:18 libmysqlclient.so -> libmysqlclient.so.20
lrwxrwxrwx 1 mysql mysql 25 9月 7 23:18 libmysqlclient.so.20 -> libmysqlclient.so.20.3.10
-rwxr-xr-x 1 mysql mysql 9587056 9月 7 23:18 libmysqlclient.so.20.3.10
-rw-r--r-- 1 mysql mysql 547940170 9月 7 23:18 libmysqld.a
-rw-r--r-- 1 mysql mysql 367873702 9月 7 23:17 libmysqld-debug.a
-rw-r--r-- 1 mysql mysql 42030 9月 7 23:17 libmysqlservices.a
drwxr-xr-x 4 mysql mysql 28 9月 7 23:18 mecab
drwxr-xr-x 2 mysql mysql 28 9月 7 23:17 pkgconfig
drwxr-xr-x 3 mysql mysql 4096 9月 7 23:18 plugin
建立完连接之后,重新配置php
此次配置成功。

[root@localhost php-5.6.37]# make
[root@localhost php-5.6.37]# make install

配置apache能解析php
修改httpd配置文件
/usr/local/httpd/conf/httpd.conf
1.
#ServerName www.example.com:80 将这一行的注释去掉,或者将此行改为:ServerName localhost:80
2.
<Directory />
AllowOverride none
Require all denied 将denied改为granted
</Directory>
3.
<IfModule dir_module> DirectoryIndex index.html index.php 添加index.php项</IfModule>4.
AddType application/x-compress .ZAddType application/x-gzip .gz .tgzAddType application/x-httpd-php .php 添加这一行
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  LAMP环境搭建