源码编译搭建LAMP
发布日期:2021-08-11 20:02:36 浏览次数:2 分类:技术文章

本文共 15389 字,大约阅读时间需要 51 分钟。

 

环境版本信息:

RHEL 5.3

Apache / 2.4.16

PHP / 5.4.45

mysql-5.5.45

 

源代码编译 安装方式

1: configure 配置 以及定制我们的软件包

2: make 把源代码包中的源代码 编译成 链接文件 目标文件 .0 Object

3:  make install   安装到 我们configure制定的目录中去

 

一、关闭有可能会影响到访问的一些限制的服务:

1、暂时清空防火墙: iptables -F

2、关闭selinux:

vim /etc/selinux/config

SELINUX=disabled

或:

setenforce 0

3、关闭:NetworkManager

    service NetworkManager stop

主配置文件, 服务器的启动脚本 记得给+x

[apache安装配置]

 1、下载地址

  (linux端下载地址)

http://httpd.apache.org/download.cgi (官网)

httpd-2.4.16.tar.gz

2、配置环境

安装:gcc gcc-c++ openssl

3、上传源码包

一般上传到OPT目录:

cd  /opt/apache/httpd-2.4.16

rz –aeb httpd-2.4.16.tar.gz

解压:tar –zxvf httpd-2.4.16.tar.gz

4、新建安装目录

mkdir  /usr/local/apache2

5、编译(在解压目录下):

./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite --enable-ssl --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util

 

配置参数用途:

--prefix=/usr/local/apache2   #指定安装路径

--enable-so  # 支持动态加载模块

--enable-rewrite  #支持网站地址重写

--enable-ssl  # 支持ssl加密

--with指的是安装本文件所依赖的库文件

 

报错:--缺少ARP

configure: error: APR not found.

APR(Apache portable Run-time libraries,Apache可移植运行库)的目的如其名称一样,主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库。在早期的Apache版本中,应用程序本身必须能够处理各种具体操作系统平台的细节,并针对不同的平台调用不同的处理函数。随着Apache的进一步开发,Apache组织决定将这些通用的函数独立出来并发展成为一个新的项目。这样,APR的开发就从Apache中独立出来,Apache仅仅是使用APR而已。

解决方法:配置三个模块来解决

./configure --prefix=/usr/local/apr

make

make install

./configure --prefix=/usr/local/apr-util

--with-apr=/usr/local/apr/bin/apr-1-config

make

make install

 Apache 正则表达式

./configure --prefix=/usr/local/pcre

make

make install

 

 

重新编译apache

make clean

./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite --enable-ssl --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util

 

报错:configure: error: pcre-config for libpcre not found. PCRE is required and available from

 

原因:apche编译时没有加上pcre

据说是缺带有devel的开发包,需要编译环境才需要安装。所以我装apache的时候需要的是开发包,而不是已经装好的库。

再次重新编译:

make clean

./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite --enable-ssl --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre/

 报错:checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures

解决方法:

安装openssl-devel:yum install openssl-devel

 

make

make install

6、软连接 -> 配置文件 页面路径

ln -s /usr/local/apache2/ /etc/apache2

ln -s /usr/local/apache2/htdocs/ /var/www/apache2

 

7、启动脚本部署

放到/etc/init.d目录下

cp /usr/local/apache2/bin/apachectl /etc/init.d/

查看本机是否存在其他 http 服务,有则关闭且禁止之

8、加入服务

/etc/init.d/apachectl 加入2个注释行

[root@xuegod-su01 httpd-2.4.16]# vim /etc/init.d/apachectl

#!/bin/sh

#

# chkconfig: 2345 64 36   # 2345 系统级别下启动这个服务  ,64 启动顺序 , 36 关闭顺序

# description: Activates/Deactivates all network interfaces configured to \

 

chkconfig --add apachectl  #加入服务

chkconfig  --list apachectl  #查看服务状态

/etc/init.d/apachectl start  #启动服务

[root@localhost ~]# netstat -tnlp | grep httpd  #查看服务端口

tcp        0      0 :::80                       :::*                        LISTEN      20683/httpd

 

[Mysql安装部署]

1、     下载

  下载地址:

  mysql-5.5.45.tar.gz:

  cmake-3.1.3-Linux-i386.tar.gz:

  上传到opt目录:rz -aeb

2、     安装cmake(cmake 相当于的./configure)

a)   解压

[root@localhost opt]#tar -zxvf cmake-3.1.3-Linux-i386.tar.gz

[root@localhost opt]# cd /opt/cmake-3.1.3-Linux-i386

b)   创建cmake的bin目录到/usr/bin目录下:

[root@localhost cmake-3.1.3-Linux-i386]# ln -s /opt/cmake-3.1.3-Linux-i386/bin/* /usr/bin/

[root@localhost cmake-3.1.3-Linux-i386]# cmake --version

cmake version 3.1.3

3、     创建mysql用户

a)   删除原来的mysql用户

userdel mysql

cat /etc/passwd

cat /etc/group

4、     添加新的mysql用户

useradd -s /sbin/nologin -m mysql /home/mysql

-s:指定用户登陆时使用的shell

/sbin/nologin:nologin就是登陆不了

-m:创建家目录

5、     创建mysql安装目录及数据目录

mkdir /usr/local/mysql-5.5  #安装目录

mkdir /usr/local/mysql/data   #数据目录

6、     编译&执行安装

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.5 \

-DMYSQL_UNIX_ADDR=/usr/local/mysql-5.5/mysql.sock \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_EXTRA_CHARSETS=all \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_MEMORY_STORAGE_ENGINE=1 \

-DMYSQL_DATADIR=/usr/local/mysql/data \

-DMYSQL_USER=mysql

 

以上参数等说明:

DCMAKE_INSTALL_PREFIX=/usr/local/mysql # mysql安装的主目录,默认为/usr/local/mysql

DMYSQL_DATADIR=/usr/local/mysql/data # mysql数据库文件的存放目录,可以自定义

DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock # 系统Socket文件(.sock)设置,基于该文件路径进行Socket链接,必须为绝对路径

DSYSCONFDIR=/etc # mysql配置文件 my.cnf的存放地址,默认为/etc下

DMYSQL_TCP_PORT=3306 # 数据库服务器监听端口,默认为3306

DENABLED_LOCAL_INFILE=1 # 允许从本地导入数据

DWITH_READLINE=1 # 快捷键功能

DWITH_SSL=yes # 支持 SSL

DMYSQL_USER=mysql # 默认为mysql

下面3个是数据库编码设置

DEXTRA_CHARSETS=all # 安装所有扩展字符集,默认为all

DDEFAULT_CHARSET=utf8 # 使用 utf8 字符

DDEFAULT_COLLATION=utf8_general_ci # 校验字符

下面5个是数据库存储引擎设在

DWITH_MYISAM_STORAGE_ENGINE=1 # 安装 myisam 存储引擎

DWITH_INNOBASE_STORAGE_ENGINE=1 # 安装 innodb 存储引擎

DWITH_ARCHIVE_STORAGE_ENGINE=1 # 安装 archive 存储引擎

DWITH_BLACKHOLE_STORAGE_ENGINE=1 # 安装 blackhole 存储引擎

DWITH_PARTITION_STORAGE_ENGINE=1 # 安装数据库分区

 

报错:

Curses library not found.  Please install appropriate package

解决方法:

1、先安装 ncurses-devel 包:yum install ncurses-devel

2、再删除刚才编译生成的 CMakeCache.txt 文件:rm CMakeCache.txt

3、再次执行一次cmake ..

编译完成:

CMake Warning:

  Manually-specified variables were not used by the project:

    MYSQL_USER

    WITH_MEMORY_STORAGE_ENGINE

-- Build files have been written to: /opt/mysql/mysql-5.5.45

执行安装:

make

make install

7、     配置文件

a)   给mysql用户配置权限

chown -R mysql:mysql /usr/local/mysql-5.5/

b)   配置配置文件

  1.         i.      放到etc目录下:

cp -vf /usr/local/mysql-5.5/support-files/my-large.cnf /etc/my.cnf   # 选择默认 配置文件 适合大型服务器

  1.        ii.      修改配置文件:

[root@localhost ~]# vi /etc/my.cnf

在[mysqld]下面添加

basedir = /usr/local/mysql-5.5

datadir = /usr/local/mysql/data

log-error = /usr/local/mysql-5.5/mysql_error.log

pid-file = /usr/local/mysql-5.5/data/mysql.pid

default-storage-engine=MyISAM(或INNODB)

user = mysql

c)   配置启动文件

  1.         i.      放到/etc/init.d目录下:

cp -vf /usr/local/mysql-5.5/support-files/mysql.server /etc/init.d/mysqld

  1.        ii.      修改启动文件

chmod +x /etc/init.d/mysqld #可执行权限

vim /etc/init.d/mysqld #在启动文件中添加以下两行:

basedir=/usr/local/mysql-5.5

datadir=/usr/local/mysql/data

8、     添加服务

[root@localhost local]# chkconfig --add mysqld

[root@localhost local]# chkconfig --list mysqld

mysqld5.5          0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭

9、     初始化数据库

cd /usr/local/mysql-5.5/scripts/

chmod +x mysql_install_db

/usr/local/mysql-5.5/scripts/mysql_install_db \

--defaults-file=/etc/my.cnf \

--basedir=/usr/local/mysql-5.5 \

--datadir=/usr/local/mysql/data \

--user=mysql

执行信息如下:

[root@localhost mysql-5.5]# /usr/local/mysql-5.5/scripts/mysql_install_db \

--defaults-file=/etc/my.cnf \

--basedir=/usr/local/mysql-5.5 \

--datadir=/usr/local/mysql/data \

--user=mysql

Installing MySQL system tables...

150810 15:48:14 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.

150810 15:48:14 [Note] /usr/local/mysql-5.5/bin/mysqld (mysqld 5.5.45-log) starting as process 29059 ...

OK

Filling help tables...

150810 15:48:17 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.

150810 15:48:17 [Note] /usr/local/mysql-5.5/bin/mysqld (mysqld 5.5.45-log) starting as process 29065 ...

OK #初始化成功

以下为提示信息:

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:

/usr/local/mysql-5.5/bin/mysqladmin -u root password 'new-password' #修改mysql的root用户密码

/usr/local/mysql-5.5/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:

/usr/local/mysql-5.5/bin/mysql_secure_installation

which will also give you the option of removing the test

databases and anonymous user created by default.  This is

strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

cd /usr/local/mysql-5.5 ; /usr/local/mysql-5.5/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

cd /usr/local/mysql-5.5/mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

启动:/etc/init.d/mysqld start

 

修改mysql的root用户密码:

/usr/local/mysql-5.5/bin/mysqladmin -u root password '123456'

 

遇到问题:

1、启动报错:

[root@localhost mysql-5.5]# service mysqld start

Starting MySQL.........The server quit without updating PID file (/usr/local/mysql-5.5/data/mysql.pid).                                      [失败]

[root@localhost mysql-5.5]# ll /usr/local/mysql-5.5/data/  #没有mysql.pid文件

总计 4

drwxr-xr-x 2 root root 4096 08-14 08:48 test

解决方法:改变mysql编译安装目录的权限: chown -R mysql:mysql /usr/local/mysql-5.5

2、通过navicat连接mysql服务时,拒绝连接。

解决方法:

登录mysql:

[root@iZ94li13q29Z bin]# ./mysql -u root -p

Enter password:

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; 任何主机使用账号root及密码连接到mysql服务器

Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH   PRIVILEGES;  #修改生效

Query OK, 0 rows affected (0.00 sec)

mysql> exit;

Bye

Navicat重新连接成功。

 

[PHP的安装部署]

1、     下载:php-5.4.45.tar.gz 并上传到opt目录

2、     创建安装目录

mkdir /usr/local/php  #创建安装目录

3、     解压

tar –zxvf php-5.4.45.tar.gz

cd /opt/php-5.4.45  #进入解压文件目录

4、编译:

./configure  --prefix=/usr/local/php --with-mysql=/usr/local/mysql-5.5  --with-apxs2=/usr/local/apache2/bin/apxs --without-pear  

 

报错:

configure: error: xml2-config not found. Please check your libxml2 installation.

解决方法:

  1、查看libxml2、libxml2-devel包是否安装:    

[root@iZ94li13q29Z ~]# rpm -qa libxml2

libxml2-2.7.6-20.el6_7.1.x86_64(libxml2包已安装)

[root@iZ94li13q29Z ~]# rpm -ql libxml2-devel

package libxml2-devel is not installed

  2、安装libxml2-devel包

[root@iZ94li13q29Z ~]# yum install libxml2-devel

 

make

报错:

PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.

 

make install

解决方法:安装pear

  在php安装目录下创建pear文件夹:mkdir /usr/local/php/pear

  在pear目录下下载pear: $wget  

   改名为p:mv  p

  运行:  

[root@iZ94li13q29Z pear]# php go-pear.php

Below is a suggested file layout for your new PEAR installation. To

change individual locations, type the number in front of the
directory. Type 'all' to change all of them or simply press Enter to
accept these locations.

1. Installation base ($prefix) : /usr/local

2. Temporary directory for processing : /tmp/pear/install
3. Temporary directory for downloads : /tmp/pear/install
4. Binaries directory : /usr/local/bin
5. PHP code directory ($php_dir) : /usr/local/lib/php
6. Documentation directory : /usr/local/docs
7. Data directory : /usr/local/data
8. User-modifiable configuration files directory : /usr/local/cfg
9. Public Web Files directory : /usr/local/www
10. System manual pages directory : /usr/local/man
11. Tests directory : /usr/local/tests
12. Name of configuration file : /usr/local/etc/pear.conf

1-12, 'all' or Enter to continue:

Beginning install...
Configuration written to /usr/local/etc/pear.conf...
Initialized registry...
Preparing to install...
installing phar:///usr/local/php/pear/go-pear.php/PEAR/go-pear-tarballs/Archive_Tar-1.4.0.tar...
installing phar:///usr/local/php/pear/go-pear.php/PEAR/go-pear-tarballs/Console_Getopt-1.4.1.tar...
installing phar:///usr/local/php/pear/go-pear.php/PEAR/go-pear-tarballs/PEAR-1.10.1.tar...
installing phar:///usr/local/php/pear/go-pear.php/PEAR/go-pear-tarballs/Structures_Graph-1.1.1.tar...
installing phar:///usr/local/php/pear/go-pear.php/PEAR/go-pear-tarballs/XML_Util-1.3.0.tar...
install ok: channel://pear.php.net/Archive_Tar-1.4.0
install ok: channel://pear.php.net/Console_Getopt-1.4.1
install ok: channel://pear.php.net/Structures_Graph-1.1.1
install ok: channel://pear.php.net/XML_Util-1.3.0
install ok: channel://pear.php.net/PEAR-1.10.1
PEAR: Optional feature webinstaller available (PEAR's web-based installer)
PEAR: Optional feature gtkinstaller available (PEAR's PHP-GTK-based installer)
PEAR: Optional feature gtk2installer available (PEAR's PHP-GTK2-based installer)
PEAR: To install optional features use "pear install pear/PEAR#featurename"

The 'pear' command is now at your service at /usr/local/bin/pear

** The 'pear' command is not currently in your PATH, so you need to

** use '/usr/local/bin/pear' until you have added
** '/usr/local/bin' to your PATH environment variable.

Run it without parameters to see the available actions, try 'pear list'

to see what packages are installed, or 'pear help' for help.

For more information about PEAR, see:

http://pear.php.net/faq.php

http://pear.php.net/manual/

Thanks for using go-pear!

安装完成:

[root@iZ94li13q29Z php-5.5.30]# make install

Installing PHP SAPI module: apache2handler
/usr/local/apache/build/instdso.sh SH_LIBTOOL='/usr/local/apr/build-1/libtool' libphp5.la /usr/local/apache/modules
/usr/local/apr/build-1/libtool --mode=install install libphp5.la /usr/local/apache/modules/
libtool: install: install .libs/libphp5.so /usr/local/apache/modules/libphp5.so
libtool: install: install .libs/libphp5.lai /usr/local/apache/modules/libphp5.la
libtool: install: warning: remember to run `libtool --finish /opt/php-5.5.30/libs'
chmod 755 /usr/local/apache/modules/libphp5.so
[activating module `php5' in /usr/local/apache/conf/httpd.conf]
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20121212/
Installing PHP CLI binary: /usr/local/php/bin/
jInstalling PHP CLI man page: /usr/local/php/php/man/man1/
Installing PHP CGI binary: /usr/local/php/bin/
Installing PHP CGI man page: /usr/local/php/php/man/man1/
Installing build environment: /usr/local/php/lib/php/build/
Installing header files: /usr/local/php/include/php/
Installing helper programs: /usr/local/php/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/php/php/man/man1/
page: phpize.1
page: php-config.1
/opt/php-5.5.30/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers: /usr/local/php/include/php/ext/pdo/

 

apache启动报错

httpd: Syntax error on line 151 of /usr/local/apache/conf/httpd.conf: Cannot load modules/libphp5.so into server: /usr/local/apache/modules/libphp5.so: cannot open shared object file: No such file or directory

原因:

编译时错误:我直接复制编译命令,但configure后是换行了,导致只./configure没有带后面的参数

./configure

--prefix=/usr/local/php\ --with-mysql=/usr/local/mysql\  --with-apxs2=/usr/local/apache/bin/apxs\

解决方法:

  重新编译:

  ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache/bin/apxs\

 

5、把配置文件复制到安装目录

cp /opt/php-5.4.45/php.ini-production /usr/local/php/php.ini

6、配置apache关联php(让apache 知道php的存在)

vi /usr/local/apache2/conf/httpd.conf

加上以下三行:

LoadModule php5_module      modules/libphp5.so

(注意 下面的必须加上 并且语法一定要对其)
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

DirectoryIndex  index.html 加上index.php 

7、测试访问php页面

[root@xuegod63 Desktop]# cd /usr/local/apache2/htdocs/   # htdocs apache 页面路径

[root@xuegod63 htdocs]# mv index.html index.html.back

[root@xuegod63 htdocs]# vim index.php

内容改为以下:

<?php

phpinfo();

?>

[root@xuegod63 htdocs]# /etc/init.d/apachectl stop

[root@xuegod63 htdocs]# /etc/init.d/apachectl start

在浏览器访问:

打开php信息页面,成功

 

 

搭建wordpress遇到问题:

访问wordpress前台首页提示:网页过多重定向

可能原因:.htaccess文件无法上传服务器

发现.htaccess其实已经上传,是隐形文件

解决方法:

一、加载apache重定向模块,操作如下:

1、#LoadModule rewrite_module modules/mod_rewrite.so这句去掉注释

 

2、AllowOverride None改为AllowOverride All

 

虚拟机的设置如下:

<VirtualHost *:80>

    ServerName 10.118.71.2:80

    DocumentRoot "/usr/local/apache2/htdocs"

    <Directory "/usr/local/apache2/htdocs">

        Options Indexes FollowSymLinks

        AllowOverride All

        Require all granted

    </Directory>

</VirtualHost>

 

二、找到wp-include文件夹下的template-loader.php文件,使用/**代码**/注释掉第六行和第七行。

1    if ( defined('WP_USE_THEMES') && WP_USE_THEMES )   

2    do_action('template_redirect');

 

重启服务 OK

转载于:https://www.cnblogs.com/wnfindbug/p/4834247.html

转载地址:https://blog.csdn.net/weixin_30633949/article/details/97062111 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:virsh使用
下一篇:nacicat premium 快捷键

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2024年04月22日 22时34分06秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章