Centos7使用wget安装PHP7、Mysql5.6、Nginx1.9
2017-04-26 10:26
746 查看
Centos7.3下使用wget安装PHP7、Mysql、Nginx
前期准备
系统设置
防火墙设置
firewall-cmd --zone=public --add-port=80/tcp --permanent firewall-cmd --zone=public --add-port=3306/tcp --permanent firewall-cmd --reload systemctl restart firewalld
关闭SELINUX
vi /etc/selinux/config #SELINUX=enforcing #注释掉 #SELINUXTYPE=targeted #注释掉 SELINUX=disabled #增加 #保存退出 shutdown -r now
创建目录
mkdir -p /data/soft/ cd /data/soft/
安装相关服务
yum install wget yum install pcre yum install openssl* yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers make yum -y install gd gd2 gd-devel gd2-devel
下载相关应用包
wget http://nginx.org/download/nginx-1.9.9.tar.gz wget http://ftp.exim.llorien.org/pcre/pcre-8.34.tar.gz wget http://dev.mysql.com/get/Downloads 13e46 /MySQL-5.6/mysql-5.6.15.tar.gz wget -O php-7.1.4.tar.gz http://hk1.php.net/get/php-7.1.4.tar.gz/from/this/mirror wget -O libmcrypt-2.5.8.tar.gz http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download wget https://bitbucket.org/libgd/gd-libgd/get/gd-2.1.0.tar.gz wget ftp://xmlsoft.org/libxml2/libxml2-2.7.2.tar.gz wget http://zlib.net/zlib-1.2.11.tar.gz wget http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz wget -O freetype-2.7.1.tar.gz https://sourceforge.net/projects/freetype/files/freetype2/2.7.1/freetype-2.7.1.tar.gz/download wget -O libpng-1.6.29.tar.gz https://sourceforge.net/projects/libpng/files/libpng16/1.6.29/libpng-1.6.29.tar.gz/download wget http://www.ijg.org/files/jpegsrc.v9.tar.gz wget http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz[/code]开始安装
安装cmake
tar zxvf cmake-2.8.12.1.tar.gz cd cmake-2.8.12.1 ./configure make && make install ln -s /usr/local/bin/cmake /usr/bin/cmake cd ..安装Mysql
编译安装
groupadd mysql useradd -g mysql mysql -s /bin/false tar zxvf mysql-5.6.15.tar.gz cd mysql-5.6.15 cmake . make make install cd /usr/local/mysql ./scripts/mysql_install_db --user=mysql chown -R root:mysql /usr/local/mysql/ chown -R mysql data ln -s /usr/local/mysql/bin/* /usr/local/bin/ cp support-files/mysql.server /etc/rc.d/init.d/mysqld chmod a+x /etc/init.d/mysqld ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock cp /etc/my.cnf /etc/my.cnfbak vim /etc/my.cnf
把下面配置复制到my.cnf# Example MySQL config file for medium systems. # # This is for a system with little memory (32M - 64M) where MySQL plays # an important part, or systems up to 128M where MySQL is used together with # other programs (such as a web server) # # MySQL programs look for option files in a set of # locations which depend on the deployment platform. # You can copy this option file to one of those # locations. For information about these locations, see: # http://dev.mysql.com/doc/mysql/en/option-files.html # # In this file, you can use all long options that a program supports. # If you want to know which options a program supports, run the program # with the "--help" option. # The following options will be passed to all MySQL clients [client] #password = your_password port = 3306 socket = /var/lib/mysql/mysql.sock # Here follows entries for some specific programs # The MySQL server [mysqld] port = 3306 socket = /var/lib/mysql/mysql.sock skip-external-locking key_buffer_size = 16M max_allowed_packet = 1M table_open_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M # Don't listen on a TCP/IP port at all. This can be a security enhancement, # if all processes that need to connect to mysqld run on the same host. # All interaction with mysqld must be made via Unix sockets or named pipes. # Note that using this option without enabling named pipes on Windows # (via the "enable-named-pipe" option) will render mysqld useless! # #skip-networking # Replication Master Server (default) # binary logging is required for replication log-bin=mysql-bin # binary logging format - mixed recommended binlog_format=mixed # required unique id between 1 and 2^32 - 1 # defaults to 1 if master-host is not set # but will not function as a master if omitted server-id = 1 # Replication Slave (comment out master section to use this) # # To configure this host as a replication slave, you can choose between # two methods : # # 1) Use the CHANGE MASTER TO command (fully described in our manual) - # the syntax is: # # CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>, # MASTER_USER=<user>, MASTER_PASSWORD=<password> ; # # where you replace <host>, <user>, <password> by quoted strings and # <port> by the master's port number (3306 by default). # # Example: # # CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306, # MASTER_USER='joe', MASTER_PASSWORD='secret'; # # OR # # 2) Set the variables below. However, in case you choose this method, then # start replication for the first time (even unsuccessfully, for example # if you mistyped the password in master-password and the slave fails to # connect), the slave will create a master.info file, and any later # change in this file to the variables' values below will be ignored and # overridden by the content of the master.info file, unless you shutdown # the slave server, delete master.info and restart the slaver server. # For that reason, you may want to leave the lines below untouched # (commented) and instead use CHANGE MASTER TO (see above) # # required unique id between 2 and 2^32 - 1 # (and different from the master) # defaults to 2 if master-host is set # but will not function as a slave if omitted #server-id = 2 # # The replication master for this slave - required #master-host = <hostname> # # The username the slave will use for authentication when connecting # to the master - required #master-user = <username> # # The password the slave will authenticate with when connecting to # the master - required #master-password = <password> # # The port the master is listening on. # optional - defaults to 3306 #master-port = <port> # # binary logging - not required for slaves, but recommended #log-bin=mysql-bin # Uncomment the following if you are using InnoDB tables #innodb_data_home_dir = /var/lib/mysql #innodb_data_file_path = ibdata1:10M:autoextend #innodb_log_group_home_dir = /var/lib/mysql # You can set .._buffer_pool_size up to 50 - 80 % # of RAM but beware of setting memory usage too high #innodb_buffer_pool_size = 16M #innodb_additional_mem_pool_size = 2M # Set .._log_file_size to 25 % of buffer pool size #innodb_log_file_size = 5M #innodb_log_buffer_size = 8M #innodb_flush_log_at_trx_commit = 1 #innodb_lock_wait_timeout = 50 [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash # Remove the next comment character if you are not familiar with SQL #safe-updates [myisamchk] key_buffer_size = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout初始化密码
systemctl restart mysqld systemctl enable mysqld mysqladmin -u root -p password "123456"安装Nginx
pcre库安装
cd /data/soft/ tar zxvf pcre-8.34.tar.gz cd pcre-8.34 ./configure --prefix=/usr/local/pcre make && make install cd ..zlib库安装
tar zxvf zlib-1.2.11.tar.gz cd zlib-1.2.11 ./configure --prefix=/usr/local/zlib make && make install cd ..nginx安装
groupadd www useradd -g www www -s /bin/false mkdir /usr/local/webserver tar zxvf nginx-1.9.9.tar.gz cd nginx-1.9.9 ./configure --prefix=/usr/local/webserver/nginx --user=www --group=www --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-pcre=/data/soft/pcre-8.34 --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module make && make install cd .. /usr/local/webserver/nginx/sbin/nginx
配置nginx服务vi /etc/rc.d/init.d/nginx#!/bin/sh # # nginx - this script starts and stops the nginx daemon # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server # processname: nginx # config: /etc/nginx/nginx.conf # config: /usr/local/webserver/nginx/conf/nginx.conf # pidfile: /usr/local/webserver/nginx/logs/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/local/webserver/nginx/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/usr/local/webserver/nginx/conf/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx make_dirs() { # make required directories user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -` if [ -z "`grep $user /etc/passwd`" ]; then useradd -M -s /bin/nologin $user fi options=`$nginx -V 2>&1 | grep 'configure arguments:'` for opt in $options; do if [ `echo $opt | grep '.*-temp-path'` ]; then value=`echo $opt | cut -d "=" -f 2` if [ ! -d "$value" ]; then # echo "creating" $value mkdir -p $value && chown -R $user $value fi fi done } start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 make_dirs echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { #configtest || return $? stop sleep 1 start } reload() { #configtest || return $? echo -n $"Reloading $prog: " killproc $nginx -HUP RETVAL=$? echo } force_reload() { restart } configtest() { $nginx -t -c $NGINX_CONF_FILE } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 ;; reload) rh_status_q || exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2 esacchmod 775 /etc/rc.d/init.d/nginx /etc/rc.d/init.d/nginx restart systemctl restart nginx.service systemctl enable nginx.service安装PHP
libxml2库安装
tar zxvf libxml2-2.7.2.tar.gz cd libxml2-2.7.2 ./configure --prefix=/usr/local/libxml2 make && make install cd ..libmcrypt库安装
tar zxvf libmcrypt-2.5.8.tar.gz cd libmcrypt-2.5.8 ./configure --prefix=/usr/local/libmcrypt make && make install cd ..libpng库安装
tar zxvf libpng-1.6.29.tar.gz cd libpng-1.6.29 ./configure --prefix=/usr/local/libpng make && make install cd ..jpegsrc库安装
tar zxvf jpegsrc.v9.tar.gz cd jpeg-9/ ./configure --prefix=/usr/local/jpeg9 --enable-shared --enable-static make && make install cd ..freetype库安装
tar zxvf freetype-2.7.1.tar.gz cd freetype-2.7.1 ./configure --prefix=/usr/local/freetype make && make install cd ..autoconf库安装
tar zxvf autoconf-latest.tar.gz cd autoconf-2.69 ./configure make && make install cd ..gd库安装
tar zxvf gd-2.1.0.tar.gz cd libgd-gd-libgd-9f0a7e7f4f0f/ cmake . make install cd ..php安装
tar zxvf php-7.1.4.tar.gz cd php-7.1.4 ./configure --prefix=/usr/local/webserver/php --with-config-file-path=/usr/local/webserver/php/etc --with-mcrypt=/usr/local/libmcrypt --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/var/lib/mysql/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd --with-libxml-dir=/usr/local/libxml2 --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg9 --with-freetype-dir=/usr/local/freetype --with-iconv --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-curl --enable-ctype make && make install cp php.ini-production /usr/local/webserver/php/etc/php.ini rm -rf /etc/php.ini ln -s /usr/local/webserver/php/etc/php.ini /etc/php.ini cp /usr/local/webserver/php/etc/php-fpm.conf.default /usr/local/webserver/php/etc/php-fpm.confPHP权限配置
vi /usr/local/webserver/php/etc/php-fpm.conf pid = run/php-fpm.pid #取消前面的分号保存退出 cp /usr/local/webserver/php/etc/php-fpm.d/www.conf.default /usr/local/webserver/php/etc/php-fpm.d/www.conf vi /usr/local/webserver/php/etc/php-fpm.d/www.conf user = www #设置php-fpm运行账号为www group = www #设置php-fpm运行组为www设置 php-fpm开机启动
cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm systemctl enable php-fpm.service相关配置
PHP设置
vi /usr/local/webserver/php/etc/php.ini #禁用函数 disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname #时区 date.timezone = PRC #禁止显示php版本的信息 expose_php = OFFNginx设置
cd /usr/local/webserver/nginx/conf/ vi nginx.conf #首行user去掉注释,修改Nginx运行组为www www;必须与/usr/local/webserver/php/etc/php-fpm.conf中的user,group配置相同,否则php运行出错 user www www; #取消FastCGI server部分location的注释,注意fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径 location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } #添加加载网站配置文件添加在最后一个大括号里面 include /usr/local/webserver/nginx/conf/vhost/*;重启服务
systemctl restart php-fpm.service systemctl restart nginx.service systemctl restart mysqld.service使用ab进行测试
安装ab工具
yum install httpd-tools ab -c 100 -n 10000 http://localhost/[/code]安装memcache扩展
由于php7的memcache扩展在pecl上的包都是会安装失败,所以本人在github上找到了另外的包yum install zip unzip cd /data/soft/ wget https://github.com/websupport-sk/pecl-memcache/archive/php7.zip unzip php7.zip cd pecl-memcache-php7/ /usr/local/webserver/php/bin/phpize ./configure --with-php-config=/usr/local/webserver/php/bin/php-config make && make install
打开 /usr/local/webserver/php/etc/php.ini 查找 ; extension_dir = “ext”
在其后增加一行:
extension = “memcache.so”PHP性能TIPS
Opcache
sudo sysctl vm.nr_hugepages=128 vi /usr/local/webserver/php/etc/php.ini zend_extension=opcache.so opcache.enable=1 opcache.enable_cli=1HugePage
opcache.huge_code_pages=1Opcache file cache
opcache.file_cache=/tmp服务器启动与停止
#PHP systemctl start php-fpm.service #启动 systemctl stop php-fpm.service #停止 systemctl restart php-fpm.service #重启 #Nginx systemctl start nginx.service #启动 systemctl stop nginx.service #停止 systemctl restart nginx.service #重启 #MySQL systemctl start mysqld.service #启动 systemctl stop mysqld.service #停止 systemctl restart mysqld.service #重启
相关文章推荐
- CentOS7使用yum安装MySQL5.6
- 详解如何在CentOS7中使用Nginx和PHP7-FPM安装Nextcloud
- 阿里云Centos7使用yum安装MySQL5.6的正确姿势
- 阿里云Centos7使用yum安装MySQL5.6的正确姿势
- centos7 yum安装 nginx php7 php-fpm mysql
- 阿里云Centos7使用yum安装MySQL5.6
- Centos7使用yum安装MySQL5.6
- 阿里云Centos7使用yum安装MySQL5.6--未测试
- 阿里云Centos7使用yum安装MySQL5.6的正确姿势
- 阿里云Centos7使用yum安装MySQL5.6
- 阿里云Centos7使用yum安装MySQL5.6
- Linux学习笔记-CentOS7安装nginx、PHP7、MySQL
- 阿里云Centos7使用yum安装MySQL5.6的正确姿势
- 使用cacti + snmp 实现对apache 、mysql 、 nginx 的监控的安装和配置
- centos7,nginx1.12.2,php7,mysql5.7.20
- Centos7下安装mysql5.6需要注意的点
- CentOS 7源码编译安装PHP5.6和Nginx1.7.9及MySQL(搭建LNMP环境)
- Centos7上使用官方YUM源安装Mysql
- 10038---CentOS7下安装Mysql失败经历--CentOS7使用yum安装和卸载Mysql过程
- liunx下使用yum安装mysql5.6