手动搭建 LAMP 环境
前言
什么是LAMP
LAMP 是Linux Apache MySQL PHP的简写,其实就是把Apache, MySQL以及PHP安装在Linux系统上,组成一个环境来运行php的脚本语言。Apache是最常用的WEB服务软件,而MySQL是比较小型的数据库软件。
环境:CentOS7
启用并建立交换空间
查看是否存在Swap分区
查看Swap分区的大小以及使用情况,一般使用free命令即可,如下所示,Swap大小为512M,目前没有使用Swap分区
➜ ~ free -m
total used free shared buff/cache available
Mem: 512 206 138 26 166 305
Swap: 512 0 512
创建文件作为Swap
1.创建要作为swap分区的文件:增加1GB大小的交换分区,则命令写法如下,其中的count等于想要的块的数量(bs*count=文件大小)。
dd if=/dev/zero of=/var/swapfile bs=1M count=1024
2.格式化为交换分区文件:
mkswap /var/swapfile # 建立swap的文件系统
3.启用交换分区文件:
swapon /var/swapfile # 启用swap文件
4.使系统开机时自启用,在文件/etc/fstab中添加一行: /var/swapfile swap swap defaults 0 0
dd if=/dev/zero of=/var/swapfile bs=1M count=1024
mkswap /var/swapfile
swapon /var/swapfile
echo "/root/swapfile swap swap defaults 0 0" >> /etc/fstab
安装阶段
安装apache2
➜ ~ sudo yum install httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.fileplanet.com
* epel: d2lzkl7pfhq30w.cloudfront.net
* extras: mirror.jaleco.com
* updates: centos-distro.cavecreek.net
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-88.el7.centos will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
httpd x86_64 2.4.6-88.el7.centos base 2.7 M
Transaction Summary
================================================================================
Install 1 Package
Total download size: 2.7 M
Installed size: 9.4 M
Is this ok [y/d/N]: y
Downloading packages:
httpd-2.4.6-88.el7.centos.x86_64.rpm | 2.7 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : httpd-2.4.6-88.el7.centos.x86_64 1/1
Verifying : httpd-2.4.6-88.el7.centos.x86_64 1/1
Installed:
httpd.x86_64 0:2.4.6-88.el7.centos
Complete!
安装 MySQL
➜ ~ yum install mysql
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.fileplanet.com
* epel: d2lzkl7pfhq30w.cloudfront.net
* extras: repos-lax.psychz.net
* updates: centos-distro.cavecreek.net
Resolving Dependencies
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.60-1.el7_5 will be installed
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.60-1.el7_5 for package: 1:mariadb-5.5.60-1.el7_5.x86_64
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.60-1.el7_5 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
mariadb x86_64 1:5.5.60-1.el7_5 base 8.9 M
Installing for dependencies:
mariadb-libs x86_64 1:5.5.60-1.el7_5 base 758 k
Transaction Summary
================================================================================
Install 1 Package (+1 Dependent package)
Total download size: 9.6 M
Installed size: 53 M
Is this ok [y/d/N]: y
Downloading packages:
(1/2): mariadb-libs-5.5.60-1.el7_5.x86_64.rpm | 758 kB 00:00
(2/2): mariadb-5.5.60-1.el7_5.x86_64.rpm | 8.9 MB 00:00
--------------------------------------------------------------------------------
Total 14 MB/s | 9.6 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 1:mariadb-libs-5.5.60-1.el7_5.x86_64 1/2
Installing : 1:mariadb-5.5.60-1.el7_5.x86_64 2/2
Verifying : 1:mariadb-5.5.60-1.el7_5.x86_64 1/2
Verifying : 1:mariadb-libs-5.5.60-1.el7_5.x86_64 2/2
Installed:
mariadb.x86_64 1:5.5.60-1.el7_5
Dependency Installed:
mariadb-libs.x86_64 1:5.5.60-1.el7_5
Complete!
编译安装php
yum install gcc autoconf gcc-c++ \
libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel readline readline-devel libxslt libxslt-devel \
systemd-devel \
openjpeg-devel -y # 安装编译库和依赖包
cd /tmp
wget http://cn2.php.net/distributions/php-7.2.4.tar.gz
tar zxvf php-7.2.4.tar.gz
#添加php-fpm用户
#创建群组
groupadd php-fpm
#创建一个用户,不允许登陆和不创主目录
useradd -s /sbin/nologin -g php-fpm -M php-fpm
cd ./php-7.2.4
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-zlib-dir \
--with-freetype-dir \
--enable-mbstring \
--with-libxml-dir=/usr \
--enable-xmlreader \
--enable-xmlwriter \
--enable-soap \
--enable-calendar \
--with-curl \
--with-zlib \
--with-gd \
--with-pdo-sqlite \
--with-pdo-mysql \
--with-mysqli \
--with-mysql-sock \
--enable-mysqlnd \
--disable-rpath \
--enable-inline-optimization \
--with-bz2 \
--with-zlib \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-pcntl \
--enable-mbregex \
--enable-exif \
--enable-bcmath \
--with-mhash \
--enable-zip \
--with-pcre-regex \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-openssl \
--enable-ftp \
--with-kerberos \
--with-gettext \
--with-xmlrpc \
--with-xsl \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-fpm-systemd \
--disable-fileinfo
make && make install
使用包管理器安装
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install yum-utils
yum-config-manager --enable remi-php73
yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo
➜ php-7.2.4 yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
Loaded plugins: fastestmirror
remi-release-7.rpm | 15 kB 00:00
Examining /var/tmp/yum-root-F1IWpp/remi-release-7.rpm: remi-release-7.6-1.el7.remi.noarch
Marking /var/tmp/yum-root-F1IWpp/remi-release-7.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package remi-release.noarch 0:7.6-1.el7.remi will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
remi-release noarch 7.6-1.el7.remi /remi-release-7 18 k
Transaction Summary
================================================================================
Install 1 Package
Total size: 18 k
Installed size: 18 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : remi-release-7.6-1.el7.remi.noarch 1/1
Verifying : remi-release-7.6-1.el7.remi.noarch 1/1
Installed:
remi-release.noarch 0:7.6-1.el7.remi
Complete!
➜ php-7.2.4 yum install yum-utils
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.fileplanet.com
* epel: d2lzkl7pfhq30w.cloudfront.net
* extras: mirror.jaleco.com
* remi-safe: mirrors.mediatemple.net
* updates: centos-distro.cavecreek.net
remi-safe | 3.0 kB 00:00
remi-safe/primary_db | 1.4 MB 00:03
Package yum-utils-1.1.31-50.el7.noarch already installed and latest version
Nothing to do
➜ php-7.2.4 yum-config-manager --enable remi-php73
Loaded plugins: fastestmirror
=============================== repo: remi-php73 ===============================
[remi-php73]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7
baseurl =
cache = 0
cachedir = /var/cache/yum/x86_64/7/remi-php73
check_config_file_age = True
compare_providers_priority = 80
cost = 1000
deltarpm_metadata_percentage = 100
deltarpm_percentage =
enabled = 1
enablegroups = True
exclude =
failovermethod = priority
ftp_disable_epsv = False
gpgcadir = /var/lib/yum/repos/x86_64/7/remi-php73/gpgcadir
gpgcakey =
gpgcheck = True
gpgdir = /var/lib/yum/repos/x86_64/7/remi-php73/gpgdir
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
hdrdir = /var/cache/yum/x86_64/7/remi-php73/headers
http_caching = all
includepkgs =
ip_resolve =
keepalive = True
keepcache = False
mddownloadpolicy = sqlite
mdpolicy = group:small
mediaid =
metadata_expire = 21600
metadata_expire_filter = read-only:present
metalink =
minrate = 0
mirrorlist = http://cdn.remirepo.net/enterprise/7/php73/mirror
mirrorlist_expire = 86400
name = Remi's PHP 7.3 RPM repository for Enterprise Linux 7 - x86_64
old_base_cache_dir =
password =
persistdir = /var/lib/yum/repos/x86_64/7/remi-php73
pkgdir = /var/cache/yum/x86_64/7/remi-php73/packages
proxy = False
proxy_dict =
proxy_password =
proxy_username =
repo_gpgcheck = False
retries = 10
skip_if_unavailable = False
ssl_check_cert_permissions = True
sslcacert =
sslclientcert =
sslclientkey =
sslverify = True
throttle = 0
timeout = 30.0
ui_id = remi-php73
ui_repoid_vars = releasever,
basearch
username =
➜ php-7.2.4 yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.fileplanet.com
* epel: d2lzkl7pfhq30w.cloudfront.net
* extras: repos-lax.psychz.net
* remi-php73: mirrors.mediatemple.net
* remi-safe: mirrors.mediatemple.net
* updates: centos-distro.cavecreek.net
remi-php73 | 3.0 kB 00:00
remi-php73/primary_db | 189 kB 00:01
Package php-mcrypt is obsoleted by php-pecl-mcrypt, trying to install php-pecl-mcrypt-1.0.2-2.el7.remi.7.3.x86_64 instead
Package php-mysql is obsoleted by php-mysqlnd, trying to install php-mysqlnd-7.3.2-1.el7.remi.x86_64 instead
Resolving Dependencies
--> Running transaction check
---> Package php.x86_64 0:7.3.2-1.el7.remi will be installed
---> Package php-cli.x86_64 0:5.4.16-46.el7 will be updated
---> Package php-cli.x86_64 0:7.3.2-1.el7.remi will be an update
---> Package php-common.x86_64 0:5.4.16-46.el7 will be updated
--> Processing Dependency: php-json(x86-64) = 7.3.2-1.el7.remi for package: php-common-7.3.2-1.el7.remi.x86_64
---> Package php-common.x86_64 0:7.3.2-1.el7.remi will be an update
---> Package php-gd.x86_64 0:7.3.2-1.el7.remi will be installed
---> Package php-ldap.x86_64 0:7.3.2-1.el7.remi will be installed
---> Package php-mysqlnd.x86_64 0:7.3.2-1.el7.remi will be installed
--> Processing Dependency: php-pdo(x86-64) = 7.3.2-1.el7.remi for package: php-mysqlnd-7.3.2-1.el7.remi.x86_64
---> Package php-pecl-mcrypt.x86_64 0:1.0.2-2.el7.remi.7.3 will be installed
--> Processing Dependency: libmcrypt.so.4()(64bit) for package: php-pecl-mcrypt-1.0.2-2.el7.remi.7.3.x86_64
---> Package php-pecl-zip.x86_64 0:1.15.4-1.el7.remi.7.3 will be installed
--> Processing Dependency: libzip5(x86-64) >= 1.5.1 for package: php-pecl-zip-1.15.4-1.el7.remi.7.3.x86_64
--> Processing Dependency: libzip.so.5()(64bit) for package: php-pecl-zip-1.15.4-1.el7.remi.7.3.x86_64
--> Running transaction check
---> Package libmcrypt.x86_64 0:2.5.8-13.el7 will be installed
---> Package libzip5.x86_64 0:1.5.1-1.el7.remi will be installed
---> Package php-json.x86_64 0:7.3.2-1.el7.remi will be installed
---> Package php-pdo.x86_64 0:7.3.2-1.el7.remi will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
php x86_64 7.3.2-1.el7.remi remi-php73 3.2 M
php-gd x86_64 7.3.2-1.el7.remi remi-php73 78 k
php-ldap x86_64 7.3.2-1.el7.remi remi-php73 76 k
php-mysqlnd x86_64 7.3.2-1.el7.remi remi-php73 231 k
php-pecl-mcrypt x86_64 1.0.2-2.el7.remi.7.3 remi-php73 29 k
php-pecl-zip x86_64 1.15.4-1.el7.remi.7.3 remi-php73 51 k
Updating:
php-cli x86_64 7.3.2-1.el7.remi remi-php73 4.9 M
php-common x86_64 7.3.2-1.el7.remi remi-php73 1.1 M
Installing for dependencies:
libmcrypt x86_64 2.5.8-13.el7 epel 99 k
libzip5 x86_64 1.5.1-1.el7.remi remi-safe 55 k
php-json x86_64 7.3.2-1.el7.remi remi-php73 63 k
php-pdo x86_64 7.3.2-1.el7.remi remi-php73 124 k
Transaction Summary
================================================================================
Install 6 Packages (+4 Dependent packages)
Upgrade 2 Packages
Total download size: 10 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/12): libmcrypt-2.5.8-13.el7.x86_64.rpm | 99 kB 00:02
warning: /var/cache/yum/x86_64/7/remi-php73/packages/php-cli-7.3.2-1.el7.remi.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 00f97f56: NOKEY
Public key for php-cli-7.3.2-1.el7.remi.x86_64.rpm is not installed
(2/12): php-cli-7.3.2-1.el7.remi.x86_64.rpm | 4.9 MB 00:03
(3/12): php-json-7.3.2-1.el7.remi.x86_64.rpm | 63 kB 00:00
(4/12): php-ldap-7.3.2-1.el7.remi.x86_64.rpm | 76 kB 00:00
(5/12): php-mysqlnd-7.3.2-1.el7.remi.x86_64.rpm | 231 kB 00:00
(6/12): php-pdo-7.3.2-1.el7.remi.x86_64.rpm | 124 kB 00:00
(7/12): php-pecl-mcrypt-1.0.2-2.el7.remi.7.3.x86_64.rpm | 29 kB 00:00
(8/12): php-pecl-zip-1.15.4-1.el7.remi.7.3.x86_64.rpm | 51 kB 00:00
(9/12): php-gd-7.3.2-1.el7.remi.x86_64.rpm | 78 kB 00:00
Public key for libzip5-1.5.1-1.el7.remi.x86_64.rpm is not installed
(10/12): libzip5-1.5.1-1.el7.remi.x86_64.rpm | 55 kB 00:03
(11/12): php-common-7.3.2-1.el7.remi.x86_64.rpm | 1.1 MB 00:07
(12/12): php-7.3.2-1.el7.remi.x86_64.rpm | 3.2 MB 00:12
--------------------------------------------------------------------------------
Total 786 kB/s | 10 MB 00:13
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Importing GPG key 0x00F97F56:
Userid : "Remi Collet <[email protected]>"
Fingerprint: 1ee0 4cce 88a4 ae4a a29a 5df5 004e 6f47 00f9 7f56
Package : remi-release-7.6-1.el7.remi.noarch (installed)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : php-common-7.3.2-1.el7.remi.x86_64 1/14
Installing : php-json-7.3.2-1.el7.remi.x86_64 2/14
Updating : php-cli-7.3.2-1.el7.remi.x86_64 3/14
Installing : php-pdo-7.3.2-1.el7.remi.x86_64 4/14
Installing : libzip5-1.5.1-1.el7.remi.x86_64 5/14
Installing : libmcrypt-2.5.8-13.el7.x86_64 6/14
Installing : php-pecl-mcrypt-1.0.2-2.el7.remi.7.3.x86_64 7/14
Installing : php-pecl-zip-1.15.4-1.el7.remi.7.3.x86_64 8/14
Installing : php-mysqlnd-7.3.2-1.el7.remi.x86_64 9/14
Installing : php-7.3.2-1.el7.remi.x86_64 10/14
Installing : php-ldap-7.3.2-1.el7.remi.x86_64 11/14
Installing : php-gd-7.3.2-1.el7.remi.x86_64 12/14
Cleanup : php-cli-5.4.16-46.el7.x86_64 13/14
Cleanup : php-common-5.4.16-46.el7.x86_64 14/14
Verifying : php-pecl-mcrypt-1.0.2-2.el7.remi.7.3.x86_64 1/14
Verifying : php-mysqlnd-7.3.2-1.el7.remi.x86_64 2/14
Verifying : php-ldap-7.3.2-1.el7.remi.x86_64 3/14
Verifying : php-pecl-zip-1.15.4-1.el7.remi.7.3.x86_64 4/14
Verifying : php-json-7.3.2-1.el7.remi.x86_64 5/14
Verifying : php-7.3.2-1.el7.remi.x86_64 6/14
Verifying : php-cli-7.3.2-1.el7.remi.x86_64 7/14
Verifying : php-gd-7.3.2-1.el7.remi.x86_64 8/14
Verifying : php-common-7.3.2-1.el7.remi.x86_64 9/14
Verifying : libmcrypt-2.5.8-13.el7.x86_64 10/14
Verifying : libzip5-1.5.1-1.el7.remi.x86_64 11/14
Verifying : php-pdo-7.3.2-1.el7.remi.x86_64 12/14
Verifying : php-cli-5.4.16-46.el7.x86_64 13/14
Verifying : php-common-5.4.16-46.el7.x86_64 14/14
Installed:
php.x86_64 0:7.3.2-1.el7.remi
php-gd.x86_64 0:7.3.2-1.el7.remi
php-ldap.x86_64 0:7.3.2-1.el7.remi
php-mysqlnd.x86_64 0:7.3.2-1.el7.remi
php-pecl-mcrypt.x86_64 0:1.0.2-2.el7.remi.7.3
php-pecl-zip.x86_64 0:1.15.4-1.el7.remi.7.3
Dependency Installed:
libmcrypt.x86_64 0:2.5.8-13.el7 libzip5.x86_64 0:1.5.1-1.el7.remi
php-json.x86_64 0:7.3.2-1.el7.remi php-pdo.x86_64 0:7.3.2-1.el7.remi
Updated:
php-cli.x86_64 0:7.3.2-1.el7.remi php-common.x86_64 0:7.3.2-1.el7.remi
Complete!
➜ php-7.2.4 php -v
PHP 7.3.2 (cli) (built: Feb 5 2019 13:10:03) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.2, Copyright (c) 1998-2018 Zend Technologies