centos: php,mysql,apache,nginx安装

2 篇文章 0 订阅
1 篇文章 0 订阅

1. 装apache: yum install httpd

   查看安装的内容:rpm -ql httpd | less

  启动apache:systemctl start httpd

源码安装: 

1.准备环境

centos7最小化安装

yum安装wget、vim、gcc、gcc-c++、cmake

2.安装apache2.4.10

官网:http://httpd.apache.org/

下载源码包:

]# cd /usr/loca/src

]# wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.10.tar.gz

下载apache组件apr、apr-util:

]# wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.10-deps.tar.gz

安装apr和apr-util:

]# tar zxvf httpd-2.4.10-deps.tar.gz

]# cd httpd-2.4.10/srclib/apr

]# ./configure --prefix=/usr/local/apr

]# make && make install

]# cd ../apr-util

]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

下载安装zlib1.2.8

]# wget http://zlib.net/zlib-1.2.8.tar.gz

]# tar zxvf zlib-1.2.8.tar.gz

]# cd zlib-1.2.8

]# ./configure --prefix=/usr/local/zlib

]# make && make install

下载安装pcre8.35

]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz

]# tar zxvf pcre-8.35.tar.gz

]# cd pcre-8.35

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

]# make && make install

下载openssl,安装apache2.4.9时提示openssl版本过低,centos7自带版本openssl1.0.1e:

]# wget http://www.openssl.org/source/openssl-1.0.1h.tar.gz

不卸载系统自带openssl,直接源码编译openssl1.0.1h

]# tar zxvf openssl-1.0.1h.tar.gz

]# cd openssl-1.0.1h

]# ./configure --prefix=/usr/local/openssl

]# make && make install

]# mv /usr/bin/openssl /usr/bin/openssl.1.0.1e

]# ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl

安装httpd2.4.9:

]# cd /usr/local/src

]# tar zxvf httpd-2.4.9.tar.gz

]# cd httpd-2.4.9

]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-cgi --enable-ssl --enable-rewrite --with-ssl=/usr/local/openssl --with-pcre=/usr/local/pcre --with-z=/usr/local/zlib --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-ssl=/usr/local/openssl --enable-modules=most --enable-mpms-shared=all --with-mpm=event
]# make && make install

 2 安装网络工具:yum install net-tools

3 关闭防火墙:systemctl stop firewalld

4 网卡:/etc/sysconfig/netword-scripts/ifcfg-ens32

多网卡配置

centos6的网卡重启方法:service network restart
centos7的网卡重启方法:systemctl restart network

DNS配置文件:cat /etc/resolv.conf
设置主机和IP绑定信息:cat /etc/hosts
设置主机名:cat /etc/hostname

安装mysql:

]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
]# yum -y install mysql57-community-release-el7-10.noarch.rpm
]# yum -y install mysql-community-server
]# systemctl start  mysqld.service
]# systemctl status mysqld.service
]# grep "password" /var/log/mysqld.log 获取临时密码
]# mysql -uroot -p
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
授权:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
mysql> FLUSH  PRIVILEGES;

安装php7.3

]# sudo wget http://cn2.php.net/distributions/php-7.3.0.tar.gz
]# mkdir /usr/local/php7.3  #创建安装目录
]# tar php-7.3.0.tar.gz  #解压
]# cd php-7.3.0   #进入解压目录
]# ./configure --enable-fpm --prefix=/usr/local/php7.3 --with-config-file-path=/usr/local/php7.3/etc --with-apxs=/usr/local/apache/bin/apxs --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-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-openssl --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip
# 会报各种错,需要安装相应的库
]# make && make install
]# ps -ef|grep php-fpm #php进程的查看

配置php7-fpm:

 # /etc/init.d/php7-fpm
 set -e
 PHPVERSION=php7.3
 NAME=php7-fpm
 DAEMON=/usr/local/$PHPVERSION/sbin/php-fpm
 
 CONFIGFILE=/usr/local/$PHPVERSION/etc/php-fpm.conf
 PIDFILE=/usr/local/$PHPVERSION/var/run/php-fpm.pid
 SCRIPTNAME=/etc/init.d/$NAME
 
 test -x $DAEMON || exit 0
 d_start(){
   $DAEMON || echo -n "already running"
 }
 
 d_stop(){
   kill -INT `cat $PIDFILE` || echo -n " not running"
 }
 
 d_reload(){
   kill -USR2 `cat $PIDFILE` || echo -n " not running"
 }
 
 case "$1" in
   start)
     echo -n "Starting $NAME is success"
     d_start
     echo "."
     ;;
   stop)
     echo -n "Stopping $NAME is success"
     d_stop
     echo "."
     ;;
   restart)
     echo -n "Restarting $NAME is success"
     d_stop
     sleep 1
     d_start
     echo "."
     ;;
 *)
     echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}"
     exit 3
     ;;
 esac

php-fpm配置:/usr/local/php7.3/etc/php-fpm.d/www.conf

# httpd.cong中需要用到
listen = 127.0.0.1:9001

启动php7-fpm:service php7-fpm start

或 /etc/init.d/php7-fpm start

apache  php7:

# /usr/local/apache/conf/httpd.conf

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
LoadModule rewrite_module modules/mod_rewrite.so


AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

<FilesMatch \.php$>
    SetHandler "proxy:fcgi://localhost:9001"
</FilesMatch>

安装nginx:

$ wget http://nginx.org/download/nginx-1.4.2.tar.gz
$ tar -zxvf nginx-1.4.2.tar.gz
$ cd nginx-1.4.2
$ ./configure \
--prefix=/usr/local/nginx \
--sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--with-http_ssl_module \
--with-pcre=../pcre-8.3.8 \   #包文件位置
--with-zlib=../zlib-1.2.11 \  #包文件位置
--with-openssl=../openssl-1.0.1h #包文件位置
$ sudo make
$ sudo make install

配置nginx-PHP,

# /usr/local/nginx/nginx.conf
user  root root;
http {
     include       mime.types;
     default_type  application/octet-stream;
 
     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
     #                  '$status $body_bytes_sent "$http_referer" '
     #                  '"$http_user_agent" "$http_x_forwarded_for"';
 
     #access_log  logs/access.log  main;
 
     sendfile        on;
     #tcp_nopush     on;
 
     #keepalive_timeout  0;
     keepalive_timeout  65;
 
     #gzip  on;
 
     server {
         listen       80;
         server_name  localhost;
        # root /var/www/test;
         #charset koi8-r;
 
         #access_log  logs/host.access.log  main;
 
         location / {
             root   html;
             #root   /var/www/test;
             index  index.php index.html index.htm;
             fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 
             try_files $uri $uri/ /index.php$is_args$query_string;
         }
         #error_page  404              /404.html;
 
         # redirect server error pages to the static page /50x.html
         #
         error_page   500 502 503 504  /50x.html;
         location = /50x.html {
             #root   /var/www/test;
             root   html;
         }
 
         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
         #
         #location ~ \.php$ {
         #    proxy_pass   http://127.0.0.1;
         #}
 
         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
         #
         location ~ \.php$ {
             #root           /var/www/test;
             root           html;
             fastcgi_pass   127.0.0.1:9001; #对应php-fpm的监听地址端口
             fastcgi_index  index.php;
         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
             include        fastcgi_params;
 
             try_files $uri $uri/ /index.php$is_args$query_string;
         }
 
         # deny access to .htaccess files, if Apache's document root
         # concurs with nginx's one
         #
         #location ~ /\.ht {
         #    deny  all;
         #}
     }
}
# /usr/local/php7.3/etc/php-fpm.d/www.conf
user root
group root

nginx与php-fpm的权限要一样

centos切换默认PHP版本:$ export PATH=/usr/local/php/bin:$PATH

nginx启动:

$ cd /usr/local/nginx
$ ./nginx

重启:./nginx -s reload

在给php添加模块时,添加成功了,但是显示不出来,没有其他办法时,执行:make clean,然后再编译。

 

https://yq.aliyun.com/articles/603862

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值