layout: post
title: "Nginx下PHP环境搭建1"
date: 2016-04-26 22:53:05 +0800
comments: true
categories: [Nginx,PHP]
Nginx下PHP环境搭建1
一、需要准备的包
- libiconv-1.7.tar.gz
- libmcrypt-2.5.7.tar.gz
- mcrypt-2.6.8.tar.gz
- mhash-0.9.3.tar.gz
- php-5.5.34.tar.bz2
二、具体安装
-
libiconv
- tar -zvxf libiconv-1.7.tar.gz
- cd libiconv-1.7
- ./configure --prefix=/usr/local
- make
- make install
-
libmcrypt
- tar -zvxf libmcrypt-2.5.7.tar.gz
- cd libmcrypt-2.5.7
- ./configure
- make
- make install
- /sbin/ldconfig //共享链接库
- ./configure --enable-ltdl-install //内键指令
- make
- make install
-
mhash
- tar -zvxf mhash-0.9.3.tar.gz
- cd mhash-0.9.3
- ./configure
- make
- make install
- ln -s /usr/local/lib/libmcrypt.la /usr/lib/ibmcrypt.la
- ln -s /usr/local/lib/libmcrypt.la.so.4 /usr/lib/libmcrypt.la.so.4
- ln -s /usr/local/lib/libmcrypt.la.so.4.4.8 /usr/lib/libmcrypt.la.so.4.4.8
- ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
- ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
- ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
- ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
- ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
-
mcrypt
- tar -zxvf mcrypt-2.6.8.tar.gz
- cd mcrypt-2.6.8
- /sbin/ldconfig
- ./configure
- 若报错则找不到LIBMCRYPT则
- export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
- ./configure -with-libmcryp-prefix=/usr/local
- make
- 报错打开报错的文件 vi /usr/local/include/mutils.h
- 找到报错的那行看是哪个文件引入失败(mhash_config.h)
- find / -name mhash_config.h 在系统中找到该文件
- cp /home/Ewan/下载/mhash-0.9.3/mhash_config.h /usr/local/include 拷贝到include文件下
- make
- make install
-
php-5.5.34.tar.bz2
- tar -jxvf php-5.5.34.tar.bz2
- cd php-5.5.34
- ./configure --prefix=/usr/local/php --enable-fastcgi --enable-fpm
- 报错 yum install libxml2 libxml2-devel
- ./configure --prefix=/usr/local/php --enable-fastcgi --enable-fpm
- make ZEND_EXTRA_LIBS='-liconv'
- make install
- 报错 vi /etc/ld.so.conf
- 输入 /usr/local/lib
- make install
- 如果还是出错 /sbin/ldconfig -v
- make install
- cp php.ini-dist /usr/local/php/etc/php.ini
-
mysql (5.5版本以下)
- groupadd mysql //添加组
- useradd mysql -g mysql //添加用户
- tar -zxvf mysql-x.x.x
- cd mysql-x.x.x
- ./configure --prefix=/usr/local/mysql --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-readline --with-ssl
- /usr/local/mysql/bin/mysql_install_db --user//初始化数据库
- cp ./support-files/mysql.server /etc/init.d/mysql //复制启动项到系统中
- cp ./support-files/my-medium.cnf /etc/my.cnf
- chmod 755 /etc/init.d/mysql(755 分别代表文件拥有者,同组者,其他人的权限 rwx 7为111 可读可写可执行)
- cd /usr/local/mysql
- chown -R mysql . //将拥有者更改为mysql用户
- chgrp -R mysql . //归到mysql组
- /usr/local/mysql/bin/mysqladmin -u root password 'abc123' //设置数据库密码
- 报错 不能连接到local mysql
- ps -ef|grep mysql //找到mysql对应的进程号
- kill -9 xxxx //杀死进程
- /usr/local/mysql/bin/mysql_install_db --user//初始化数据库
- service mysql start //启动MYSQL
- /usr/local/mysql/bin/mysqladmin -u root password 'abc123' //设置数据库密码
- /usr/local/mysql/bin/mysql -u root -p //测试输入的密码
- 进入到mysql 后可以\q退出
-
安装mysql(5.5版本)
下载Mysql5.5.4
1. tar zxvf mysql-5.5.40.tar.gz
2. cd mysql-5.5.4
3. yum install ncurses-devel cmake bison-devel libaio-devel gcc-c++ bison -y
* mysql5.5 版本之后,预编译的 configure命令改为了 cmake, 需要手动安装一下 cmake命令
5. cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci-- Library mysqlclient depends on OSLIBS -lpthread;m;rt;dl-- Configuring done-- Generating done-- Build files have been written to: /root/mysql-5.5.40 ————预编译无报错,成功。
* make
* [100%] Building CXX object mysql-test/lib/My/SafeProcess/CMakeFiles/my_safe_process.dir/safe_process.cc.oLinking CXX executable my_safe_process[100%] Built target my_safe_process————无报错,make正常。
* make install -- Installing: /usr/local/mysql/man/man1/mysql_fix_extensions.1 -- Installing: /usr/local/mysql/man/man1/mysqldumpslow.1 -- Installing: /usr/local/mysql/man/man1/mysql_secure_installation.1 -- Installing: /usr/local/mysql/man/man8/mysqld.8 ————无报错,make install正常。
* groupadd mysql ————创建mysql组
* useradd -g mysql mysql ————在mysql组中创建mysql用户
* cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf ————默认没有mysql的配置文件,将源码包中的配置文件拷贝到etc下的配置文件中。
* /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data ————初始化数据库,指定用户为mysql,家目录为/usr/local/mysql,数据库目录为/usr/local/mysql/data
* chown -R root /usr/local/mysql/ ————改变目录的所有者
* chown -R mysql /usr/local/mysql/data ————改变目录的所有者
* chgrp -R mysql /usr/local/mysql/ ————改变目录的所属组
* export PATH=$PATH:/usr/local/mysql/bin ————将/usr/local/mysql/bin下的命令放到环境变量中
* /usr/local/mysql/bin/mysqld_safe --user=mysql & ————启动mysql
* mysql
* Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
ps:在实际的操作过程中上面在10步初始化数据库时有可能会error这时可以考虑用
ps -ef|grep mysql //找到mysql对应的进程号
kill -9 xxxx //杀死进程
然后执行
chown -R root /usr/local/mysql/ ————改变目录的所有者
chown -R mysql /usr/local/mysql/data ————改变目录的所有者
chgrp -R mysql /usr/local/mysql/ ————改变目录的所属组
export PATH=$PATH:/usr/local/mysql/bin ————将/usr/local/mysql/bin下的命令放到环境变量中
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data ————初始化数据库,指定用户为mysql,家目录为/usr/local/mysql,数据库目录为/usr/local/mysql/data
/usr/local/mysql/bin/mysqld_safe & 启动Mysql 或者
/usr/local/mysql/bin/mysqld_safe --user=mysql & ————启动mysql
在执行以下操作
Mysql启动、停止的方法
/usr/local/mysql/bin/mysqld_safe --user=mysql & 启动
mysqladmin –uroot –pxxx shutdown 停止
tail -f /var/log/mysqld.log 查看mysql的错误日志
修改 mysql监听地址为127.0.0.1
netstat -ntulp
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 28253/mysqld
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1889/sshd
默认是监听的0.0.0.0
vi /etc/my.cnf
添加一列
[mysqld]
port = 3306
socket = /tmp/mysql.socK
bind-address=127.0.0.1
# mysqladmin -uroot -p shutdow
# /usr/local/mysql/bin/mysqld_safe --user=mysql &
保存并退出
netstat -ntulp
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 29103/mysqld
————修改成功
修改 mysql的root密码
use mysql
update user set Password=PASSWORD('新密码') where User='root' and Host='localhost';
flush privileges;flush privileges;
# mysql -uroot -p
Enter password:
mysql>
————修改新密码成功
网友评论