apache2
wget http://mirrors.sohu.com/apache/httpd-2.4.12.tar.gz
tar -zxvf httpd-2.4.12.tar.gz
cd httpd-2.4.12
cd httpd-2.4.12
./configure --prefix=/usr/local/apache2 --enable-module=shared --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre
启动,重启和停止
/usr/local/apache/bin/apachectl -k start
(不加参数k也行)
/usr/local/apache/bin/apachectl -k restart
/usr/local/apache/bin/apachectl -k stop
启动过程中会提示程序“apachectl”尚未安装。 您可以使用以下命令安装: sudo apt-getinstall apache2.2-common 然后在终端输入 sudoapt-get installapache2.2-common 完成后就可以启动了。启动的时候要用sudo 否则会报 (13)Permissiondenied: AH00072: make_sock: could not bind to address 0.0.0.0:80nolistening sockets available错误。还有一个解决办法是 Edit the config fileto change the port Apache uses to a number greater than 1024.
简单启动apache命令
配置文件
gedit /usr/local/apache/conf/httpd.conf
修改以下配置(当然这些修改是最基本的修改,如果要更高级的,参照其他Ubuntuapache配置手册)
找到:
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
在后面添加:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
找到:
DirectoryIndex index.html
在下面添加:
DirectoryIndex index.html index.php
找到:
#ServerName www.example.com:80
修改为:
ServerName 127.0.0.1:80或者ServerNamelocalhost:80
记得要去掉前面的“#”
否则会出现以下错误提示:
httpd: Could not reliably determine theserver's fully qualified domain name, using 127.0.1.1 forServerName
安装mysql
wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.25.tar.gz
tar -zxvf mysql-5.6.25.tar.gz
cd mysql-5.6.25
sudo apt-get install cmake 安装cmake
sudo apt-get install openssl sudo apt-get install libssl-dev RedHat、centos才是openssl-devel 安装 ncurses sudo apt-get install libncurses5-dev
sudo vim /etc/my.cnfcmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 make -j 2 && make install
添加mysql用户
参考配置sudo groupadd mysql sudo useradd -s /sbin/nologin -M -g mysql mysql
# Example MySQL config file for medium systems.
# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock
default-character-set=utf8mb4
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
bind-address=127.0.0.1
port = 3306
socket = /tmp/mysql.sock
datadir = /usr/local/mysql/var
collation-server = utf8mb4_general_ci
character-set-server = utf8mb4
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
# 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 # Uncomment the following if you are using InnoDB tables innodb_data_home_dir = /usr/local/mysql/var innodb_data_file_path = ibdata1:10M:autoextend innodb_log_group_home_dir = /usr/local/mysql/var # 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 default-character-set=utf8mb4 [myisamchk] key_buffer_size = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout
初始化
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var --user=mysql
chown -R mysql /usr/local/mysql/var
chgrp -R mysql /usr/local/mysql/.
cp support-files/mysql.server /etc/init.d/mysql
chmod 755 /etc/init.d/mysql
cat > /etc/ld.so.conf.d/mysql.conf<<EOF
/usr/local/mysql/lib
/usr/local/lib
EOF
ldconfig
启动
/etc/init.d/mysql start
5.6 报错
Failed to issue method call: Unit mysql.service failed to load: No such file or directory. See system logs and 'systemctl status mysql.service' for details.
解决方法
# systemctl enable mysql.service
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
ln -s /usr/local/mysql/bin/mysqldump /usr/bin/mysqldump
ln -s /usr/local/mysql/bin/myisamchk /usr/bin/myisamchk
ln -s /usr/local/mysql/bin/mysqld_safe /usr/bin/mysqld_safe
可以登录了
mysql -u root
修改密码
use mysql;
update user set password=password('$mysqlrootpwd') where user='root';
flush privileges;
安装php
php 源码编译
chinaunix.net
tar -zxvf libiconv-1.14.tar.gzcd libiconv-1.14./configuremake -j 2wget http://down1.chinaunix.net/distfiles/libiconv-1.14.tar.gz
报错
gcc -DHAVE_CONFIG_H -DEXEEXT=\"\" -I. -I.. -I../lib -I../intl -DDEPENDS_ON_LIBICONV=1 -DDEPENDS_ON_LIBINTL=1 -g -O2 -c -o width.o `test -f 'uniwidth/width.c' || echo './'`uniwidth/width.c
In file included from progname.c:26:0:
./stdio.h:1010:1: 错误: ‘gets’未声明(不在函数内)
gcc -DHAVE_CONFIG_H -DEXEEXT=\"\" -I. -I.. -I../lib -I../intl -DDEPENDS_ON_LIBICONV=1 -DDEPENDS_ON_LIBINTL=1 -g -O2 -c xmalloc.c
make[2]: *** [progname.o] 错误 1
make[2]: *** 正在等待未完成的任务....
make[2]:正在离开目录 `/home/lenky/下载/libiconv-1.14/srclib'
make[1]: *** [all] 错误 2
make[1]:正在离开目录 `/home/lenky/下载/libiconv-1.14/srclib'
make: *** [all] 错误 2
解决方法:
lenky@robert-T430S:~/下载/libiconv-1.14$ vi srclib/stdio.h
到1010行,注释掉该行即可:
_GL_CXXALIASWARN (gets);
/* It is very rare that the developer ever has full control of stdin,
so any use of gets warrants an unconditional warning. Assume it is
always declared, since it is required by C89. */
//_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
#endif
重新make,OK。
&& make installcd ..
wget http://down1.chinaunix.net/distfiles/libmcrypt-2.5.7.tar.gz
tar -zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure
make -j 2&& make install
ldconfig
cd libltdl/
./configure --enable-ltdl-install
make && make install
cd ../../
wget http://down1.chinaunix.net/distfiles/mhash-0.9.3.tar.gz
tar -zxvf mhash-0.9.3.tar.gz
cd mhash-0.9.3
./configure
make -j 2 && make install
cd ../
wget http://mirrors.sohu.com/php/php-5.6.9.tar.gz
tar -zxvf php-5.6.9.tar.gz
cd php-5.6.9
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo make -j 2 ZEND_EXTRA_LIBS='-liconv'
Ubuntu安装php即常见错误解决方法
参考 http://blog.sina.com.cn/s/blog_7718e4430101li7a.html 报错 configure: error: jpeglib.h not foundsudo apt-get install libjpeg-dev解决方法
错误:
configure: error: png.h not found.
解决办法:
# sudo apt-get install libpng-dev
错误:
configure: error: freetype.h not found.
解决办法:
# sudo apt-get install libfreetype6-dev
make install
cp php.ini-production /usr/local/php/etc/php.ini sed -i 's/post_max_size = 8M/post_max_size = 50M/g' /usr/local/php/etc/php.ini sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /usr/local/php/etc/php.ini sed -i 's/;date.timezone =/date.timezone = PRC/g' /usr/local/php/etc/php.ini sed -i 's/short_open_tag = Off/short_open_tag = On/g' /usr/local/php/etc/php.ini sed -i 's/; cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /usr/local/php/etc/php.ini sed -i 's/; cgi.fix_pathinfo=0/cgi.fix_pathinfo=0/g' /usr/local/php/etc/php.ini sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /usr/local/php/etc/php.ini sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /usr/local/php/etc/php.ini sed -i 's/register_long_arrays = On/;register_long_arrays = On/g' /usr/local/php/etc/php.ini sed -i 's/magic_quotes_gpc = On/;magic_quotes_gpc = On/g' /usr/local/php/etc/php.ini sed -i 's/disable_functions =.*/disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server/g' /usr/local/php/etc/php.ini
后期配置
ln -s /usr/local/php/bin/php /usr/bin/php ln -s /usr/local/php/bin/phpize /usr/bin/phpize ln -s /usr/local/php/sbin/php-fpm /usr/bin/php-fpm cd ..
mkdir -p /usr/local/zend/
wget http://downloads.zend.com/guard/5.5.0/ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz
tar -zxvf ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz
cp ZendGuardLoader-php-5.3-linux-glibc23-x86_64/php-5.3.x/ZendGuardLoader.so /usr/local/zend/
cat >>/usr/local/php/etc/php.ini<<EOF
;eaccelerator
;ionCube
[Zend Optimizer]
zend_extension=/usr/local/zend/ZendGuardLoader.so
zend_loader.enable=1
zend_loader.disable_licensing=0
zend_loader.obfuscation_level_support=3
zend_loader.license_path=
EOF
cd ..
cat >/usr/local/php/etc/php-fpm.conf<<EOF [global] pid = /usr/local/php/var/run/php-fpm.pid error_log = /usr/local/php/var/log/php-fpm.log log_level = notice [www] listen = /tmp/php-cgi.sock listen.backlog = -1 listen.allowed_clients = 127.0.0.1 listen.owner = www listen.group = www listen.mode = 0666 user = www group = www pm = dynamic pm.max_children = 10 pm.start_servers = 2 pm.min_spare_servers = 1 pm.max_spare_servers = 6 request_terminate_timeout = 100 request_slowlog_timeout = 0 slowlog = var/log/slow.log EOF
创建php-fpm启动脚本
vim /etc/init.d/php-fpm chmod +x /etc/init.d/php-fpm
以下是一份参考:
#! /bin/sh
### BEGIN INIT INFO
# Provides: php-fpm
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts php-fpm
# Description: starts the PHP FastCGI Process Manager daemon
### END INIT INFO
prefix=/usr/local/php
exec_prefix=${prefix}
php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=${prefix}/var/run/php-fpm.pid
php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"
wait_for_pid () {
try=0
while test $try -lt 35 ; do
case "$1" in
'created')
if [ -f "$2" ] ; then
try=''
break
fi
;;
'removed')
if [ ! -f "$2" ] ; then
try=''
break
fi
;;
esac
echo -n .
try=`expr $try + 1`
sleep 1
done
}
case "$1" in
start)
echo -n "Starting php-fpm "
$php_fpm_BIN --daemonize $php_opts
if [ "$?" != 0 ] ; then
echo " failed"
exit 1
fi
wait_for_pid created $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
stop)
echo -n "Gracefully shutting down php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -QUIT `cat $php_fpm_PID`
wait_for_pid removed $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed. Use force-quit"
exit 1
else
echo " done"
fi
;;
force-quit)
echo -n "Terminating php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -TERM `cat $php_fpm_PID`
wait_for_pid removed $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
restart)
$0 stop
$0 start
;;
reload)
echo -n "Reload service php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -USR2 `cat $php_fpm_PID`
echo " done"
;;
*)
echo "Usage: $0 {start|stop|force-quit|restart|reload}"
exit 1
;;
esac
启动
groupadd www
useradd -s /sbin/nologin -g www www
/etc/init.d/php-fpm start