虚拟机上CentOS 7.0编译安装Nginx+MySQL+PHP(二)

来源:互联网 发布:淘宝ipsa旗舰店 编辑:程序博客网 时间:2024/05/14 02:52

初始化:

./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql #生成mysql系统数据库

(上面这句有问题:之前版本mysql_install_db是在mysql_basedir/script下,5.7放在了mysql_install_db/bin目录下,且已被废弃。参考:http://blog.itpub.net/29733787/viewspace-1590891/

(因此使用命令:bin/mysqld --initialize代替)

设置Mysql服务启动

// 设置环境变量,更改PATH参数
vim /root/.bash_profile    PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/libsource /root/.bash_profile

chkconfig --add mysqldchkconfig mysqld on service mysqld start

ln -s /usr/local/mysql/my.cnf /etc/my.cnf #添加到/etc目录的软连接

cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld #把Mysql加入系统启动

chmod 755 /etc/init.d/mysqld #增加执行权限

chkconfig mysqld on #加入开机启动

vi /etc/rc.d/init.d/mysqld #编辑

basedir=/usr/local/mysql #MySQL程序安装路径

datadir=/data/mysql #MySQl数据库存放目录

:wq! #保存退出

service mysqld start #启动

vi /etc/profile #把mysql服务加入系统环境变量:在最后添加下面这一行

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

:wq! #保存退出

source /etc/profile  #使配置立刻生效

下面这两行把myslq的库文件链接到系统默认的位置,这样你在编译类似PHP等软件时可以不用指定mysql的库文件地址。

ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql

ln -s /usr/local/mysql/include/mysql /usr/include/mysql

mkdir /var/lib/mysql #创建目录

ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock #添加软链接


修改密码:

第一步、用安全模式登入数据库:

利用vim命令打开mysql配置文件my.cnf

在mysqld进程配置文件中添加skip-grant-tables,添加完成后,执行wd保存。

使用mysql -uroot -p 登陆,提示输入密码时回车即可。

参考http://jingyan.baidu.com/article/9c69d48f42166213c9024e02.html

第二步,修改密码。

mysql5.7的mysql.user表结构被修改,使用如下语句可实现密码修改

update mysql.user set authentication_string=password('123456') where user='root' and Host = 'localhost';

(错误:

还是有问题,原来是权限问题:

输入 mysql -u root 登录 mysql 的时候出现以下错误:

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

出现这个问题的原因是没有生成 mysql.sock 文件,没有生成这个文件的原因是 /usr/local/mysql 目录的权限不对:

chown -R mysql:mysql  /usr/local/mysql 即可解决

还是有问题:参考  http://blog.csdn.net/wyzxg/article/details/4720041

我用此法解决了,并且我的mysql.sock再data文件夹下,find就好。



二、安装Nginx

1、安装pcre

cd /usr/local/src

mkdir /usr/local/pcre

tar zxvf pcre-8.35.tar.gz

cd pcre-8.35

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

make

make install



2、安装openssl

cd /usr/local/src

mkdir /usr/local/openssl

tar zxvf openssl-1.0.1h.tar.gz

cd openssl-1.0.1h

./config --prefix=/usr/local/openssl

make

make install

vi /etc/profile

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

:wq!

source /etc/profile

  1. 安装php

    cd /usr/local/src    

    tar -zvxf php-5.3.13.tar.gz    

    cd  php-5.3.13    

    mkdir -p /usr/local/php5  #建立php安装目录    

    ./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-gd --with-iconv  --with-zlib  --enable-xml --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-mbregex  --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --with-jpeg-dir --with-freetype-dir #配置    

    make   #编译    

    make install    #安装    

    cp  php.ini-production   /usr/local/php5/etc/php.ini  #复制php配置文件到安装目录    

    rm -rf /etc/php.ini   #删除系统自带配置文件  

    ln -s /usr/local/php5/etc/php.ini  /etc/php.ini    #添加软链接    

    cp  /usr/local/php5/etc/php-fpm.conf.default   /usr/local/php5/etc/php-fpm.conf      #拷贝模板文件为php-fpm配置文件    

    vi  /usr/local/php5/etc/php-fpm.conf  #编辑    

    user = www    #设置php-fpm运行账号为www    

    group = www   #设置php-fpm运行组为www    

    pid = run/php-fpm.pid    #取消前面的分号    

    cp /usr/local/src/php-5.3.13/sapi/fpm/init.d.php-fpm   /etc/rc.d/init.d/php-fpm  #设置 php-fpm开机启动,拷贝php-fpm到启动目录    

    chmod +x /etc/rc.d/init.d/php-fpm  #添加执行权限    

    chkconfig php-fpm on    #设置开机启动    

    vi /usr/local/php5/etc/php.ini    #编辑配置文件    

    找到:disable_functions =    

    修改为:disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname    

    #列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。    

    找到:;date.timezone =    

    修改为:date.timezone = PRC   #设置时区    

    找到:expose_php = On    

    修改为:expose_php = OFF  #禁止显示php版本的信息    

    PS:在编译PHP的过程中可能会报UNDEFINED REFERENCE TO `LIBICONV_OPEN 无法编译PHP LIBICONV错误.  

  2. 配置nginx支持php

    vi /usr/local/nginx/conf/nginx.conf      #编辑配置文件    

    user   www  www;          #首行user去掉注释,修改Nginx运行组为www www;必须与/usr/local/php5/etc/php-fpm.conf中的user,group配置相同,否则php运行出错    

    index  index.php  index.html index.htm;    #添加index.php    

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000    

    #    

    location ~ \.php$ {    

       root           html;#此处和server下面root保持一致,默认为html    

       fastcgi_pass   127.0.0.1:9000;    

       fastcgi_index  index.php;    

       fastcgi_param  SCRIPT_FILENAME   /usr/local/nginx/html/$fastcgi_script_name;    

       include        fastcgi_params;     

    注意:取消FastCGI server部分location的注释,并要注意fastcgi_param行的参数,改为/data/webroot/(此为网站根目录绝对路径)$fastcgi_script_name

    /etc/init.d/nginx restart  #重启nginx

  3. 还需要创建系统用户及用户组

  4. /usr/sbin/groupadd -f www
    /usr/sbin/useradd -g www www

    另外:上面nginx.conf中的配置也不对,改为如下正确:

  5. location ~ \.php$ {

  6.             fastcgi_pass    127.0.0.1:9000;  
     
                    fastcgi_index   index.php;  
     
                    fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;  
     
                    include fastcgi_params;                   
    include fastcgi.conf;
            }

0 0
原创粉丝点击