linux搭建LAMP

发布时间:2022-06-20 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了linux搭建LAMP脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

搭建wordPress

编译安装的MySQL

安装如下基础软件,就可以解决你后面编译脚本的,绝大多数错误问题了

yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel oPEnssl-devel ncurses-devel SQLITe-devel readline-devel tk-devel GDBm-devel db4-devel libpcap-devel xz-devel net-tools vim -y

yum install @R_418_1512@ make pcre-devel ncurses-devel openssl-devel libcurl-devel -y

yum install libXMl2-devel libjpeg-devel libpng-devel freetype-devel libcurl-devel wget -y

linux很多软件的运行,依赖于操作系统本身的一些软件支持 yum groupinstall "Development tools" -y

桌面开发工具包(图形化相关包) yum groupinstall "Desktop Platform Development" -y

安装一些底层命令 [root@boos mysql-5.6.50]# yum install cmake pcre-devel ncurses-devel openssl-devel libcurl-devel -y

linux很多软件的运行,依赖于操作系统本身的一些软件支持 yum groupinstall "Development tools" -y

桌面开发工具包(图形化相关包) yum groupinstall "Desktop Platform Development" -y

底层编译库的安装 yum install cmake pcre-devel ncurses-devel openssl-devel libcurl-devel -y

关闭火墙 [root@boos ~]# iptables -F [root@boos ~]# Systemctl stop firewalld [root@boos ~]# systemctl disable firewalld [root@boos mysql-5.6.50]# setenforce 0 setenforce: SELinux is disabled

安装httpd [root@boos ~]# yum install httpd -y

安装mysql [root@boos source-code]# wget -c https://repo.huaweicloud wangt.cc /mysql/Downloads/MySQL-5.6/mysql-5.6.50.tar.gz --2022-04-01 17:31:46-- https://repo.huaweicloud wangt.cc /mysql/Downloads/MySQL-5.6/mysql-5.6.50.tar.gz Resolving repo.huaweicloud wangt.cc (repo.huaweicloud wangt.cc )... 120.232.209.150, 175.153.171.171, 118.123.210.88, ... Connecting to repo.huaweicloud wangt.cc (repo.huaweicloud wangt.cc )|120.232.209.150|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 32409084 (31M) [application/octet-stream] Saving to: ‘mysql-5.6.50.tar.gz’

100%[=======================================>] 32,409,084 10.7MB/s in 2.9s

2022-04-01 17:31:50 (10.7 MB/s) - ‘mysql-5.6.50.tar.gz’ saved [32409084/32409084]

[root@boos source-code]# ll -h total 31M -rw-r--r-- 1 root root 31M Sep 23 2020 mysql-5.6.50.tar.gz

对mysql解压缩 [root@boos source-code]# tar -zxf mysql-5.6.50.tar.gz

查看解压文件夹的大小 [root@boos source-code]# du -sh * 284M mysql-5.6.50 31M mysql-5.6.50.tar.gz

[root@boos source-code]# cd mysql-5.6.50 [root@boos mysql-5.6.50]# ls BUILD extra mysys_ssl storage client include packaging strings cmake INSTALL plugin support-files CMakeLists.txt libmysql README tests cmd-line-utils libmysqld regex unittest config.h.cmake libservices scripts VERSION configure.cmake LICENSE source_downloads vio dbug man sql win Docs mysql-test sql-bench zlib Doxyfile-perfschema mysys sql-common

创建编译脚本,设置编译参数 [root@boos mysql-5.6.50]# vim cmake.sh [root@boos mysql-5.6.50]# cat cmake.sh cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ -DMYSQL_DATADIR=/usr/local/mysql/data -DENABLED_LOCAL_INFILE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_EXTRA_CHARSETS=all -DMYSQL_USER=mysql

设置权限 [root@boos mysql-5.6.50]# chmod +x cmake.sh [root@boos mysql-5.6.50]# ll cmake.sh -rwxr-xr-x 1 root root 295 Apr 1 17:38 cmake.sh

执行此脚本 [root@boos mysql-5.6.50]# ./cmake.sh

目前mysql还是没有的,只有安装结束后,会自动生成 -- Build files have been written to: /usr/local/source-code/mysql-5.6.50 [root@boos mysql-5.6.50]# ls /usr/local/mysql ls: cannot access /usr/local/mysql: No such file or directory [root@boos mysql-5.6.50]#

开始编译,以及安装到指定的位置 安装过程会较久,等待即可,别出问题就行。

[root@lamp-241 mysql-5.6.50]# make && make install

修改mysql安装目录的权限,属主,属组 [root@boos mysql-5.6.50]# chown -R mysql.mysql /usr/local/mysql/ [root@boos mysql-5.6.50]# ll /usr/local/mysql/ total 244 drwxr-xr-x 2 mysql mysql 4096 Apr 1 18:14 bin drwxr-xr-x 3 mysql mysql 4096 Apr 1 18:13 data drwxr-xr-x 2 mysql mysql 4096 Apr 1 18:13 docs drwxr-xr-x 3 mysql mysql 4096 Apr 1 18:13 include drwxr-xr-x 3 mysql mysql 4096 Apr 1 18:13 lib -rw-r--r-- 1 mysql mysql 198041 Sep 23 2020 LICENSE drwxr-xr-x 4 mysql mysql 4096 Apr 1 18:13 man drwxr-xr-x 10 mysql mysql 4096 Apr 1 18:14 mysql-test -rw-r--r-- 1 mysql mysql 587 Sep 23 2020 README drwxr-xr-x 2 mysql mysql 4096 Apr 1 18:14 scripts drwxr-xr-x 28 mysql mysql 4096 Apr 1 18:14 share drwxr-xr-x 4 mysql mysql 4096 Apr 1 18:14 sql-bench drwxr-xr-x 2 mysql mysql 4096 Apr 1 18:14 support-files

初始化数据库,生成可用的数据库文件 移除默认的mysql配置文件,改名即可 [root@boos ~]# mv /etc/my wangt.cc f /etc/my wangt.cc f.ori [root@boos ~]# ls /etc/my wangt.cc f ls: cannot access /etc/my wangt.cc f: No such file or directory

确保没有mysql进程 [root@boos ~]# ps -ef |grep mysql root 3895 1424 0 18:40 pts/0 00:00:00 grep --color=auto mysql

进入mysql安装目录,开始初始化 [root@boos mysql]# ./scripts/mysql_install_db --user=mysql 看到两个ok后表示安装正确

验证数据库目录里是否有文件 [root@boos mysql]# ll /usr/local/mysql/data/ total 110604 -rw-rw---- 1 mysql mysql 12582912 Apr 1 18:41 ibdata1 -rw-rw---- 1 mysql mysql 50331648 Apr 1 18:41 ib_LOGfile0 -rw-rw---- 1 mysql mysql 50331648 Apr 1 18:41 ib_logfile1 drwx------ 2 mysql mysql 4096 Apr 1 18:41 mysql drwx------ 2 mysql mysql 4096 Apr 1 18:41 performance_schema drwxr-xr-x 2 mysql mysql 4096 Apr 1 18:13 test

拷贝脚本,放入linux一个固定的服务启动目录 [root@boos mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

启动、检查mysql服务 [root@boos mysql]# service mysql status MySQL is not running [FAILED] [root@boos mysql]# service mysql start Starting MySQL.Logging to '/usr/local/mysql/data/boos.err'. [ OK ] [root@boos mysql]# service mysql status MySQL running (4078) [ OK ] [root@boos mysql]#

设置mysql默认密码 [root@boos mysql]# /usr/local/mysql/bin/mysqladmin -uroot password 'wenjie666' Warning: Using a password on the command line interface can be insecure.

测试mysql登录 确保服务运行了 [root@boos mysql]# ps -ef |grep mysql root 3982 1 0 18:45 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/boos.pid mysql 4078 3982 0 18:45 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=boos.err --pid-file=/usr/local/mysql/data/boos.pid root 4138 1424 0 18:48 pts/0 00:00:00 grep --color=auto mysql

端口 [root@boos mysql]# netstat -tnlp |grep mysql tcp6 0 0 :::3306 ::😗 LISTEN 4078/mysqld

使用Mysql登录命令 [root@boos mysql]# mysql -uroot -pwenjie666 -bash: mysql: command not found

需要配置环境变量 [root@boos mysql]# vim /etc/profile [root@boos mysql]# tail -1 /etc/profile export PATH=/usr/local/mysql/bin/:$PATH

检查PATH变量, [root@boos mysql]# source /etc/profile [root@boos mysql]# [root@boos mysql]# echo $PATH /usr/local/mysql/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

执行命令登录 [root@boos mysql]# mysql -uroot -pwenjie666 Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 2 Server version: 5.6.50 Source distribution

Copyright (c) 2000, 2020, oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

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

mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec)

mysql> select version(); +-----------+ | version() | +-----------+ | 5.6.50 | +-----------+ 1 row in set (0.00 sec)

mysql> exit; Bye

[root@boos mysql]# pwd /usr/local/mysql

编译安装的apache

下载地址 http://Archive.apache.org/dist/apr/

文件下载 [root@boos ~]# wget -c http://archive.apache.org/dist/apr/apr-1.5.2.tar.bz2

解压缩,编译安装即可 [root@boos ~]# tar -xf apr-1.5.2.tar.bz2

如果不指定配置参数,则会安装到默认路径 并且这里需要修改一个配置 修改此行 [root@boos apr-1.5.2]# cd apr-1.5.2 [root@boos apr-1.5.2]# vim configure 29605 RM='$RM -f'

再次执行配置脚本 [root@boos apr-1.5.2]# ./configure

开始编译安装 [root@boos apr-1.5.2]# make && make install

安装apr-util软件

完整的APR(Apache portable Run-time libraries,Apache可移植运行库)实际上包含了三个开发包:apr、apr-util以及apr-iconv,每一个开发包分别独立开发,并拥有自己的版本。

apr-util该目录中也是包含了一些常用的开发组件。

这些组件与apr目录下的相比,它们与apache的关系更加密切一些。比如存储段和存储段组,加密等等 [root@boos source-code]# pwd /usr/local/source-code [root@boos source-code]# ls apr-1.5.2 apr-1.5.2.tar.bz2 mysql-5.6.50 mysql-5.6.50.tar.gz

[root@boos source-code]# wget -c https://archive.apache.org/dist/apr/apr-util-1.5.4.tar.bz2

解压缩 [root@boos source-code]# tar -xf apr-util-1.5.4.tar.bz2

开始编译安装apr-utils ,且需要指定安装的apr命令路径 [root@boos apr-util-1.5.4]# ./configure --with-apr=/usr/local/apr/bin/apr-1-config

编译且安装 [root@boos apr-util-1.5.4]# make && make inxtall

在编译安装好了apr和apr-util之后 你得找到基础软件库, 你得让系统找到这些软件库可以用 [root@boos apr-util-1.5.4]# ls /usr/local/apr/lib apr.exp libapr-1.so.0 libaprutil-1.so.0 libexpat.so.0 aprutil.exp libapr-1.so.0.5.2 libaprutil-1.so.0.5.4 libexpat.so.0.5.0 libapr-1.a libaprutil-1.a libexpat.a pkgconfig libapr-1.la libaprutil-1.la libexpat.la libapr-1.so libaprutil-1.so libexpat.so 这些.so就好比windows下的.dll

ldconfig命令

一般来说,库文件安装到/lib,/lib64,/usr/lib/,/usr/lib64等,都可以找得到; 但是如果一个软件A把库文件安装到/usr/local/A/lib下,就要把这个路径加入到ldconfig命令可以找到的路径列表里面去,别人才能找到。 ldconfig是一个动态链接库管理命令;主要用途是在默认搜索目录(/lib,/lib64,/usr/lib/,/usr/lib64)以及动态库配置文件/etc/ld.so.conf中所列的目录中搜索出可共享的动态链接库。

怎样将库文件的指定安装路径加入到ldconfig命令的搜索列表里 方法1:在/etc/ld.so.conf这个主配置文件里加上一行,写上让别人要查找库文件的路径

[root@boos apr-util-1.5.4]# echo "/usr/local/apr/lib/" >> /etc/ld.so.conf [root@boos apr-util-1.5.4]# [root@boos apr-util-1.5.4]# cat /etc/ld.so.conf include ld.so.conf.d/*.conf /usr/local/apr/lib/

方法2:在/etc/ld.so.conf.d/目录下创建一个*.conf结尾的文件,里面加入该路径即可

echo /usr/local/apr/lib/ > /etc/ld.so.conf.d/lamp.conf

ldconfig 上面加入路径后,就使用此命令让其生效

编译安装httpd
@H_406_144@

[root@boos source-code]# pwd /usr/local/source-code

[root@boos source-code]# wget -c https://archive.apache.org/dist/httpd/httpd-2.4.37.tar.bz2

解压缩httpd [root@boos source-code]# tar -xf httpd-2.4.37.tar.bz2 [root@boos source-code]# cd httpd-2.4.37 [root@boos httpd-2.4.37]#

[root@boos httpd-2.4.37]# ls ABOUT_APACHE buildconf httpd.dsp libhttpd.mak README.cmake acinclude.m4 CHANGES httpd.mak LICENSE README.platforms Apache-apr2.dsw CMakeLists.txt httpd.spec Makefile.in ROADMAP Apache.dsw config.layout include Makefile.win server apache_probes.d configure INSTALL modules srclib ap.d configure.in InstallBin.dsp NOTICE support build docs LAYOUT NWGNUmakefile test BuildAll.dsp emacs-style libhttpd.dep os VERSIONING BuildBin.dsp httpd.dep libhttpd.dsp README

修改配置参数,可以做成脚本 [root@boos httpd-2.4.37]# vim apache--configure.sh [root@boos httpd-2.4.37]# cat apache--configure.sh ./configure --enable-modules=all --enable-mods-shared=all --enable-so --enable-rewrite --with-pcre --enable-ssl --with-mpm=prefork --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr/bin/apu-1-config

添加执行权限,执行该脚本 [root@boos httpd-2.4.37]# chmod +x apache--configure.sh [root@boos httpd-2.4.37]# ./apache--configure.sh

如果你前面都和我的一样,那就不会出问题

yum -y install pcre-devel yum -y install openssl-devel

这些库就是和你上面给httpd编译添加的参数,是对应起来的了

编译且安装 root@boos httpd-2.4.37]# pwd /usr/local/source-code/httpd-2.4.37 [root@boos httpd-2.4.37]# make && make install

  编译安装的php

文件下载php [root@boos httpd-2.4.37]# wget -c https://museum.php wangt.cc /php7/php-7.2.17.tar.xz

解压缩 [root@boos source-code]# tar -xf php-7.2.17.tar.xz [root@boos source-code]# cd php-7.2.17

修改配置参数,可以做成脚本 [root@boos php-7.2.17]# vim configure_php.sh [root@boos php-7.2.17]# cat configure_php.sh ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysqli --with-pdo-mysql --with-zlib --with-curl --enable-zip --with-gd --with-freetype-dir --with-jpeg-dir --with-png-dir --enable-sockets --with-xMLrpc --enable-SOAp --enable-Opcache --enable-mbstring --enable-mbregex --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvSEM --enable-sysvshm --enable-calendar --enable-bcmath

configure配置php编译 修改文件权限 [root@boos php-7.2.17]# chmod +x configure_php.sh [root@boos php-7.2.17]# [root@boos php-7.2.17]# ./configure_php.sh

如果可能报错,缺少一些库,则需要安装如下依赖

比如你在装机时候,选择的软件包的不同 yum install libxml2-devel -y yum install libjpeg-devel -y yum install libpng-devel -y yum install freetype-devel -y yum -y install libcurl-devel

编译且安装 [root@boos php-7.2.17]# make && make install

[root@boos php-7.2.17]# pwd /usr/local/source-code/php-7.2.17

修改apache配置文件,找到你的安装路径 配置语言支持 [root@boos apache2]# cd conf [root@boos conf]# ls extra httpd.conf httpd.conf.bak magic mime.types original [root@boos conf]# vim httpd.conf 159 LoadModule negotiation_module modules/mod_negotiation.so 去掉这一行的注释 482 Include conf/extra/httpd-languages.conf 打开此选项,扩展配置文件就生效了

添加以下两行意思是以.php结尾的文件都认为是php程序文件,注意两句话的.php前面都是有一个空格的 也就是长这样 166 LoadModule php7_module modules/libphp7.so 167 AddHandler php7-script .php 168 AddType text/html .php

添加一个默认的网站首页,添加为php的文件 263 # 264 # DirectoryIndex: sets the file that Apache will serve if a directory 265 # is requested. 266 # 267 268 DirectoryIndex index.php index.html 269 270

关于网站默认的首页html文件,存放的目录路径,由以下参数控制 230 # DocumentRoot: The directory out of which you will serve your 231 # Documents. By default, all requests are taken From this directory, but 232 # symbolic links and aliases may be used to point to other locations. 233 # 234 DocumentRoot "/usr/local/apache2/htdocs" 235 <Directory "/usr/local/apache2/htdocs">

修改apache的子配置文件,优先支持中文,需要做如下两步操 [root@boos conf]# vim /usr/local/apache2/conf/extra/httpd-languages.conf

19 DefaultLanguage zh-CN

75 # Just list the languages in decreasing order of preference. We have 76 # more or less alphabetized them here. You probably want to change this. 77 # 78 LanguagePriority zh-CN en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv tr zh-CN zh-TW

测试apache是否支持php 进入apache网页根目录,创建一个php文件,查看是否执行 [root@boos htdocs]# pwd /usr/local/apache2/htdocs

[root@boos htdocs]# vim index.php [root@boos htdocs]# cat index.php [root@boos htdocs]# cat index.php 晚上9点

启动apache 拷贝apache默认提供的一个脚本即可,就是启动apache的命令

[root@boos htdocs]# cp /usr/local/apache2/bin/apachectl /etc/init.d/apache

[root@boos htdocs]# netstat -tnlp |grep 80 [root@boos htdocs]# [root@boos htdocs]# service apache start

[root@boos htdocs]# netstat -tnlp|grep 80 tcp6 0 0 :::80 ::😗 LISTEN 22593/httpd

完成wrodpress博客部署

下载码 [root@boos source-code]# wget -c https://cn.wordpress.org/wordpress-4.7.3-zh_CN.tar.gz

创建目录,保存wordpress的代码 以及解压缩源码,全部拷贝到该目录中

[root@boos source-code]# mkdir -p /www/yuchao-blog [root@boos source-code]# tar -zxf wordpress-4.7.3-zh_CN.tar.gz [root@boos source-code]# cp -a wordpress/* /www/yuchao-blog/

更改wordpress源码属主属组 [root@boos source-code]# chown -R daemon.daemon /www/yuchao-blog/

准备网站上线发布(给apache添加一个新配置文件,专门发布我们这个wordpress)虚拟主机

[root@boos source-code]# vim /usr/local/apache2/conf/httpd.conf 492 # Virtual hosts 493 Include conf/extra/httpd-vhosts.conf

修改该虚拟主机配置文件,添加关于wordpress的配置信息 [root@boos source-code]# ls -l /usr/local/apache2/conf/extra/httpd-vhosts.conf -rw-r--r-- 1 root root 1467 Apr 1 19:50 /usr/local/apache2/conf/extra/httpd-vhosts.conf

此时可以修改mysql的密码,用如下命令,注意语法

-u -p参数后面不得有空格,是直接跟上用户名或者密码的

-p 不写密码的话,会让你交互式输入密码

password 跟上你的新的mysql密码

[root@boos Software-mysql]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 3 Server version: 5.6.50 Source distribution

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

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

mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec)

创建wordpress数据库 mysql> create database wordpress default charset utf8; Query OK, 1 row affected (0.05 sec)

mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | | wordpress | +--------------------+ 5 rows in set (0.00 sec)

修改apache配置,添加可访问权限 [root@boos source-code]# vim /usr/local/apache2/conf/httpd.conf

修改这里Require all denied 默认拒绝所有,改为Require all granted

脚本宝典总结

以上是脚本宝典为你收集整理的linux搭建LAMP全部内容,希望文章能够帮你解决linux搭建LAMP所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。