LAMP-CentOS 7-环境搭建笔记

1、apache安装部署

官网:http://httpd.apache.org/

文档:http://httpd.apache.org/docs/2.4/

源码包:apache-2.4.20 http://mirrors.noc.im/apache//httpd/httpd-2.4.20.tar.gz

下载依赖包:

wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz                            //如果没有wget命令  安装:        # yum -y install wget

wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz

wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.39/pcre-8.39.tar.gz

解压依赖包:

tar -xzvf apr-1.4.5.tar.gz

tar -xzvf apr-util-1.3.12.tar.gz

pcre-8.39.tar.gz

安装apr-1.4.5

进入安装目录

安装并编译

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

make && make install

安装apr-util

进入安装目录

安装并编译

./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config

make && make install

安装pcre-8.39

进入安装目录

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

make && make install

安装apache

进入安装目录

用--with参数指定安装的依赖包

./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre

make:编译时间会比较长

make install:安装

配置文件:conf/httpd.conf

启动:./apachectl -k start

安全停止:./apachectl -k graceful-stop

立刻停止:./apachectl -k stop

安全重启:./apachectl -k graceful

立刻重启:./apachectl -k restart

问题记录:

问题:AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message

解决:进入apache安装目录、编辑httpd.conf文件,搜索"#ServerName",添加ServerName localhost:8080

# vi httpd.conf

#ServerName www.example.com:80

ServerName localhost:80

相应位置端口修改80,再重新启动apache 即可。

# /usr/local/apache/bin/apachectl -k restart

LAMP-CentOS 7-环境搭建笔记_第1张图片

检验安装结果,本机浏览器打开     127.0.0.1:80    远程浏览器打开    ip:80    显示下方内容,到此配置部署成功!

2.mysql安装部署

检查安装支持包yum -y install make gcc-c++ cmake bison-devel  ncurses-devel

下载mysql57-community-release-el7-11.noarch.rpm

# yum localinstall mysql57-community-release-el7-11.noarch.rpm

# y

# yum install mysql-server              //安装mysql-server

# systemctl start mysqld.service        //启动mysql服务

# vim /var/log/mysqld.log                      //找到mysql登录密码,可直接到下一步

# grep 'password' /var/log/mysqld.log

# mysql -uroot -p**********                   //***********是上一步找到的登录密码

mysql> alter user 'root'@'localhost' identified by '12345678'          //修改mysql密码,如果提示密码不符合,设置复杂密码即可

mysql> quit                              //退出 mysql

mysql 3306端口

mysql安装后默认是localhost访问,如果需要外部访问可以设置一个新的账号把host改为%,意味着所有ip均可以访问

grant all privilegeson*.* to'outUser'@'%'identifiedby'12'with grant option

然后

flush privileges;

就可以使用outUser账户密码12来外部访问,有的时候无法访问需要打开防火墙开放端口

centos 7 中使用的是firewall-cmd命令

# firewall-cmd --list-all-zones    #查看所有的zone信息

# firewall-cmd --get-default-zone     #查看默认zone是哪一个

# firewall-cmd --zone=internal --change-zone=p3p1  #临时修改接口p3p1所属的zone为internal

# firewall-cmd --add-service=http    #暂时开放http

# firewall-cmd --permanent --add-service=http  #永久开放http

# firewall-cmd --zone=public --add-port=80/tcp --permanent  #在public中永久开放80端口

# firewall-cmd --permanent --zone=public --remove-service=ssh   #从public zone中移除服务

# firewall-cmd --reload   #重新加载配置

打开3306端口

firewall-cmd --add-port=3306/tcp --permanent

ok

LAMP-CentOS 7-环境搭建笔记_第2张图片

3、php安装

依赖包要先安装上

php-mcrypt libmcrypt libmcrypt-devel  autoconf  freetype gd jpegsrc libmcrypt libpng libpng-devel libjpeg libxml2 libxml2-devel zlib curl curl-devel

下载安装包          wget http://au1.php.net/distributions/php-7.0.18.tar.gz

进入解压安装包

# ./configure --enable-fpm --with-pdo-mysql --with-apxs2=/usr/local/apache/bin/apxs

*** 注: 在configure过程中, 可能会遇到下面的错误! Sorry, I cannot run apxs. ***

Sorry, I cannot run apxs. Possible reasons follow:

1. Perl is not installed

2. apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs

3. Apache was not built using --enable-so (the apxs usage page is displayed)

configure: error: Sorry, I cannot run apxs. Either you need to install Perl or you need to pass the absolute path of apxs by using --with-apxs=/absolute/path/to/apxs

解决方案:直接运行"/usr/local/apache/bin/apxs"这个脚本, 得到下面的错误提示:

bash: ./apxs: /replace/with/path/to/perl/interpreter: bad interpreter: No such file or directory

感觉是apxs程序有问题, 但问题在哪里呢? "interpreter"是什么呢? interpreter是"解释程序"!

运行"head -1 /usr/local/apache/bin/apxs"得到下面内容:

#!/replace/with/path/to/perl/interpreter -w

这里没有指明正确的perl执行程序的位置! 原来这就才是真正的问题原因所在!!!

打开apxs文件把这一行更改为"#!/usr/bin/perl -w". 再运行php的configure, 一切正常!


配置完成

# make 编译完成Build complete  “Do you want to send this report now?[Yns]:n”

# make install安装

/*****      以下安装记录

[root@localhost php-7.0.18]# make install

Installing PHP SAPI module:      apache2handler

/usr/local/apache/build/instdso.sh SH_LIBTOOL='/usr/local/apr/build-1/libtool' libphp7.la /usr/local/apache/modules

/usr/local/apr/build-1/libtool --mode=install install libphp7.la /usr/local/apache/modules/

install .libs/libphp7.so /usr/local/apache/modules/libphp7.so

install .libs/libphp7.lai /usr/local/apache/modules/libphp7.la

libtool: install: warning: remember to run `libtool --finish /tmp/soft/php-7.0.18/libs'

chmod 755 /usr/local/apache/modules/libphp7.so

[activating module `php7' in /usr/local/apache/conf/httpd.conf]

Installing shared extensions:    /usr/local/lib/php/extensions/no-debug-zts-20151012/

Installing PHP CLI binary:        /usr/local/bin/

Installing PHP CLI man page:      /usr/local/php/man/man1/

Installing PHP FPM binary:        /usr/local/sbin/

Installing PHP FPM defconfig:    /usr/local/etc/

Installing PHP FPM man page:      /usr/local/php/man/man8/

Installing PHP FPM status page:  /usr/local/php/php/fpm/

Installing phpdbg binary:        /usr/local/bin/

Installing phpdbg man page:      /usr/local/php/man/man1/

Installing PHP CGI binary:        /usr/local/bin/

Installing PHP CGI man page:      /usr/local/php/man/man1/

Installing build environment:    /usr/local/lib/php/build/

Installing header files:          /usr/local/include/php/

Installing helper programs:      /usr/local/bin/

program: phpize

program: php-config

Installing man pages:            /usr/local/php/man/man1/

page: phpize.1

page: php-config.1

Installing PEAR environment:      /usr/local/lib/php/

[PEAR] Archive_Tar    - installed: 1.4.2

[PEAR] Console_Getopt - installed: 1.4.1

[PEAR] Structures_Graph- installed: 1.1.1

[PEAR] XML_Util      - installed: 1.4.2

[PEAR] PEAR          - installed: 1.10.3

Wrote PEAR system config file at: /usr/local/etc/pear.conf

You may want to add: /usr/local/lib/php to your php.ini include_path

/tmp/soft/php-7.0.18/build/shtool install -c ext/phar/phar.phar /usr/local/bin

ln -s -f phar.phar /usr/local/bin/phar

Installing PDO headers:          /usr/local/include/php/ext/pdo/

******/   以上安装记录

安装完成

部署php

进入php安装解压包

# cp php.ini-development /usr/local/php/php.ini

# cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf

# vim /usr/local/etc/php-fpm.conf

最后一行改为

include=/usr/local/etc/php-fpm.d/*.conf

:wq保存退出

# cp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/php-fpm.conf

# cp sapi/fpm/php-fpm /usr/local/bin(php之前版本需要)

# vim /usr/local/php/php.ini      后面路径改为:/usr/local/lib/php.ini

cgi.fix_pathinfo=0(找到这一行修改)

# vim /usr/local/etc/php-fpm.d/php-fpm.conf

user = nobody

group = nobody

listen = 127.0.0.1:9000

启动服务

# cd /usr/local/bin

# php-fpm(启动)

# ps aux | grep php-fpm(查看进程,是否启动)

# kill php-fpm(关闭php)

-bash: kill: php-fpm: 参数必须是进程或任务 ID

# killall php-fpm          //如果没有kill命令输入   #  yum install psmisc

# ps -aux | grep php-fpm(查看关闭结果)

root      11039  0.0  0.0 112664  968 pts/0    S+  21:10  0:00 grep --color=auto php-fpm

# php-fpm(启动)

注:如何安裝 vim 呢?

# rpm -qa|grep vim

输入rpm -qa|grep vim 命令, 如果 vim 已经正确安裝,会返回下面的三行代码:

vim-enhanced-7.4.160-7.el7

vim-minimal-7.4.160-7.el7

vim-common-7.4.160-7.el7

如果少了其中的某一条,比如 vim-enhanced 的,就用命令 yum -y install vim-enhanced 来安裝:

yum -yinstallvim-enhanced

如果上面的三条一条都沒有返回, 可以直接用 yum -y install vim* 命令

yum -y install vim*

4、apache配置php

你可能感兴趣的:(LAMP-CentOS 7-环境搭建笔记)