安装PHP
安装PHP相关依赖
yum install enchant enchant-devel gmp-devel libc-client libc-client-devel pam-devel firebird-devel libicu-devel openldap openldap-devel libmcrypt-devel unixODBC-devel freetds freetds-devel
yum install -y gcc gcc-c++ make cmake bison autoconf wget lrzsz
yum install -y libtool libtool-ltdl-devel
yum install -y freetype-devel libjpeg.x86_64 libjpeg-devel libpng-devel gd-devel
yum install -y python-devel patch sudo
yum install -y openssl* openssl openssl-devel ncurses-devel
yum install -y bzip* bzip2 unzip zlib-devel
yum install -y libevent*
yum install -y libxml* libxml2-devel
yum install -y libcurl* curl-devel
yum install -y readline-devel
make && make install && make clean
源码安装
wget http://cn2.php.net/distributions/php-7.0.12.tar.gz
tar xzf php-7.0.12.tar.gz
cd cd php-7.0.12
./configure --prefix=/usr/local/php --with-config-file-scan-dir=/usr/local/php/etc/ --enable-inline-optimization --enable-session --enable-fpm --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pdo-sqlite --with-sqlite3 --with-gettext --enable-mbregex --enable-mbstring --enable-xml --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-xmlrpc --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-curlwrappers --with-zlib --enable-zip --with-bz2 --with-gd --enable-gd-native-ttf --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-readline
make
make install && make clean
ln -s /usr/local/php/bin/php /usr/local/bin/php
ln -s /usr/local/php/sbin/php-fpm /usr/local/bin/php-fpm
php -v
PHP 7.0.12 (cli) (built: Oct 24 2016 22:29:41) ( NTS )
PHP 5.6及以上已经内置了php-fpm,不需要再使用外挂的方式安装php-fpm。只需要编译时加上“--enable-fpm”参数即可。
以上为只标注了部份php扩展,如需打开全部扩展,可以使用"--enable-all",如若需要查看具体参数说明,可通过如下命令查看:
> ./configure --help
错误处理
ext/date/php_date.lo' is not a valid libtool object
./configure 后,直接make可能会出现libtool: link: 'ext/date/php_date.lo' is not a valid libtool object 的错误。 make clean 一下然后再make,即可。原因未知,可能是某些脚本执行顺序的问题?做个标记~
配置PHP
A,配置php.ini文件
cp /root/php-7.0.12/php.ini-production /usr/local/php/etc/php.ini
vim /usr/local/php/etc/php.ini
> display_errors=Off
> default_time_zone=Asia/Chongqing
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
#### B,启动php-fpm
> # /usr/local/php/sbin/php-fpm -D
安装 nginx
安装依赖
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
源码安装
wget http://nginx.org/download/nginx-1.11.5.tar.gz
tar xzf nginx-1.11.5.tar.gz
cd nginx-1.11.5
./configure \
--prefix=/usr/local/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-file-aio \
--with-ipv6 \
--with-pcre
make
make install && make clean
nginx -v
nginx version: nginx/1.11.5
vim /usr/local/nginx/nginx.conf
#/usr/sbin/groupadd -f nginx
#/usr/sbin/useradd -g nginx nginx
错误处理
nginx安装 nginx: [emerg] getpwnam(“www”) failed 错误 参考
linux 64系统中安装nginx1.3时如果出现错误:nginx: [emerg] getpwnam(“www”) failed
- 解决方法1: 在nginx.conf中 把user nobody的注释去掉既可
- 解决方法2: 错误的原因是没有创建nginx这个用户,应该在服务器系统中添加nginx用户组和用户nginx,如下命令:
#/usr/sbin/groupadd -f nginx
#/usr/sbin/useradd -g nginx nginx
安装 Mysql
安装依赖
yum -y install make gcc-c++ cmake bison-devel ncurses-devel perl
wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
tar xzf boost_1_59_0.tar.gz
cd boost_1_59_0
./bootstrap.sh
./b2 install --prefix=/usr/local/boost
# 创建用户,组
groupadd mysql
mkdir /home/mysql #自定义位置
mkdir /home/mysql/data #自定义位置
useradd -g mysql -d /home/mysql mysql
下载安装
安装5.7*版本没有搞好
wget https://github.com/mysql/mysql-server/archive/mysql-5.6.34.tar.gz
tar xzf mysql-5.7.15.tar.gz
cd mysql-server-mysql-5.7.15
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/home/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost
make && make install
初始化数据库
进入安装补录下的bin目录下,执行
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/home/mysql/data
注:默认密码为空
调整配置文件和环境变量参数
将默认生成的my.cnf备份
> mv /etc/my.cnf /etc/my.cnf.bak
> cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
# 如下是我修改配置文件/etc/my.cnf, 用于设置编码为utf8以防乱码
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
[client]
default-character-set=utf8
# 复制启动脚本到init.d下
> cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# 增加执行权限
> chmod 755 /etc/init.d/mysqld
# 创建mysql命令文件
> ln -s /usr/local/mysql/bin/mysql /usr/sbin/mysql
注:没有这个文件就没有mysql命令,不能在任意位置使用mysql 访问数据库
启动mysql
service mysqld start
访问数据库
mysql -uroot -p
修改默认密码
use mysql; update user set password=PASSWORD("123456") where user='root';
创建超级用户
GRANT ALL PRIVILEGES ON . TO 'admin'@'localhost' IDENTIFIED BY '123456' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON pengshi_develop.* TO 'admin'@'localhost' IDENTIFIED BY '123456' WITH GRANT OPTION; GRANT ALL PRIVILEGES ON pengshi_develop.* TO 'admin'@'127.0.0.1' IDENTIFIED BY '123456' WITH GRANT OPTION;
配置开机启动
vim /etc/rc.d/rc.local
# 添加如下参数
/usr/sbin/nginx
/usr/local/bin/php-fpm -D
service mysqld start
# 然后
chmod +x /etc/rc.d/rc.local