搭建lamp环境

 

1:安装apache

[root@server1 src]# tar zxvf apr-1.5.2.tar.gz   
[root@server1 src]# cd apr-1.5.2
[root@server1 apr-1.5.2]# ./configure --prefix=/usr/local/apr
[root@server1 apr-1.5.2]# make && make install
  •  
  • 编译安装apr-util(apr-util-1.5.4.tar.gz)

下载地址: http://mirrors.cnnic.cn/apache//apr/apr-util-1.5.4.tar.gz

[root@server1 src]# tar zxvf apr-util-1.5.4.tar.gz
[root@server1 apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr    #编译安装apr-util必须指定apr的安装位置
[root@server1 apr-util-1.5.4]# make && make install
  •  
  • 编译安装pcre (pcre-8.38.tar.gz) ## 此处你也可以进行本地RPM包的安装

下载地址: https://sourceforge.net/projects/pcre/files/pcre/8.38/pcre-8.38.tar.gz/download

[root@server1 src]# tar zxvf pcre-8.38.tar.gz
[root@server1 src]# cd pcre-8.38
[root@server1 pcre-8.38]# ./configure --prefix=/usr/local/pcre
[root@server1 src]# make && make install
  •  

编译安装Apache

下载地址: http://mirrors.cnnic.cn/apache//httpd/httpd-2.4.20.tar.g

  • [root@server1 src]# tar zxvf httpd-2.4.20.tar.gz
  • [root@server1 src]# cd httpd-2.4.20
  • [root@server1 httpd-2.4.20]# ./configure \ --prefix=/usr/local/apache --sysconfdir=/etc/httpd \ --enable-so --enable-ssl --enable-cgi --enable-rewrite \ --with-zlib --with-pcre=/usr/local/pcre \ --with-apr=/usr/local/apr \ --with-apr-util=/usr/local/apr-util \ --enable-mods-shared=most --enable-mpms-shared=all \ --with-mpm=event
  • [root@server1 httpd-2.4.20]# make && make install
选项解释:
--prefix=/usr/local/apache    # 指定安装目录
--sysconfdir=/etc/httpd    # 指定配置文件安装路径
--enable-so --enable-ssl  #允许运行时加载DSO模块 # 启动ssl加密功能
--enable-cgi --enable-rewrite  # 启用cgi协议  #启用URL重写功能 
--with-zlib --with-pcre   # 指定pcre的安装路径  
--with-apr=/usr/local/apr   #指定apr的安装路径
--with-apr-util=/usr/local/apr-util   # 指定apr-util的安装路径
--enable-modules=most   # 启用大多数共享模块
--enable-mpms-shared=most  #启用MPM大多数参数
--with-mpm=event  #指定使用的MPM的类型
  •  
  • 启动Apache服务并验证
[root@server1 bin]# ./apachectl start   # 找到我们编译安装时指定的安装路径下bin目录下
[root@server1 bin]# crul http://localhost   # 验证apache是否可以正常访问
  • 1
  • 2
  • 修改apache的配置文件并设置PidFile路径(默认在/usr/local/apache/logs/httpd.pid)
[root@server1 bin]# ./apachectl stop    # 先停止apache服务
[root@server1 bin]# vim /etc/httpd/httpd.conf   # 添加以下内容
        PidFile  "/var/run/httpd.pid"
[root@server1 bin]# ./apachectl start  
  • 1
  • 2
  • 3
  • 4
  • 编写服务脚本/etc/init.d/httpd,让其可以使用service起停,并可以加到服务列表中
[root@server1 ~]# vim /etc/init.d/httpd   #添加以下内容
     #!/bin/bash
     #
     # httpd        Startup script for the Apache HTTP Server
     #
     # chkconfig: - 85 15
     # description: Apache is a World Wide Web server.  It is used to serve \
     #         HTML files and CGI.
     # processname: httpd
     # config: /etc/httpd/conf/httpd.conf
     # config: /etc/sysconfig/httpd
     # pidfile: /var/run/httpd.pid

     # Source function library.
     . /etc/rc.d/init.d/functions

     if [ -f /etc/sysconfig/httpd ]; then
             . /etc/sysconfig/httpd
     fi

     # Start httpd in the C locale by default.
     HTTPD_LANG=${HTTPD_LANG-"C"}

     # This will prevent initlog from swallowing up a pass-phrase prompt if
     # mod_ssl needs a pass-phrase from the user.
     INITLOG_ARGS=""

     # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
     # with the thread-based "worker" MPM; BE WARNED that some modules may not
     # work correctly with a thread-based MPM; notably PHP will refuse to start.

     # Path to the apachectl script, server binary, and short-form for messages.
     apachectl=/usr/local/apache/bin/apachectl
     httpd=${HTTPD-/usr/local/apache/bin/httpd}
     prog=httpd
     pidfile=${PIDFILE-/var/run/httpd.pid}
     lockfile=${LOCKFILE-/var/lock/subsys/httpd}
     RETVAL=0

     start() {
             echo -n $"Starting $prog: "
             LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
             RETVAL=$?
             echo
             [ $RETVAL = 0 ] && touch ${lockfile}
             return $RETVAL
     }

     stop() {
        echo -n $"Stopping $prog: "
        killproc -p ${pidfile} -d 10 $httpd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
     }
     reload() {
         echo -n $"Reloading $prog: "
         if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
             RETVAL=$?
             echo $"not reloading due to configuration syntax error"
             failure $"not reloading $httpd due to configuration syntax error"
         else
             killproc -p ${pidfile} $httpd -HUP
             RETVAL=$?
         fi
         echo
     }

     # See how we were called.
     case "$1" in
       start)
        start
        ;;
       stop)
        stop
        ;;
       status)
             status -p ${pidfile} $httpd
        RETVAL=$?
        ;;
       restart)
        stop
        start
        ;;
       condrestart)
        if [ -f ${pidfile} ] ; then
            stop
            start
        fi
        ;;
       reload)
             reload
        ;;
       graceful|help|configtest|fullstatus)
        $apachectl $@
        RETVAL=$?
        ;;
       *)
        echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
        exit 1
     esac

     exit $RETVAL
  •  

<1> 给脚本添加执行权限

  [root@server1 ~]# chmod +x /etc/init.d/httpd
  [root@server1 ~]# service httpd start
    Starting httpd:                                            [  OK  ]      
    [root@server1 ~]# service httpd status
    httpd (pid  3365) is running...
  •  

<2> 将httpd服务加到服务列表中,并设置在235级别开机启动

  [root@server1 ~]# chkconfig --add httpd
    [root@server1 ~]# chkconfig httpd --level 235 on
    [root@server1 ~]# chkconfig --list httpd
    httpd           0:off   1:off   2:on    3:on    4:off   5:on    6:off
  •  
  • 将/usr/local/apache/bin加入到PATH路径中去,让其中的命令可以进行全局执行
[root@server1 ~]# vim /etc/profile.d/apache.sh    # 脚本的名字必须要以.sh命名
    export PATH=$PATH:/usr/local/apache/bin

转载: https://blog.csdn.net/xuxingzhuang/article/details/51592363

安装mariadb:

[root@localhost soft]# groupadd -r mysql

> 添加用户到组 mysql 并且可以在不登录的情况下使用

[root@localhost soft]# useradd -r -g mysql -s /sbin/nologin -d /usr/local/mysql -M mysql

> 创建数据库存放目录

[root@localhost soft]# mkdir -p /data/mysql

> 改变数据库存放目录所属组为 mysql:mysql

[root@localhost soft]# chown -R mysql:mysql /data/mysql
执行编译安装

> 进入到解压后的源码包文件夹

[root@localhost soft]# cd mariadb-10.2.6

> 输入编译参数

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
 -DMYSQL_DATADIR=/data/mysql \
 -DSYSCONFDIR=/etc \
 -DWITHOUT_TOKUDB=1 \
 -DWITH_INNOBASE_STORAGE_ENGINE=1 \
 -DWITH_ARCHIVE_STPRAGE_ENGINE=1 \
 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
 -DWIYH_READLINE=1 \
 -DWIYH_SSL=system \
 -DVITH_ZLIB=system \
 -DWITH_LOBWRAP=0 \
 -DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock \
 -DDEFAULT_CHARSET=utf8 \
 -DDEFAULT_COLLATION=utf8_general_ci

> 如果编译失败请删除CMakeCache.txt

[root@localhost soft]# rm -f CMakeCache.txt

> 让指令重新执行,否则每次读取这个文件,命令修改正确也是报错

> cmake没问题,可以编译并且安装了: make && make install 时间会有点长根据个人机器吧,你可以干别的事情去!

[root@localhost soft]# make && make install

> 执行完成也就是安装完成了, 不过请注意, 这只是安装了, 并没有启动, 启动不成功等于没安装, 不能用也是徒劳无功不是?
6. 配置MariaDB

> 进行到 maria 安装目录

[root@localhost ~]# cd /usr/local/mysql/

> 使用maria用户执行脚本, 安装数据库到数据库存放目录

[root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mysql

> 输入以下信息:

[root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mysql
Installing MariaDB/MySQL system tables in '/data/maria' ...
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 MariaDB root USER !
To do so, start the server, then issue the following commands:

'./bin/mysqladmin' -u root password 'new-password'
'./bin/mysqladmin' -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:
'./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 MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd '.' ; ./bin/mysqld_safe --datadir='/data/maria'

You can test the MariaDB daemon with mysql-test-run.pl
cd './mysql-test' ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/
6. 复制maria配置文件到/etc目录

> 进行到 maria 安装目录

[root@localhost ~]# cd /usr/local/mysql/

> 拷贝support-files目录下的文件my-large.cnf到/etc目录并重命名为my.cnf

[root@localhost mysql]# cp support-files/my-large.cnf /etc/my.cnf
7. 创建启动脚本

[root@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
1
8. 启动mysqld服务

[root@localhost mysql]# /etc/rc.d/init.d/mysqld start
1
9. 配置环境变量, 以便在任何目录下输入mysql

> 打开并新建文件

[root@localhost mysql]# vim /etc/profile.d/mysql.sh

> 输入以下内容

export PATH=$PATH:/usr/local/mysql/bin/

> 保存并退出

:wq

> 为脚本赋于可执行权限

[root@localhost mysql]# chmod 0777 /etc/profile.d/mysql.sh

> 进行mysql.sh脚本所在目录, 并执行脚本, 以立即生效环境变量

[root@localhost mysql]# source /etc/profile.d/mysql.sh
10. 初始化MariaDB


> 运行MariaDB初始化脚本

[root@localhost mysql]# ./bin/mysql_secure_installation

> 以下提示:

Enter current password for root (enter for none):   输入当前root密码(没有输入)

Set root password? [Y/n]    设置root密码?(是/否)

New password:   输入新root密码

Re-enter new password:      确认输入root密码

Password updated successfully!      密码更新成功

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

默认情况下,MariaDB安装有一个匿名用户,
允许任何人登录MariaDB而他们无需创建用户帐户。
这个目的是只用于测试,安装去更平缓一些。
你应该进入前删除它们生产环境。

Remove anonymous users? [Y/n]       删除匿名用户?(是/否)

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

通常情况下,root只应允许从localhost连接。
这确保其他用户无法从网络猜测root密码。

Disallow root login remotely? [Y/n]     不允许root登录远程?(是/否)

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

默认情况下,MariaDB提供了一个名为“测试”的数据库,任何人都可以访问。
这也只用于测试,在进入生产环境之前应该被删除。

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

重新加载权限表将确保所有到目前为止所做的更改将立即生效。

Reload privilege tables now? [Y/n]      现在重新加载权限表(是/否)

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

全部完成!如果你已经完成了以上步骤,MariaDB安装现在应该安全。

Thanks for using MariaDB!

感谢使用MariaDB!
编译安装MariaDB后所有配置

Last login: Sun Jun 11 13:50:59 2017 from 192.168.1.101
[root@localhost ~]# rm -rf /etc/my.cnf /etc/my.cnf.d/
[root@localhost ~]# cd /usr/local/mysql/
[root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mysql/
Installing MariaDB/MySQL system tables in '/data/mysql/' ...
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 MariaDB root USER !
To do so, start the server, then issue the following commands:

'./bin/mysqladmin' -u root password 'new-password'
'./bin/mysqladmin' -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:
'./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 MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd '.' ; ./bin/mysqld_safe --datadir='/data/mysql/'

You can test the MariaDB daemon with mysql-test-run.pl
cd './mysql-test' ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/

[root@localhost mysql]# cp support-files/my-large.cnf /etc/my.cnf
[root@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@localhost mysql]# /etc/rc.d/init.d/mysqld start
Reloading systemd:                                         [  OK  ]
Starting mysqld (via systemctl):                           [  OK  ]
[root@localhost mysql]# vim /etc/profile.d/mysql.sh
[root@localhost mysql]# touch /etc/profile.d/mysql.sh
[root@localhost mysql]# echo 'export PATH=$PATH:/usr/local/mysql/bin/' > /etc/profile.d/mysql.sh 
[root@localhost mysql]# chmod 0777 /etc/profile
profile    profile.d/ 
[root@localhost mysql]# chmod 0777 /etc/profile.d/mysql.sh 
[root@localhost mysql]# source /etc/profile.d/mysql.sh 
[root@localhost mysql]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.2.6-MariaDB-log Source distribution

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> 

安装php:

yum install -y libxml2 libxml2-devel bzip2-devel

编译安装 libmcrypt, mhash, mcrypt 二进制源码包 
编译安装libmcrypt-2.5.8

[root@localhost ~]# tar zxvf libmcrypt-2.5.8.tar.gz [root@localhost ~]# cd libmcrypt-2.5.8 [root@localhost libmcrypt-2.5.8]# ./configure --prefix=/usr/local/related/libmcrypt [root@localhost libmcrypt-2.5.8]# make && make install

[root@localhost libmcrypt-2.5.8]# cd ~ [root@localhost ~]# rm -rf libmcrypt-2.5.8*1

编译安装mhash-0.9.9.9

[root@localhost ~]# tar zxf mhash-0.9.9.9.tar.gz [root@localhost ~]# cd mhash-0.9.9.9 [root@localhost mhash-0.9.9.9]# ./configure --prefix=/usr/local/related/mhash [root@localhost mhash-0.9.9.9]# make && make install

[root@localhost mhash-0.9.9.9]# cd ~ [root@localhost ~]# rm -rf mhash-0.9.9.9*1

编译安装mcrypt-2.6.8

[root@localhost ~]# tar zxf mcrypt-2.6.8.tar.gz && cd mcrypt-2.6.8 [root@localhost mcrypt-2.6.8]# export LD_LIBRARY_PATH=/usr/local/related/libmcrypt/lib:/usr/local/related/mhash/lib [root@localhost mcrypt-2.6.8]# export LDFLAGS="-L/usr/local/related/mhash/lib -I/usr/local/related/mhash/include/"

[root@localhost mcrypt-2.6.8]# export CFLAGS="-I/usr/local/related/mhash/include/" [root@localhost mcrypt-2.6.8]# ./configure --prefix=/usr/local/related/mcrypt --with-libmcrypt-prefix=/usr/local/related/libmcrypt [root@localhost mcrypt-2.6.8]# make && make install [root@localhost mcrypt-2.6.8]# cd ~ [root@localhost ~]# rm -rf mcrypt-2.6.8*

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs  --with-config-file-path=/usr/local/php/etc  --with-mysql-sock=/var/run/mysql/mysql.sock    --with-mcrypt=/usr/include  --with-mysql   --with-mysqli   --with-pdo-mysql --enable-mbstring --enable-session  --enable-opcache --enable-fpm --enable-fastcgi --with-fpm-user=daemon      --with-fpm-group=daemon  --with-mcrypt=/usr/local/libmcrypt

复制配置文件php.ini
[root@localhost php-5.6.13]# cp /usr/local/src/php-5.6.13/php.ini-production /etc/php.ini
整合Apache
1、在/etc/httpd/conf/httpd.conf文件中加入PHP文件类型解析(加在文件最后即可)

[root@localhost ~]# sed -i '378aAddType application/x-httpd-php .php' /etc/httpd/httpd.conf
[root@localhost ~]# sed -i '379aAddtype application/x-httpd-php-source .phps' /etc/httpd/httpd.conf
[root@localhost ~]# sed -i 's/DirectoryIndex.*index.*/DirectoryIndex index.php index.html/g' /etc/httpd/httpd.conf
2、重启Apache

[root@localhost ~]# service httpd restart  # 或 /etc/init.d/httpd restart
3、添加测试页面

[root@localhost php-5.6.13]# cat /usr/local/apache2/htdocs/index.php 
<?php
    phpinfo()
?>

最后解压你的PHP安装包;

可能会出现问题需要网上自己寻找解决问题。 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值