centos+openresty+mariaDB+php搭建web服务器

一。openresty

1.依赖关系

openresty依赖于perl 5.6.1+, libreadline, libpcre, libssl,首先安装依赖关系。

yum install readline-devel pcre-devel openssl-devel gcc

2.下载源码

使用wget下载

wget https://openresty.org/download/ngx_openresty-1.9.7.1.tar.gz

博主安装时最新版为1.9.7.1,可以登录http://openresty.org查看最新版本,选择需要的版本进行下载。

解压下载好的压缩包

tar xzvf ngx_openresty-1.9.7.1.tar.gz

注意将1.9.7.1替换为你下载的版本号

3. ./configure

进入 ngx_openresty-VERSION/ 目录, 然后输入以下命令配置:

./configure

默认, –prefix=/usr/local/openresty 程序会被安装到/usr/local/openresty目录。
我们可以指定各种选项,比如


./configure --prefix=/opt/openresty \
--with-luajit \
--without-http_redis2_module \
--with-http_iconv_module \
--with-http_postgres_module

具体用法参考./configure –help 或者官方文档

4.编译、安装

使用make编译

make

安装

make install

5.将nginx添加到系统变量

PATH=/usr/local/openresty/nginx/sbin:$PATH
export PATH

6.默认项目路径

/usr/local/openresty/nginx/html

7.启动、关闭、重启nginx

nginx -c /usr/local/openresty/nginx/conf/nginx.conf   //启动并加载配置文件
nginx  -s stop    //停止
nginx  -s reload    //重启

二。mariaDB

1.安装mariaDB

yum install mariadb mariadb-server net-tools

2.创建系统启动链接

systemctl enable mariadb.service
systemctl start mariadb.service

3.设置mysql密码

mysql_secure_installation

接下来屏幕会出现一系列代码,代码及操作记录如下

/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we’ll need the current
password for the root user. If you’ve just installed MariaDB, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):<– 回车
OK, successfully used password, moving on

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] <– y 回车
New password: <– 设置用户名为root的mysql密码
Re-enter new password: <– 密码确认
Password updated successfully!
Reloading privilege tables..
… Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] <– y 回车
… Success!

Normally, root should only be allowed to connect from ‘localhost’. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] <– y 回车
… Success!

By default, MariaDB comes with a database named ‘test’ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] <– y 回车
- Dropping test database…
… Success!
- Removing privileges on test database
… Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] <– y 回车
… Success!

Cleaning up…

All done! If you’ve completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

至此,mariaDB设置完毕

4.启动方式

systemctl start mariadb.service

三。php

1.安装php及相关模块

yum install php-fpm php-cli php-mysql php-gd php-ldap php-odbc php-pdo php-pecl-memcache php-pear php-mbstring php-xml php-xmlrpc php-mbstring php-snmp php-soap

2.创建启动链接

systemctl enable php-fpm.service
systemctl start php-fpm.service

3.打开nginx配置中的php

配置文件为/usr/local/openresty/nginx/conf/nginx.conf
将其中php配置项注释去掉

 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }

4.修改nginx的用户

cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.confbak #备份原有配置文件
vi /etc/php-fpm.d/www.conf #编辑
user = nginx #修改用户为nginx
group = nginx #修改组为nginx
:wq #保存退出

5.启动、重启php-fpm

systemctl start php-fpm.service  //启动
systemctl restart php-fpm.service    //重启
systemctl status php-fpm.service     //查看状态

你可能感兴趣的:(Web,centos,DB,perl,openresty,maria)