搭建阿里云服务器环境(OpenResty+PHP 7+MySQL5.7)
本人第一次搭建,已经搭建成功并能访问,希望给新手带来一些帮助,
若有不对的地方还希望给我指出来,谢谢。
-
1.安装编译工具
-
1.1 命令:
yum install gcc-c++ cmake
-
1.2
安装Boost(
从MySQL5.7.5开始,需要用上)
资源包 https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.bz2
( 养成一个好习惯下载的文件统一放在一个地方cd /usr/local/src 用wget命令) -
1.3 解压并复制
tar -jxvf boost_1_59_0.tar.bz2
cp -r boost_1_59_0/usr/local
-
2.安装MySQL
-
使用下面的命令检查是否安装有MySQL Server
rpm -qa | grep mysql
我的阿里云服务器本身有一个mysql-libs-5.1.73-8.el6_8.x86_64,所以我就没有重复安装了。
-
3.安装PHP7
-
3.1 资源包
-
3.2 解压并进入软件包:
tar xvzf php-7.0.5.tar.gz
cd php-7.0.5 -
3.3 编译安装
命令1: ./configure –prefix=/usr/local/php705 –with-curl –with-freetype-dir –with-gd –with-gettext –with-iconv-dir –with-kerberos –with-libdir=lib64 –with-libxml-dir –with-mysqli –with-openssl –with-pcre-regex –with-pdo-mysql –with-pdo-sqlite –with-pear –with-png-dir –with-xmlrpc –with-xsl –with-zlib –enable-fpm –enable-bcmath –enable-libxml –enable-inline-optimization –enable-gd-native-ttf –enable-mbregex –enable-mbstring –enable-opcache –enable-pcntl –enable-shmop –enable-soap –enable-sockets –enable-sysvsem –enable-xml –enable-zip
命令2: make && make install -
3.4 复制出配置文件
cp /usr/local/php705/etc/php-fpm.conf.default /usr/local/php705/etc/php-fpm.conf
cp /usr/local/php705/etc/php-fpm.d/www.conf.default /usr/local/php705/etc/php-fpm.d/www.conf
cp /usr/local/src/php-7.0.5/php.ini-production /usr/local/php705/lib/php.ini在此有个小插曲:我当时按着之前php版本路径去找php.ini没有找到。
用命令:find / -name ‘php.ini-production’ -
3.4 安装依赖
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel mysql-devel pcre-devel libxslt-devel curl-devel openssl-devel
-
3.5 解压并进入软件包
tar xvzf php-7.0.5.tar.gz
cd php-7.0.5 -
3.6 启动php-fpm
/usr/local/php705/sbin/php-fpm
若无报错,则说明启动成功
若报错请跳转至 http://blog.csdn.net/weixin_38450689/article/details/75142405
-
4.OpenResty1.9.7.4
-
4.1 资源包
-
4.2 安装依赖
yum install readline-devel pcre-devel openssl-devel
-
4.3 解压并进入软件包
tar xvzf openresty-1.9.7.4.tar.gz
cd openresty-1.9.7.4 -
4.4 编译安装
命令1: ./configure –prefix=/usr/local/openresty1974
命令2:gmake && gmake install -
4.5 启动nginx
/usr/local/openresty1974/nginx/sbin/nginx
若无报错,则说明启动成功
若报错请跳转至 http://blog.csdn.net/weixin_38450689/article/details/75142404
-
5. 安装memcache扩展
-
5.1 下载php7专用扩展包
-
5.2 解压并进入软件包
unzip php7
cd pecl-memcache-php7 -
5.3 编译安装
命令1: ./configure –with-php-config=/usr/local/php705/bin/php-config
命令2: make && make install -
5.4 修改php.ini
vim /usr/local/php705/lib/php.ini
加入下面这行
extension=memcache.so -
5.5 检查是否成功
/usr/local/php705/bin/php -m
若有memcache,则说明安装成功
-
6.配置Nginx
-
6.1 备份配置文件
cp -a /usr/local/openresty1974/nginx/conf/nginx.conf
/usr/local/openresty1974/nginx/conf/nginx.conf.bak -
6.2 打开配置文件
vim /usr/local/openresty1974/nginx/conf/nginx.conf
将里面server{ }块全部删掉,在最后的}前include 你自己的配置文件路径 例如:/usr/local/openresty1974/nginx/conf/*.conf -
6.3 写自己的配置文件
最好写在/usr/local/openresty1974/nginx/conf/这个目录下 例如:test.conf
vim /usr/local/openresty1974/nginx/conf/test.conf 里面加入以下内容:
server {
listen 80;
server_name test.com;
root your project;
index index.html index.htm index.php;
charset utf-8;
location ~ \.php${
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
}
}