centos: php,mysql,apache,nginx安裝

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章