Centos7使用wget安装PHP7、Mysql5.6、Nginx1.9

来源:互联网 发布:linux 卸载squid 编辑:程序博客网 时间:2024/05/18 02:06

Centos7.3下使用wget安装PHP7、Mysql、Nginx

前期准备

系统设置

防火墙设置

firewall-cmd --zone=public --add-port=80/tcp --permanentfirewall-cmd --zone=public --add-port=3306/tcp --permanentfirewall-cmd --reloadsystemctl 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 pcreyum 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 makeyum -y install gd gd2 gd-devel gd2-devel

下载相关应用包

wget http://nginx.org/download/nginx-1.9.9.tar.gzwget http://ftp.exim.llorien.org/pcre/pcre-8.34.tar.gzwget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.15.tar.gzwget -O php-7.1.4.tar.gz http://hk1.php.net/get/php-7.1.4.tar.gz/from/this/mirrorwget -O libmcrypt-2.5.8.tar.gz http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/downloadwget https://bitbucket.org/libgd/gd-libgd/get/gd-2.1.0.tar.gzwget ftp://xmlsoft.org/libxml2/libxml2-2.7.2.tar.gzwget http://zlib.net/zlib-1.2.11.tar.gzwget http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gzwget -O freetype-2.7.1.tar.gz https://sourceforge.net/projects/freetype/files/freetype2/2.7.1/freetype-2.7.1.tar.gz/downloadwget -O libpng-1.6.29.tar.gz https://sourceforge.net/projects/libpng/files/libpng16/1.6.29/libpng-1.6.29.tar.gz/downloadwget http://www.ijg.org/files/jpegsrc.v9.tar.gzwget http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz

开始安装

安装cmake

tar zxvf cmake-2.8.12.1.tar.gzcd cmake-2.8.12.1./configuremake && make installln -s /usr/local/bin/cmake /usr/bin/cmakecd ..

安装Mysql

编译安装

groupadd mysqluseradd -g mysql mysql -s /bin/falsetar zxvf mysql-5.6.15.tar.gzcd mysql-5.6.15cmake .makemake installcd /usr/local/mysql./scripts/mysql_install_db --user=mysqlchown -R root:mysql /usr/local/mysql/chown -R mysql dataln -s /usr/local/mysql/bin/* /usr/local/bin/cp support-files/mysql.server /etc/rc.d/init.d/mysqldchmod a+x /etc/init.d/mysqldln -s /var/lib/mysql/mysql.sock /tmp/mysql.sockcp /etc/my.cnf /etc/my.cnfbakvim /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_passwordport = 3306socket = /var/lib/mysql/mysql.sock# Here follows entries for some specific programs# The MySQL server[mysqld]port = 3306socket = /var/lib/mysql/mysql.sockskip-external-lockingkey_buffer_size = 16Mmax_allowed_packet = 1Mtable_open_cache = 64sort_buffer_size = 512Knet_buffer_length = 8Kread_buffer_size = 256Kread_rnd_buffer_size = 512Kmyisam_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 replicationlog-bin=mysql-bin# binary logging format - mixed recommendedbinlog_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 omittedserver-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]quickmax_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 = 20Msort_buffer_size = 20Mread_buffer = 2Mwrite_buffer = 2M[mysqlhotcopy]interactive-timeout

初始化密码

systemctl restart mysqldsystemctl enable mysqldmysqladmin -u root -p password "123456"

安装Nginx

pcre库安装

cd /data/soft/tar zxvf pcre-8.34.tar.gzcd pcre-8.34./configure --prefix=/usr/local/pcremake && make installcd ..

zlib库安装

tar zxvf zlib-1.2.11.tar.gzcd zlib-1.2.11./configure --prefix=/usr/local/zlibmake && make installcd .. 

nginx安装

groupadd wwwuseradd -g www www -s /bin/falsemkdir /usr/local/webservertar zxvf nginx-1.9.9.tar.gzcd 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_modulemake && make installcd ../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 0nginx="/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/nginxlockfile=/var/lock/subsys/nginxmake_dirs() {# make required directoriesuser=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`if [ -z "`grep $user /etc/passwd`" ]; thenuseradd -M -s /bin/nologin $userfioptions=`$nginx -V 2>&1 | grep 'configure arguments:'`for opt in $options; doif [ `echo $opt | grep '.*-temp-path'` ]; thenvalue=`echo $opt | cut -d "=" -f 2`if [ ! -d "$value" ]; then# echo "creating" $valuemkdir -p $value && chown -R $user $valuefifidone}start() {[ -x $nginx ] || exit 5[ -f $NGINX_CONF_FILE ] || exit 6make_dirsecho -n $"Starting $prog: "daemon $nginx -c $NGINX_CONF_FILEretval=$?echo[ $retval -eq 0 ] && touch $lockfilereturn $retval}stop() {echo -n $"Stopping $prog: "killproc $prog -QUITretval=$?echo[ $retval -eq 0 ] && rm -f $lockfilereturn $retval}restart() {#configtest || return $?stopsleep 1start}reload() {#configtest || return $?echo -n $"Reloading $prog: "killproc $nginx -HUPRETVAL=$?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" instart)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 2esac
chmod 775 /etc/rc.d/init.d/nginx/etc/rc.d/init.d/nginx restartsystemctl restart nginx.servicesystemctl enable nginx.service

安装PHP

libxml2库安装

tar zxvf libxml2-2.7.2.tar.gzcd libxml2-2.7.2./configure --prefix=/usr/local/libxml2make && make installcd ..

libmcrypt库安装

tar zxvf libmcrypt-2.5.8.tar.gzcd libmcrypt-2.5.8./configure --prefix=/usr/local/libmcryptmake && make installcd ..

libpng库安装

tar zxvf libpng-1.6.29.tar.gzcd libpng-1.6.29./configure --prefix=/usr/local/libpngmake && make installcd ..

jpegsrc库安装

tar zxvf jpegsrc.v9.tar.gzcd jpeg-9/./configure --prefix=/usr/local/jpeg9 --enable-shared --enable-staticmake && make installcd ..

freetype库安装

tar zxvf freetype-2.7.1.tar.gzcd freetype-2.7.1./configure --prefix=/usr/local/freetypemake && make installcd ..

autoconf库安装

tar zxvf autoconf-latest.tar.gzcd autoconf-2.69./configuremake && make installcd ..

gd库安装

tar zxvf gd-2.1.0.tar.gzcd libgd-gd-libgd-9f0a7e7f4f0f/cmake .make installcd ..

php安装

tar zxvf php-7.1.4.tar.gzcd 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-ctypemake && make installcp php.ini-production /usr/local/webserver/php/etc/php.inirm -rf /etc/php.iniln -s /usr/local/webserver/php/etc/php.ini /etc/php.inicp /usr/local/webserver/php/etc/php-fpm.conf.default /usr/local/webserver/php/etc/php-fpm.conf

PHP权限配置

vi /usr/local/webserver/php/etc/php-fpm.confpid = 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.confvi /usr/local/webserver/php/etc/php-fpm.d/www.confuser = www #设置php-fpm运行账号为wwwgroup = www #设置php-fpm运行组为www

设置 php-fpm开机启动

cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpmsystemctl 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 = OFF

Nginx设置

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.servicesystemctl restart nginx.servicesystemctl restart mysqld.service

使用ab进行测试

安装ab工具

yum install httpd-toolsab -c 100 -n 10000 http://localhost/

安装memcache扩展

由于php7的memcache扩展在pecl上的包都是会安装失败,所以本人在github上找到了另外的包

yum install zip unzip cd /data/soft/wget https://github.com/websupport-sk/pecl-memcache/archive/php7.zipunzip php7.zipcd pecl-memcache-php7//usr/local/webserver/php/bin/phpize./configure --with-php-config=/usr/local/webserver/php/bin/php-configmake && make install

打开 /usr/local/webserver/php/etc/php.ini 查找 ; extension_dir = “ext”
在其后增加一行:
extension = “memcache.so”

PHP性能TIPS

Opcache

sudo sysctl vm.nr_hugepages=128vi /usr/local/webserver/php/etc/php.inizend_extension=opcache.soopcache.enable=1opcache.enable_cli=1

HugePage

opcache.huge_code_pages=1

Opcache file cache

opcache.file_cache=/tmp

服务器启动与停止

#PHPsystemctl start php-fpm.service #启动systemctl stop php-fpm.service #停止systemctl restart php-fpm.service #重启#Nginxsystemctl start nginx.service #启动systemctl stop nginx.service #停止systemctl restart nginx.service #重启#MySQLsystemctl start mysqld.service #启动systemctl stop mysqld.service #停止systemctl restart mysqld.service #重启
0 0
原创粉丝点击