准备工作
$ yum -y install gcc gcc-c++ make
安装apache
$ yum -y install openssl openssl-devel zlib zlib-devel pcre pcre-devel
$ tar -zxf httpd-2.4.7.tar.gz
$ tar -zxf apr-1.4.6.tar.gz
$ tar -zxf apr-util-1.4.1.tar.gz
$ cp -r apr-1.4.6 httpd-2.4.7/srclib/apr
$ cp -r apr-util-1.4.1 httpd-2.4.7/srclib/apr-util
$ cd httpd-2.4.7
$ ./configure --prefix= /usr/local/apache2 --enable-rewrite --enable-so --enable-headers --enable-expires --enable-modules= most --enable-deflate --enable-ssl
$ make && make install
$ /usr/local/apache2/bin/apachectl -t
$ /usr/local/apache2/bin/apachectl -k stop
$ /usr/local/apache2/bin/apachectl -k start
$ ss -antp | grep :80
$ ps -aux | grep httpd
---------------------------
网页路径中输入:服务器IP地址
安装MySQL
$ yum -y install cmake bison ncurses-devel
$ tar -zxf ncurses-5.9.tar.gz
$ cd ncurses-5.9
$ ./configure --with-shared --without-debug --without-ada --enable-overwrite
$ make && make install
$ useradd -M -s /sbin/nologin mysql
$ tar -zxf mysql-5.5.48.tar.gz
$ cd mysql-5.5.48
$ cmake -DCMAKE_INSTALL_PREFIX= /usr/local/mysql -DMYSQL_UNIX_ADDR= /tmp/mysql.sock -DEXTRA_CHARSETS= all -DDEFAULT_CHARSET= utf8 -DDEFAULT_COLLATION= utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE= 1 -DWITH_INNOBASE_STORAGE_ENGINE= 1 -DWITH_MEMORY_STORAGE_ENGINE= 1 -DWITH_READLINE= 1 -DENABLED_LOCAL_INFILE= 1 -DMYSQL_USER= mysql -DMYSQL_TCP_PORT= 3306
$ make && make install
$ cp -a support-files/my-medium.cnf /etc/my.cnf
$ cd /usr/local/mysql
$ chown -R mysql data
$ ./scripts/mysql_install_db --user= mysql
$ /usr/local/mysql/bin/mysqld_safe --user= mysql &
$ ss -antp | grep :3306
$ /usr/local/mysql/bin/mysql
mysql> show databases;
用exit登出
$ /usr/local/mysql/bin/mysqladmin -uroot password 123
$ /usr/local/mysql/bin/mysql -uroot -p,回车输入密码
mysql> show database;
安装php
$ tar -zxf freetype-2.3.5.tar.gz
$ cd freetype-2.3.5
$ ./configure --prefix= /usr/local/freetype
$ make && make install
$ tar -zxf libmcrypt-2.5.8.tar.gz
$ cd libmcrypt-2.5.8
$ ./configure --prefix= /usr/local/libmcrypt
$ make && make install
$ cd libltdl
$ ./configure --enable-ltdl-install
$ make && make install
$ tar -zxf mhash-0.9.9.9.tar.gz
$ cd mhash-0.9.9.9
$ ./configure
$ make && make install
$ tar -zxf mcrypt-2.6.8.tar.gz
$ cd mcrypt-2.6.8
$ export LD_LIBRARY_PATH= /usr/local/libmcrypt/lib:/usr/local/lib
$ ./configure --with-libmcrypt-prefix= /usr/local/libmcrypt
$ make && make install
$ tar -zxf zlib-1.2.3.tar.gz
$ cd zlib-1.2.3
$ ./configure
$ vim Makefile
CFLAGS= -O3 -DUSE_MMAP -fPIC
$ make && make install
$ tar -zxf libpng-1.2.31.tar.gz
$ cd libpng-1.2.31
$ ./configure --prefix= /usr/local/libpng
$ make && make install
$ mkdir /usr/local/jpeg6
$ mkdir /usr/local/jpeg6/bin
$ mkdir /usr/local/jpeg6/lib
$ mkdir /usr/local/jpeg6/include
$ mkdir -p /usr/local/jpeg6/man/man1
$ yum -y install libtool*
$ tar -zxf jpegsrc.v6b.tar.gz
$ cd jpeg-6b
$ cp -a /usr/share/libtool/config/config.sub ./
$ cp -a /usr/share/libtool/config/config.guess ./
$ ./configure --prefix= /usr/local/jpeg6/ --enable-shared --enable-static
$ make && make install
$ yum -y install libxml2-devel python-devel
$ tar -zxf libxml2-2.9.1.tar.gz
$ cd libxml2-2.9.1
$ ./configure --prefix= /usr/local/libxml2
$ make && make install
$ tar -zxf php-7.0.7.tar.gz
$ cd php-7.0.7
$ ./configure --prefix= /usr/local/php/ --with-config-file-path= /usr/local/php/etc/ --with-apxs2= /usr/local/apache2/bin/apxs --with-libxml-dir= /usr/local/libxml2/ --with-jpeg-dir= /usr/local/jpeg6/ --with-png-dir= /usr/local/libpng/ --with-freetype-dir= /usr/local/freetype/ --with-mcrypt= /usr/local/libmcrypt/ --with-mysqli= /usr/local/mysql/bin/mysql_config --enable-soap --enable-mbstring= all --enable-sockets --with-pdo-mysql= /usr/local/mysql --with-gd --without-pear
$ make && make install
$ mkdir /usr/local/php/etc
$ cp -a php.ini-production /usr/local/php/etc/php.ini
vim /usr/local/apache2/conf/httpd.conf
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
$ /usr/local/apache2/bin/apachectl stop
$ /usr/local/apache2/bin/apachectl start
------------------------
$ vim /usr/local/apache2/htdocs/test-php.php
< ?php
phpinfo( ) ;
?>
$ 浏览器输入网址访问:http://apacheServerIP/test-php.php
-----------------------
$ vim /usr/local/apache2/htdocs/test-php-mysql.php
< ?php
$servername = "localhost" ;
$username = "root" ;
$password = "123" ;
// 创建连接
$conn = mysqli_connect( $servername , $username , $password ) ;
// 检测连接
if ( ! $conn ) {
//die( ) 函数输出一条消息,并退出当前脚本,是 exit( ) 函数的别名。
die( "Connection failed: " . mysqli_connect_error( )) ;
}
echo "连接成功" ;
// 创建数据库
$sql = "CREATE DATABASE IF NOT EXISTS wordpress" ;
if ( mysqli_query( $conn , $sql )) {
echo "数据库创建成功" ;
} else {
echo "Error creating database: " . mysqli_error( $conn ) ;
}
mysqli_close( $conn ) ;
?>
$ 浏览器输入网址访问:http://apacheServerIP/test-php-mysql.php
优化PHP、添加扩展模块
$ cd 解压目录/php-7.0.7/ext/openssl
$ mv config0.m4 config.m4
$ /usr/local/php/bin/phpize
$ ./configure --with-openssl --with-php-config= /usr/local/php/bin/php-config
$ make && make install
$ cd php-7.0.7/ext/zlib/
$ mv config0.m4 config.m4
$ /usr/local/php/bin/phpize
$ ./configure --with-zlib --with-php-config= /usr/local/php/bin/php-config
$ make && make install
$ unzip 解压目录/pecl-memcache-php7.zip
$ cd pecl-memcache-php7
$ /usr/local/php/bin/phpize
$ ./configure --with-php-config= /usr/local/php/bin/php-config
$ make && make install
$ yum -y install 解压目录/libevent/c7或c6/libevent*
$ tar -zxf memcached-1.4.17.tar.gz
$ cd memcached-1.4.17
$ ./configure --prefix= /usr/local/memcache
$ make && make install
$ useradd -s /sbin/nologin memcache
$ /usr/local/memcache/bin/memcached -umemcache &
$ ss -antp | grep :11211
vim /usr/local/php/etc/php.ini
extension_dir= "/usr/local/php/lib/php/extensions/no-debug-zts-20151012/"
extension= "openssl.so" ;
extension= "memcache.so" ;
extension= "zlib.so" ;
$ /usr/local/apache2/bin/apachectl stop
$ /usr/local/apache2/bin/apachectl start
搭建网站
$ tar -zxf wordpress-4.7.4-zh_CN.tar.gz
$ cp -a wordpress /usr/local/apache2/htdocs/
$ useradd -s /sbin/nologin apache
$ chown -R apache:apache /usr/local/apache2/htdocs
$ vim /usr/local/apache2/conf/httpd.conf
User apache
Group apache
< IfModule dir_module>
DirectoryIndex index.php
< /IfModule>
$ /usr/local/apache2/bin/apachectl stop
$ /usr/local/apache2/bin/apachectl start
$ 进入数据库创建wordpress数据库
改主题、写文章(若写的文章是中文主题,需要联网添加Pinyin Permalink插件、并启用)
设置相关的服务开机自启
$ vim /etc/rc.local
/usr/local/apache2/bin/apachectl start
/usr/local/mysql/bin/mysqld_safe --user= mysql &
/usr/local/memcache/bin/memcached -umemcache &
chmod +x /etc/rc.d/rc.local
hp
#网站测试: 改主题、写文章(若写的文章是中文主题,需要联网添加Pinyin Permalink插件、并启用)
#### 设置相关的服务开机自启
```shell
#设置apache、mysql、memcache(安装了优化PHP部分)开机自启
$ vim /etc/rc.local
/usr/local/apache2/bin/apachectl start
/usr/local/mysql/bin/mysqld_safe --user=mysql &
/usr/local/memcache/bin/memcached -umemcache &
chmod +x /etc/rc.d/rc.local