记一次LAMP环境搭建
環境:
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 .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php????????添加這一行
轉載于:https://blog.51cto.com/8469401/2171967
總結
以上是生活随笔為你收集整理的记一次LAMP环境搭建的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Leetcode】62. 不同路径
- 下一篇: 如何为你的回归问题选择最合适的机器学习算