centos7.2 安装LAMP

目录

1. 访问ftp报错

2. 依赖软件查询

一.安装gcc

二.安装zlib压缩库

三.安装apache

四.安装libxml2

五.安装jpeg8

六.安装libpng

七.安装freetype(字体库)

八.安装GD库

扫描二维码关注公众号,回复: 4845520 查看本文章

九.curl 安装

十.安装 php5

十一 安装MySQL

1.安装cmake(更先进的configure)

2.编译安装MySQL

3.配置并初始化MySQL

Apache 开机自动启动

十二.卸载操作系统自带apache


--查看系统位数命令(64位还是32位)

getconf LONG_BIT

虚拟机网络设置

桥接模式:相当于局域网中一台独立的主机.

NAT模式:依赖于主机之上, 数据通过主机网络来与虚拟网络进行通信.

配置网上命令

vi /etc/sysconfig/network-scripts/ifcfg-eth0
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.1.160
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=202.96.134.33
DNS2=114.114.144.144

--重启网络配置

service network restart

  或者 

systemctl restart network

1. 访问ftp报错

解决:

关闭selinux

vi  /etc/selinux/config

内容修改为:   selinux=disable

之后重启reboot

 

2. 依赖软件查询

查找与下载

http://rpmfind.net 

一.安装gcc

安装网络工具
yum install net-tools
yum install gcc
(更新)
yum -y update gcc  
yum -y install gcc gcc-c++

----------------------------------------------------------------------------------

gcc

    cloog-ppl

       ppl(libppl.so.7/libppl_c.so.2)

    cpp

mpfr(libmpfr.so.1)

gcc-c++

    libstdc++-devel

mpfr-2.4.1-6.el6.i686.rpm和ppl-0.10.2-11.el6.i686.rpm

快捷键rz  sz:

rz、sz命令没找到?

安装lrzsz即可:

shell># yum -y install lrzsz

 

二.安装zlib压缩库

shell>## cd /home/alexruo/tar

shell># tar –zxvf zlib-1.2.5.tar.gz

shell># cd zlib-1.2.5

shell># ./configure //这个配置编译命令不要加目录参数[注意如果是系统是64 #CFLAGS="-O3 -fPIC" ./configure //使用64位元的方法进行编译 ]

shell># make && make install

CFLAGS="-O3 -fPIC" ./configure && make && make install

三.安装apache

------------------------------------------------------------------------------------------------

编译apache时出错:

#./configure --prefix……检查编辑环境时出现:

checking for APR... no

configure: error: APR not found .  Please read the documentation

解决办法:

1.下载所需软件包:

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

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

    wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.zip  

2.编译安装:

    yum remove apr-util-devel apr apr-util-mysql apr-docs apr-devel apr-util apr-util-docs

具体步骤如下:

  a:解决apr not found问题>>>>>>

    [root@xt test]# tar -zxf apr-1.4.5.tar.gz 

    [root@xt test]# cd  apr-1.4.5 

    [root@xt apr-1.4.5]# ./configure --prefix=/usr/local/apr 

    [root@xt apr-1.4.5]# make && make install 

  b:解决APR-util not found问题>>>>

    [root@xt test]# tar -zxf apr-util-1.3.12.tar.gz 

    [root@xt test]# cd apr-util-1.3.12 

    [root@xt apr-util-1.3.12]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config 

    [root@xt apr-util-1.3.12]# make && make install

  c:解决pcre问题>>>>>>>>>

    [root@xt test]#unzip -o pcre-8.10.zip 

    [root@xt test]#cd pcre-8.10 

    [root@xt pcre-8.10]#./configure --prefix=/usr/local/pcre 

    [root@xt pcre-8.10]#make && make install

4.最后编译Apache时加上:

--with-apr=/usr/local/apr \

--with-apr-util=/usr/local/apr-util/ \

--with-pcre=/usr/local/pcre

成功编译完成~

①
./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
③
./configure --prefix=/usr/local/pcre && make && make install 

------------------------------------------------------------------------------------------------

shell># cd /home/alexruo/tar

shell># tar -jxvf httpd-2.2.19.tar.bz2

shell># cd httpd-2.2.19

 shell>#./configure --prefix=/usr/local/web  \

       --enable-modules=all \

       --enable-mods-shared=all \

       --enable-so

shell># make && make install

configure: error: APR not found.  Please read the documentation.

./configure --prefix=/usr/local/php \
--with-apxs2=/usr/local/web/bin/apxs \
--with-mysql=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-freetype-dir=/usr/local/freetype \
--with-gd=/usr/local/gd \
--with-zlib \
--with-libxml-dir=/usr/local/libxml2 \
--with-jpeg-dir=/usr/local/jpeg \
--with-png-dir \
--with-curl=/usr/local/curl \
--enable-mbstring=all \
--enable-mbregex \
--enable-shared && make && make install

启动Apache

shell># /usr/local/web/bin/apachectl start/stop/restart

/usr/local/web/bin/apachectl start 

#测试apache

浏览器打开: http://虚拟机IP

看到 "it works!",即为成功

 

配置虚拟主机

1)配置host文件

打开C:/windows/system32/drivers/etc/hosts 文件

增加域名记录

如:

192.168.9.38       www.ec1.com

192.168.9.38       www.ec2.com

2) 增加虚拟主机

vi /usr/local/web/conf/httpd.conf

取消#  Include conf/extra/httpd-vhosts.conf

这一行前面的#号

保存退出

vi /usr/local/web/conf/extra/httpd-vhosts.conf

增加虚拟主机记录

<VirtualHost *:80>

    ServerAdmin [email protected]

    DocumentRoot "/usr/local/web/htdocs/ec1"

    ServerName www.ec1.com

    ServerAlias www.dummy-host.example.com

    ErrorLog "logs/dummy-host.example.com-error_log"

    CustomLog "logs/dummy-host.example.com-access_log" common

</VirtualHost>

<VirtualHost *:80>

    ServerAdmin [email protected]

                DocumentRoot "/usr/local/web/htdocs/ec2"

    ServerName www.ec2.com

    ErrorLog "logs/dummy-host2.example.com-error_log"

    CustomLog "logs/dummy-host2.example.com-access_log" common

</VirtualHost>

<VirtualHost *:80>

                DocumentRoot "/var/www/shop"

    ServerName www.ec1.com

</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/web/apache/htdocs/aaa.com/"
    ServerName www.aaa.com
    DirectoryIndex my.html index.html index.htm index.php
</VirtualHost>

注意:/var/www/shop  以上三个目录var  www  shop 的其他用户必须有x可执行权限

3)

       shell># cd /usr/local/web/htdocs

        shell># mkdir ec1 ec2

       shell># echo this is ec1.com > ec1/index.html

       shell># echo this is ec2.com > ec2/index.html

4)重启apache

/usr/local/web/bin/apachectl restart

5)浏览器打开www.ec1.com,和www.ec2.com

看到不同的网站内容,虚拟主机创建完毕!

安装图形库,为编译PHP做准备

libxml2-2.7.2.tar.gz

jpegsrc.v8b.tar.gz

libpng-1.4.3.tar.gz     

freetype-2.4.1.tar.gz

gd-2.0.35.tar.gz

 

四.安装libxml2

shell># cd /home/alexruo/tar

shell># tar zxvf libxml2-2.7.2.tar.gz

shell># cd libxml2-2.7.2

shell>#./configure --prefix=/usr/local/libxml2  \

--without-zlib

shell># make && make install

./configure --prefix=/usr/local/libxml2  --without-zlib && make && make install 

五.安装jpeg8

shell># cd /home/alexruo/tar

shell># tar -zxvf jpegsrc.v8b.tar.gz

shell># cd jpeg-8b

shell>#./configure --prefix=/usr/local/jpeg \

--enable-shared --enable-static

shell># make && make install

--enable-shared  把jpeg需要的函数库程序都编译到该软件里边

                  优点:函数调用速度快

                              缺点:软件本身比较大

--enable-static   静态方式函数处理,需要什么函数,马上include来

              优点:软件本身比较小

              缺点:函数调用速度慢

./configure --prefix=/usr/local/jpeg --enable-shared --enable-static && make && make install

六.安装libpng

shell># cd /home/alexruo/tar

shell># tar zxvf libpng-1.4.3.tar.gz

shell># cd libpng-1.4.3

shell>#./configure  #和zlib一样不要带参数,让它默认安装到相应目录

shell># make && make install

./configure && make && make install

七.安装freetype(字体库)

shell># cd /home/alexruo/tar

shell># tar zxvf freetype-2.4.1.tar.gz

shell># cd freetype-2.4.1

shell>#./configure --prefix=/usr/local/freetype

shell># make && make install

 

mkdir  -p  /usr/local/freetype/include/freetype2/freetype/internal 

mkdir  -p  /usr/local/freetype/include/freetype2/freetype/internal 
./configure --prefix=/usr/local/freetype && make && make install

八.安装GD库

shell># cd /home/alexruo/tar

shell># tar -zvxf gd-2.0.35.tar.gz

shell># mkdir -p /usr/local/gd

shell># cd gd-2.0.35

shell>#./configure --prefix=/usr/local/gd  \

           --with-jpeg=/usr/local/jpeg/    \

           --with-png --with-zlib \

           --with-freetype=/usr/local/freetype

shell># make && make install

configure: error: png requested but not found
yum install libpng-devel libpng -y

./configure --prefix=/usr/local/gd  \
--with-jpeg=/usr/local/jpeg/ 	\
--with-png --with-zlib \
--with-freetype=/usr/local/freetype && make && make install

九.curl 安装

#tar -zxvf curl-7.17.1.tar.gz

#cd curl-7.17.1.tar.gz

# ./configure --prefix=/usr/local/curl

# make

# make install

注意:

解决configure: error: OpenSSL Crypto library not found

服务器软件配置

crypto是什么呢? OpenSSL 加密库(lib), 这个库需要openssl-devel ,ubuntu中就是 libssl-dev

RedHat Fedora 平台

yum -y install openssl-devel

Debian ,ubunu 平台

apt-get install libssl-dev

yum -y install openssl-devel

./configure --prefix=/usr/local/curl && make && make install 

十.安装 php5

shell># cd /home/alexruo/tar

shell># tar -jxvf php-5.3.6.tar.bz2

shell># cd php-5.3.6

shell>#./configure --prefix=/usr/local/php \

           --with-apxs2=/usr/local/web/bin/apxs \

           --with-mysql=mysqlnd \

           --with-pdo-mysql=mysqlnd \

           --with-mysqli=mysqlnd \

           --with-freetype-dir=/usr/local/freetype \

           --with-gd=/usr/local/gd \

           --with-zlib \

--with-libxml-dir=/usr/local/libxml2 \

           --with-jpeg-dir=/usr/local/jpeg \

           --with-png-dir \

--with-curl=/usr/local/curl \

           --enable-mbstring=all \

           --enable-mbregex \

           --enable-shared

shell># make && make install

问题一:找不到apxs
The output of /usr/local/web/bin/apxs follows:
./configure: /usr/local/web/bin/apxs: /replace/with/path/to/perl/interpreter: bad interpreter: No such file or directory
configure: error: Aborting

找不到apxs
yum install -y perl* 
yum install -y httpd-devel
#find / -name apxs  得到的路径是:/usr/bin/apxs
于是修改--with-apsx2=/usr/bin/apxs指定到正确路径
 /usr/local/jpeg/include/jpeglib.h 

问题二:编译php报错xml2-config not found. Please check your libxml2 installation
yum install libxml2-devel libxml2 -y

问题三:jpeg头文件路径不正确
/usr/local/jpeg/include/jpeglib.h

编译命令:
./configure --prefix=/usr/local/php \
--with-apxs2=/usr/local/web/bin/apxs \
--with-mysql=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-freetype-dir=/usr/local/freetype \
--with-gd=/usr/local/gd \
--with-zlib \
--with-libxml-dir=/usr/local/libxml2 \
--with-jpeg-dir=/usr/local/jpeg \
--with-png-dir \
--with-curl=/usr/local/curl \
--enable-mbstring=all \
--enable-mbregex \
--enable-shared && make && make install 

复制php.ini配置文件到指定目录

shell># cp php.ini-development /usr/local/php/lib/php.ini

配置Apache使其支持php

vi /usr/local/web/conf/httpd.conf

  1. 在httpd.conf(Apache主配置文件)中增加:

AddType application/x-httpd-php .php  

  1. 找到下面这段话:

<IfModule dir_module>

    DirectoryIndex index.html

</IfModule>

在index.html 前面添加index.php

  1. 建立php测试网页

vi /usr/local/web/htdocs/index.php 

  1. 重启apache

shell># /usr/local/web/bin/apachectl restart

  1. 再次浏览器查看http://虚拟机IP

如果看到php信息,工作就完成了!

 

十一 安装MySQL

1.安装cmake(更先进的configure)

shell># cd /home/alexruo/tar

shell># tar zxvf cmake-2.8.5.tar.gz

shell># cd cmake-2.8.5

shell># ./bootstrap

shell># make && make install

2.编译安装MySQL

shell># cd /home/alexruo/tar

shell># tar zxvf mysql-5.5.17.tar.gz

shell># cd mysql-5.5.17

shell># cmake \

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

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

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci

(准备安装到那里

数据存储目录

默认的字符集

校对字符集)

(报错就安装ncurses-devel)

shell># mount .....挂载光盘/  

(或者:#yum -y install ncurses-devel  这种方式apt install libncurses5-dev)


shell># rpm -ivh ncurses-devel-5.7-3.20090208.el6.i686.rpm

shell># rm -f CMakeCache.txt    //删除该文件

shell># cmake 。。。 。。。            //重新cmake

shell># make && make install

shell># cp support-files/my-medium.cnf /etc/my.cnf

3.配置并初始化MySQL

shell># useradd  mysql   (该mysql用户会存在于同名的组下)

shell># chmod +x /usr/local/mysql

(数据库用户信息不小心删除光了,删除data目录,从此开始执行以下指令,直至结束)

shell># chown -R mysql.mysql /usr/local/mysql

初始化mysql数据库  

shell># /usr/local/mysql/scripts/mysql_install_db \

--user=mysql \

--basedir=/usr/local/mysql \

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

把mysql安装文件(除了data)的主人都改为root,避免数据库恢复为出厂设置。

shell># chown -R root /usr/local/mysql

shell># chown -R mysql /usr/local/mysql/data

& 后台运行mysql服务

shell># /usr/local/mysql/bin/mysqld_safe --user=mysql &

//查看mysql是否有启动

shell># ps –A | grep mysql   

测试数据库

#/usr/local/mysql/bin/mysql

shell># /usr/local/mysql/bin/mysql –uroot -p

mysql> show databases;  

数据库操作:

select host,user,password from user;

接上步,修改mysql密码(可不做此步,默认无密码)

mysql> UPDATE user SET Password=password('root') WHERE user='root';

mysql> flush privileges;

安装命令
 cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci && make && make install 

初始化并配置命令
添加账户及权限设置
useradd mysql
chmod +x /usr/local/mysql
chown -R mysql.mysql /usr/local/mysql 
初始化数据库
/usr/local/mysql/scripts/mysql_install_db \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data &

设置权限
chown -R root /usr/local/mysql
chown -R mysql /usr/local/mysql/data

后台启动mysql
/usr/local/mysql/bin/mysqld_safe --user=mysql &
查看是否启动
ps –A | grep mysql

登录
/usr/local/mysql/bin/mysql -uroot -p
show databases;
user mysql;
修改密码
UPDATE user SET Password=password('root') WHERE user='root';
select host,user,password from user;
刷新
flush privileges;
退出
exit;

测试安装数据

  • #/usr/local/mysql/bin/mysql -uroot -psaroot0.123;
  • mysql> show databases;
  • mysql> use test
  • mysql> create table goods;
  • mysql> insert into goods values(1,'htc'),(2,'apple'),(3,'nokia');
  • mysql> show tables;
  • mysql> select * from goods;
  • 新建一个PHP文件 ,保存,并通过URL来访问它

 <?php

$link = mysql_connect('localhost','root','szrdr00t0.123');

mysql_select_db('test',$link);

mysql_query('set names utf8');

 

$sql = "select * from goods";

$qry = mysql_query($sql);

while($rst = mysql_fetch_assoc($qry)){

   print_r($rst);

   echo "<br />";

}

得到结果 ,测试成功

 

  1. 配置开机自启动服务项

shell># cp 安装包解压目录/support-files/mysql.server /etc/init.d/mysqld

shell># chmod +x /etc/init.d/mysqld

shell># chkconfig --add mysqld

shell># chkconfig mysqld on    //设置开机自启动

 

配置文件路径:

shell># vi /etc/rc.d/rc.local

在  文件中增加启动相关服务的命令如下:

/usr/local/web/bin/apachectl start

/usr/local/mysql/bin/mysqld_safe --user=mysql &

service vsftpd start

5.p7zip安装

yum –y install p7zip  

重新安装apache启动失败

[root@localhost httpd-2.2.19]# /usr/local/web/bin/apachectl restart

httpd not running, trying to start

(98)Address already in use: make_sock: could not bind to address [::]:80

(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80

no listening sockets available, shutting down

Unable to open logs

原因是80端口被占用

解决:

查看80端口使用情况

[root@localhost httpd-2.2.19]# netstat -lnp|grep 80

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

unix  2      [ ACC ]     STREAM     LISTENING     6580   1957/gpm            /dev/gpmctl

unix  2      [ ACC ]     STREAM     LISTENING     5422   1800/pcscd          /var/run/pcscd.comm

查看80的使用者是谁端口

[root@localhost httpd-2.2.19]# ps 28195

  PID TTY      STAT   TIME COMMAND

28195 ?        Ss     0:00 /usr/local/web/bin/httpd -k restart

经过分析知道了80端口被系统的一个进程占用,这个进程是旧的apache服务

将这个进程杀之

[root@localhost httpd-2.2.19]# kill -9 28195

[root@localhost httpd-2.2.19]#

Apache 开机自动启动

源码编译的安装Apache,是不能使用service命令启动的,通常启动Apache的命令是:

# /usr/local/apache2/bin/apachectl start

其中/usr/local/apache2/bin目录下的Apachectl文件其实就是一个启动脚本,把apachectl文件copy/etc/init.d/目录下,同时重命名为apache2(名字随便取,方便记住就行)
# cp /usr/local/web/bin/apachectl /etc/init.d/apache2

然后修改apache2文件,让它能够支持servicechkconfig命令:

# vim /etc/init.d/apache2

在前面有“#”的注释的任意地方,加入下面2行:

# chkconfig: 35 20 80
# description: Apache2

说明:

  • 3个数字的意思分别是:在哪些运行级别启动apache35);启动序号(S20);关闭序号(K80)。
  • 35也就是说在第三启动级别和第五启动级别的时候会默认启动apache
  • 20就是指系统起来的时候有很多的服务需要启动,而这个程序排在第二十位启动,以此类推
  • 80就是指系统关闭的时候,这个服务顺序排在第80位关闭

注意:

  • #号不能省略

保存退出后就可以用service来启动和关闭apache
比如:
# service apache2 start(/usr/local/web/bin/apachectl restart[start])
# netstat -antp |grep 80
tcp 0 0 :::80 :::* LISTEN 13410/httpd

Apache跟随系统一起启动(开机自启动),需要把apache2加入到chkconfig就可:

# chkconfig –-add apache2
# chkconfig apache2 on

************************************************************************

十二.卸载操作系统自带apache

  1. 删除默认apache进程
  • ps –A | grep  http
  • 杀死apache对应进程

killall  httpd  杀死全部的httpd进程

  1. 把默认apache服务给删除
  2. 启动自己的apache

猜你喜欢

转载自blog.csdn.net/luofeng7788/article/details/86133569