一、 挂载光盘

命令:

mount /dev/cdrom /media

光盘上的文件系统,最常见是 ISO9660 和 Universal Disk Format (UDF) 格式。
你可以尝试以下两个命令:

mount -t iso9660 /dev/cdrom /mnt/cdrom
mount -t udf /dev/cdrom /mnt/cdrom

执行mount命令时找不到介质或者mount:no medium found的解决办法
首先确定,VMWARE的CD/DVD设置内,已经成功选中ISO镜像。如下图所示:

这里写图片描述
临时解决办法:在虚拟机下部的状态栏内,找到CD/DVD图标(一个光盘图标),此时一般显示为灰色,鼠标点一下,即可启动CD/DVD,此时CD/DVD即可加载到虚拟机系统内,如下图所示:
未加载CD/DVD:这里写图片描述
已加载CD/DVD:这里写图片描述
永久解决办法:在虚拟机的CD/DVD设置里,将“已连接”和“打开电源时连接”两个选项,选中,确定即可。如下图所示:
这里写图片描述
此时再执行mount命令,即可成功挂载光盘。

sudo mkdir /mnt/cdrom
mount -t iso9660 /dev/cdrom /mnt/cdrom
cd /media

看看有没有东西,有东西就说明挂载成功

二、 安装gcc编译器

装好Linux后,默认是有gcc的,不过在编译过程中有可能会出现gcc依赖不足等问题,故这里再安装一次,这里使用yum来安装:

yum -y install gcc*

三、 卸载系统 Apache、 MySQL 和 PHP 的 RPM 安装包

默认Linux系统是有安装Apache和Mysql的RPM包的,不过我是卸载了然后使用源代码重新编译安装下,因为如果要使用高版本软件的话就只能这样了。
卸载前需关闭启动的服务,如 httpd、 mysqld

service httpd stop
service mysqld stop

卸载 RPM 包的 Apache、 MySQL

yum remove httpd
yum remove mysql

若有出现依赖问题等不能卸载的,可截断依赖

rpm –e http-1.2.3.rpm --nodeps

四、 安装杂项:

/usr/bin/yum -y install ntp vim-enhanced gcc gcc-c++ flex bison \
autoconf automake bzip2-devel ncurses-devel zlib-devel \
libjpeg-devel libpng-devel libtiff-devel freetype-devel \
libXpm-devel gettext-devel pam-devel libtool libtool-ltdl \
openssl openssl-devel fontconfig-devel libxml2-devel curl-devel \
libicu libicu-devel libmcrypt libmcrypt-devel libmhash libxml2 \
libmhash-devel mysql-devel libxslt libxslt-devel make pcre-devel \ libmcrypt-devel

注意:这里一部分为可选,根据你单独安装的插件情况选择这里需要不需要安装,默认全部安装即可。
注意:如果这一步yum 安装失败,检查虚拟机网络连接,确保能连接外网。

五、 安装apr:

tar xf apr-1.5.2.tar.gz
cd apr-1.5.2
./configure
make && make install

六、 安装apr-util:

tar xf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure --with-apr=/usr/local/apr/
make && make install

七、 安装apache:

tar xf httpd-2.4.17.tar.gz
cd httpd-2.4.17
./configure --prefix=/usr/local/apache2 --with-mpm=prefork \
 --enable-so --enable-rewrite --enable-mods-shared=all \
 --enable-nonportable-atomics=yes --disable-dav --enable-cache \
 --enable-disk-cache --enable-ssl --enable-mem-cache \
 --enable-file-cache
make && make install
cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd

设置文件的访问权限

chmod a+x /etc/init.d/httpd

加入服务

chkconfig --add httpd

开机自启

chkconfig httpd on  
service httpd restart

apache开机自启动开/关:

chkconfig httpd on / off

八、 安装mysql:

  1. 工具/原料

mysql-5.6.17-linux-glibc2.5-i686.tar.gz
mysql-5.6.17-linux-glibc2.5-x86_64.tar.gz
到mysql官网下载mysql编译好的二进制安装包,在下载页面Select Platform:选项选择linux-generic,然后把页面拉到底部,64位系统下载Linux - Generic (glibc 2.5) (x86, 64-bit),32位系统下载Linux - Generic (glibc 2.5) (x86, 32-bit)
这里写图片描述

  1. 解压缩并拷贝

tar mysql-5.6.17-linux-glibc2.5-i686.tar.gz
cp mysql-5.6.17-linux-glibc2.5-i686 /usr/local/mysql –r

注意:目录结尾不要加/

  1. 添加系统mysql组和mysql用户:

groupadd mysql
useradd -r -g mysql mysql
  1. 安装数据库:

1) 进入安装mysql软件目录:

cd /usr/local/mysql

2) 修改当前目录拥有者为mysql用户:

chown -R mysql:mysql ./

3) 安装数据库:

./scripts/mysql_install_db --user=mysql  --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

注意:这里会报warning 无视继续后边操作即可
说明:64位系统安装的时候可能会报如下错误
原因:是因为64位系统中安装了32位程序是因为64位系统中安装了32位程序
强烈建议重新下载64位MySQL安装!!!
这里写图片描述
宝宝,如果你非要安装32位的会出很多问题的!


sh: ./bin/my_print_defaults: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory
FATAL ERROR: Neither host 'localhost.localdomain' nor 'localhost' could be looked up with
./bin/resolveip
Please configure the 'hostname' command to return a correct
hostname.
If you want to solve this at a later stage, restart this script
with the --force option

解决办法:

yum install glibc.i686

./bin/my_print_defaults: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
FATAL ERROR: Neither host 'localhost.localdomain' nor 'localhost' could be looked up with
./bin/resolveip
Please configure the 'hostname' command to return a correct
hostname.
If you want to solve this at a later stage, restart this script
with the --force option

解决办法:

yum install libstdc++.so.6

Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

解决办法:

yum -y install libaio.so.1

4) 修改当前目录拥有者为root用户:

chown -R root:root ./

5) 修改当前data目录拥有者为mysql用户:

chown -R mysql:mysql data

6) 到此数据库安装完毕
7) mysql5.7系列安装:
注:
mysql5.7和之前版本不同,很多资料上都是这个命令:../scripts/mysql_install_db --user=mysql,而mysql5.7的mysql_install_db命令是在bin目录下 的并且建议 用 mysqld --initialize命令
mysql5.7之前版本初始化配置表命令:
script/mysql_install_db --user=mysql --basedir=/Ultrapower/test/mysql --datadir=/Ultrapower/test/mysql/data/
--user 启动mysql的用户
--basedir mysql安装目录
--datadir mysql数据仓库目录
正确安装命令:

cd /usr/local/mysql
chown -R mysql:mysql ./
mkdir data
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

安装完记得执行上边第四和第五步,改目录权限

  1. 启动mysql服务和添加开机启动mysql服务:

添加开机启动:

cp support-files/mysql.server /etc/init.d/mysql

意思是:把启动脚本放到开机初始化目录。

chkconfig mysql on

至此,设置MySQL开机自启动成功。

启动mysql服务:

service mysql start

查看mysql服务是否启动成功:

ps -ef|grep mysql 
  1. 修改mysql的root用户密码,root初始密码为空的:

./bin/mysqladmin -u root password '密码'

注意:此操作可以跳过,默认mysql无密码,后期登录mysql再“set password=....”命令进行设置

  1. 把mysql客户端放到默认路径:

ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql

注意:建议使用软链过去,不要直接包文件复制,便于系统安装多个版本的mysql

  1. 如果服务能开启 连不上mysql

报错信息:mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory

yum install libncurses.so.5

报错信息:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

more /etc/my.cnf |grep sock

你会看到:socket=/var/lib/mysql/mysql.sock
由上可知my.cnf中定义的为/var/lib/mysql/mysql.sock目录下,而错误提示为/tmp/mysql.sock目录下
也就是说mysql已经生成了正确的sock文件,但客户端连接还是从初始目录去找sock文件

vim /etc/my.cnf

socket=/var/lib/mysql/mysql.sock // 注销掉这行
socket = /tmp/mysql.sock // 添加该行
重启MySQL

service mysql restart

连接MySQL测试

mysql –uroot -p
  1. 配置远程访问mysql权限

如果没有给远程登录用户添加所有机器都能访问的权限,将会出现“1045-Access denied for user root@IT(using password:NO)”,这表明需要添加权限;
mysql服务器端链接mysql(root用户),执行以下两条命令:

允许所有用户用(账户:root,密码:123456)链接mysql:

grant all on *.* to root@"%" identified by "123456";

刷新权限:

flush privileges;

完成以上步骤,就可以远程访问MySQL数据库了。
参考链接:
http://www.111cn.net/database/mysql/46377.htm
http://jingyan.baidu.com/article/046a7b3ed85f3ef9c27fa9dc.html

九、 安装libmycrypt

cd /usr/local/src
tar zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure
make
make install

十、 安装PHP:

tar xf php-5.6.17.tar.gz
cd php-5.6.17
./configure --prefix=/usr/local/php \
 --with-apxs2=/usr/local/apache2/bin/apxs --enable-cgi --with-mysql \
 --with-config-file-path=/usr/local/php/etc \
 --with-pdo-mysql=/usr/local/mysql/bin/mysql\
 --with-mysqli=/usr/local/mysql/bin/mysql_config \
 --enable-zip --enable-fpm -enable-sockets --enable-soap --enable-pcntl \
 --enable-mbstring --enable-intl --enable-calendar --enable-bcmath \
 --enable-exif --with-mcrypt --with-mhash --with-gd --with-png-dir \
 --with-jpeg-dir --with-freetype-dir --with-libxml-dir --with-curl \
 --with-zlib   --with-openssl --with-kerberos=shared \
 --with-gettext=shared --with-xmlrpc=shared --with-xsl

注意:以上带路径的需要根据自己的环境配置目录更改,不要死搬硬套!
如果安装的是nginx去掉这里:
这里写图片描述

make && make install
cp php.ini-production /usr/local/php/etc/php.ini
ln -s /usr/local/php/bin/ph* /usr/local/bin/

十一、 编辑apache配置文件支持php:

vim /usr/local/apache/conf/httpd.conf

查找AddType application/x-gzip .gz .tgz,在该行下面添加:

AddType application/x-httpd-php .php

查找DirectoryIndex index.html 把该行修改成:

DirectoryIndex index.html index.htm index.php
ServerName localhost

十二、 安装nginx

  1. 目的:

更换Apache为nginx

  1. 关闭Apache,关闭Apache开机自启动

service httpd stop
chkconfig httpd off
  1. 为了支持rewrite功能,我们需要安装pcre

通过yum安装:

yum install pcre*

如果以上命令报错,那么进行编译安装

cd /user/local/src/
wget http://sourceforge.jp/frs/g_redir.php?m=jaist&f=%2Fpcre%2Fpcre%2F8.30%2Fpcre-8.30.tar.gz
tar zxf pcre-8.30.tar.gz
cd pcre-8.30/
./configure 
make&&make install
  1. 需要ssl的支持, 安装openssl

先检查有没有安装openssl

openssl version -a

如果已经安装,跳过此步。
如果没有版本号,进行yum安装:

yum install openssl*
  1. 安装nginx

将nginx-*.tar.gz 上传到/usr/local/src 目录下

cd /user/local/src/
tar –zxvf nginx-***.tar.gz
cd nginx-***
./configure --prefix=/usr/local/nginx \
--with-http_ssl_module \
--with-http_spdy_module \
--with-http_stub_status_module \
--with-pcre

说明:
–with-http_stub_status_module:支持nginx状态查询
–with-http_ssl_module:支持https
–with-http_spdy_module:支持google的spdy,想了解请百度spdy,这个必须有ssl的支持
–with-pcre:为了支持rewrite重写功能,必须制定pcre

如果报错–with-http_spdy_module, 去掉这个选项重新编译

make
make install
  1. 启动 nginx

/usr/local/nginx/sbin/nginx

测试是否安装启动成功

curl -s http://localhost | grep nginx.com 

这里写图片描述
Nginx 关闭

/usr/local/nginx/sbin/nginx -s stop

Nginx 不停止重新加载

/usr/local/nginx/sbin/nginx -s reload

说明:如果已经做了下边的第九步“设置nginx开机自启动”,也就是已经编辑过 /etc/init.d/nginx
可以使用命令:

service nginx start|stop|restart|reload|status|help 

或者

/etc/init.d/nginx start|stop|restart|reload|status|help 
  1. 检查php有没有安装php-fpm

find / -name ‘php-fpm’

或者:

cd /usr/local/php/sbin/

看看有没有php-fpm
如果有,说明已经安装了php-fpm

如果没有安装php-fpm,则重新编译安装php
在编译初始化的时候加上--enable-fpm”
重新执行 make && make install
安装完再次进行检查

find / -name ‘php-fpm’

生成配置文件

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

启动php-fpm

/usr/local/php/sbin/php-fpm

查看php-fpm 启动是否正常

netstat  -anltp   |grep  9000

这里写图片描述

  1. 设置nginx 和php-fpm开机自启动

首先,在linux系统的/etc/init.d/目录下创建nginx文件和php-fpm文件

vim /etc/init.d/nginx

在脚本中添加如代码:

#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
#              It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
   echo "nginx already running...."
   exit 1
fi
   echo -n $"Starting $prog: "
   daemon $nginxd -c ${nginx_config}
   RETVAL=$?
   echo
   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
   return $RETVAL
}
# Stop nginx daemons functions.
stop() {
        echo -n $"Stopping $prog: "
        killproc $nginxd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
    echo -n $"Reloading $prog: "
    #kill -HUP `cat ${nginx_pid}`
    killproc $nginxd -HUP
    RETVAL=$?
    echo
}
# See how we were called.
case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
reload)
        reload
        ;;
restart)
        stop
        start
        ;;
status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo $"Usage: $prog {start|stop|restart|reload|status|help}"
        exit 1
esac
exit $RETVAL
vim /etc/init.d/php-fpm

在脚本中添加如下代码:

#!/bin/bash
# php-fpm startup script for the php-fpm 
# php-fpm version:5.5.0-alpha6
# chkconfig: - 85 15
# description: php-fpm is very good
# processname: php-fpm
# pidfile: /var/run/php-fpm.pid
# config: /usr/local/php/etc/php-fpm.conf
  
php_command=/usr/local/php/sbin/php-fom
php_config=/usr/local/php/etc/php-fpm.conf
php_pid=/usr/local/php/var/run/php-fpm.pid
RETVAL=0
prog="php-fpm"
  
#start function
php_fpm_start() {
    /usr/local/php/sbin/php-fpm
}
  
start(){
    if [ -e $php_pid  ]
    then
    echo "php-fpm already start..."
    exit 1
    fi
    php_fpm_start
}
  
stop(){
    if [ -e $php_pid ]
    then
    parent_pid=`cat $php_pid`
    all_pid=`ps -ef | grep php-fpm | awk '{if('$parent_pid' == $3){print $2}}'`
    for pid in $all_pid
    do
            kill $pid
        done
        kill $parent_pid
    fi
    exit 1
}
  
restart(){
    stop
    start
}
  
# See how we were called.
case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
restart)
        stop
        start
        ;;
status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo $"Usage: $prog {start|stop|restart|status}"
        exit 1
esac
exit $RETVAL

接着,设置文件的访问权限:

chmod a+x /etc/init.d/nginx 
chmod a+x /etc/init.d/php-fpm

(a+x参数表示 ==> all user can execute 所有用户可执行)

最后,执行开机自启动命令
加入服务

chkconfig --add nginx
chkconfig --add php-fpm

开机自启

chkconfig nginx on    
chkconfig php-fpm on

或者,这样开机自启动
将ngix加入到rc.local文件中,这样开机的时候nginx也能默认启动

vi /etc/rc.local

添加如下代码

/etc/init.d/nginx start 

保存并退出
下次重启就会生效,实现nginx的自启动。

补充说明:
以上两种自启动方式区别:
chkconfig调用的服务是在/etc/init.d下面的东东,而这些东东都是在启动过程中搞的。
/etc/rc.local这个文件是在系统已经初始化完成就绪之后,才来读这个东东的。这个东东里面的东西和系统是否启动没有多大关系。

  1. 将nginx和 php 关联

新建测试文件

vim /www/phpinfo.php
<?php
phpinfo();

修改nginx配置支持php

vim /usr/local/nginx/conf/nginx.conf

修改以下内容

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           /www;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #

这里写图片描述
启动或者加载nginx 的配置

/usr/local/nginx/sbin/nginx 

或者

/usr/local/nginx/sbin/nginx  -s  reload

访问测试:
http://192.888.888.888/phpinfo.php

  1. nginx多端口配置

修改nginx配置文件

cd /user/local/nginx/conf/
vim nginx.conf

相应位置引入vhosts文件

include vhosts/*.conf;

这里写图片描述
新建vhosts文件夹

mkdir vhosts
cd vhosts
vim xxx.xxx.com.conf

将以下代码复制进去

    server {
        listen       81;
        server_name  xxx.xxxxx.com;
        #charset koi8-r;
        #access_log  logs/xxx.access.log;
        location / {
            root   /www;
            index  index.php index.html index.htm;
            try_files $uri $uri/ /index.php?$query_string;
        }
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           /www;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

这里写图片描述
说明:
1:需要监听的端口号
2:项目域名
3:项目执行日志,默认关闭,按需可以开启
4:项目入口文件所在目录
5:laravel官方给出的方法,开启nginx的rewrite功能,理论上通用,请自测
6:项目入口文件所在目录
7:神秘识别目录的变量
开启rewrite功能(上图标“5”位置)。
可以有效解决下级页面跳转找不到地址的问题。

如果有多个端口,就复制多个“xxx.xxxxx.com.conf”,分别重命名不同名字(随便命名,以.conf结尾即可,不需要跟站点域名一样)就可以,再如上图改标红的部分,看哪些需要改就改哪些(一般改标“1、2、3、4、6”的位置)。

提示:
如果你的网站访问空白,注意给web目录配置权限

chmod –R 777 /www/web目录

标签: Lnmp, Lamp

添加新评论


手机号仅后台超管可见,普通注册用户以及网站前台全站不可见,请勿担心泄露风险!