前言

什么是LAMP
LAMP 是Linux Apache MySQL PHP的简写,其实就是把Apache, MySQL以及PHP安装在Linux系统上,组成一个环境来运行php的脚本语言。Apache是最常用的WEB服务软件,而MySQL是比较小型的数据库软件。
环境:CentOS7

启用并建立交换空间

查看是否存在Swap分区

查看Swap分区的大小以及使用情况,一般使用free命令即可,如下所示,Swap大小为512M,目前没有使用Swap分区
1➜  ~ free -m
2              total        used        free      shared  buff/cache   available
3Mem:            512         206         138          26         166         305
4Swap:           512           0         512
Copy

创建文件作为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
1dd if=/dev/zero of=/var/swapfile bs=1M count=1024
2mkswap /var/swapfile
3swapon /var/swapfile
4echo "/root/swapfile swap swap defaults 0 0" >> /etc/fstab
Copy

安装阶段

安装apache2

1➜  ~ sudo yum install httpd
2Loaded plugins: fastestmirror
3Loading mirror speeds from cached hostfile
4 * base: mirror.fileplanet.com
5 * epel: d2lzkl7pfhq30w.cloudfront.net
6 * extras: mirror.jaleco.com
7 * updates: centos-distro.cavecreek.net
8Resolving Dependencies
9--> Running transaction check
10---> Package httpd.x86_64 0:2.4.6-88.el7.centos will be installed
11--> Finished Dependency Resolution
12
13Dependencies Resolved
14
15================================================================================
16 Package       Arch           Version                        Repository    Size
17================================================================================
18Installing:
19 httpd         x86_64         2.4.6-88.el7.centos            base         2.7 M
20
21Transaction Summary
22================================================================================
23Install  1 Package
24
25Total download size: 2.7 M
26Installed size: 9.4 M
27Is this ok [y/d/N]: y
28Downloading packages:
29httpd-2.4.6-88.el7.centos.x86_64.rpm                       | 2.7 MB   00:00
30Running transaction check
31Running transaction test
32Transaction test succeeded
33Running transaction
34  Installing : httpd-2.4.6-88.el7.centos.x86_64                             1/1
35  Verifying  : httpd-2.4.6-88.el7.centos.x86_64                             1/1
36
37Installed:
38  httpd.x86_64 0:2.4.6-88.el7.centos
39
40Complete!
Copy

安装 MySQL

1➜  ~ yum install mysql
2Loaded plugins: fastestmirror
3Loading mirror speeds from cached hostfile
4 * base: mirror.fileplanet.com
5 * epel: d2lzkl7pfhq30w.cloudfront.net
6 * extras: repos-lax.psychz.net
7 * updates: centos-distro.cavecreek.net
8Resolving Dependencies
9--> Running transaction check
10---> Package mariadb.x86_64 1:5.5.60-1.el7_5 will be installed
11--> 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
12--> Running transaction check
13---> Package mariadb-libs.x86_64 1:5.5.60-1.el7_5 will be installed
14--> Finished Dependency Resolution
15
16Dependencies Resolved
17
18================================================================================
19 Package             Arch          Version                    Repository   Size
20================================================================================
21Installing:
22 mariadb             x86_64        1:5.5.60-1.el7_5           base        8.9 M
23Installing for dependencies:
24 mariadb-libs        x86_64        1:5.5.60-1.el7_5           base        758 k
25
26Transaction Summary
27================================================================================
28Install  1 Package (+1 Dependent package)
29
30Total download size: 9.6 M
31Installed size: 53 M
32Is this ok [y/d/N]: y
33Downloading packages:
34(1/2): mariadb-libs-5.5.60-1.el7_5.x86_64.rpm              | 758 kB   00:00
35(2/2): mariadb-5.5.60-1.el7_5.x86_64.rpm                   | 8.9 MB   00:00
36--------------------------------------------------------------------------------
37Total                                               14 MB/s | 9.6 MB  00:00
38Running transaction check
39Running transaction test
40Transaction test succeeded
41Running transaction
42  Installing : 1:mariadb-libs-5.5.60-1.el7_5.x86_64                         1/2
43  Installing : 1:mariadb-5.5.60-1.el7_5.x86_64                              2/2
44  Verifying  : 1:mariadb-5.5.60-1.el7_5.x86_64                              1/2
45  Verifying  : 1:mariadb-libs-5.5.60-1.el7_5.x86_64                         2/2
46
47Installed:
48  mariadb.x86_64 1:5.5.60-1.el7_5
49
50Dependency Installed:
51  mariadb-libs.x86_64 1:5.5.60-1.el7_5
52
53Complete!
Copy

编译安装php

1yum install gcc autoconf gcc-c++ \
2libxml2 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 \
3systemd-devel \
4openjpeg-devel -y  # 安装编译库和依赖包
5cd /tmp
6wget http://cn2.php.net/distributions/php-7.2.4.tar.gz
7tar zxvf php-7.2.4.tar.gz 
8#添加php-fpm用户
9#创建群组
10groupadd php-fpm
11#创建一个用户,不允许登陆和不创主目录 
12useradd -s /sbin/nologin -g php-fpm -M php-fpm
13
14cd ./php-7.2.4
15./configure \
16--prefix=/usr/local/php \
17--with-config-file-path=/usr/local/php/etc \
18--with-zlib-dir \
19--with-freetype-dir \
20--enable-mbstring \
21--with-libxml-dir=/usr \
22--enable-xmlreader \
23--enable-xmlwriter \
24--enable-soap \
25--enable-calendar \
26--with-curl \
27--with-zlib \
28--with-gd \
29--with-pdo-sqlite \
30--with-pdo-mysql \
31--with-mysqli \
32--with-mysql-sock \
33--enable-mysqlnd \
34--disable-rpath \
35--enable-inline-optimization \
36--with-bz2 \
37--with-zlib \
38--enable-sockets \
39--enable-sysvsem \
40--enable-sysvshm \
41--enable-pcntl \
42--enable-mbregex \
43--enable-exif \
44--enable-bcmath \
45--with-mhash \
46--enable-zip \
47--with-pcre-regex \
48--with-jpeg-dir=/usr \
49--with-png-dir=/usr \
50--with-openssl \
51--enable-ftp \
52--with-kerberos \
53--with-gettext \
54--with-xmlrpc \
55--with-xsl \
56--enable-fpm \
57--with-fpm-user=php-fpm \
58--with-fpm-group=php-fpm \
59--with-fpm-systemd \
60--disable-fileinfo
61 make && make install
Copy

使用包管理器安装

1yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
2yum install yum-utils
3yum-config-manager --enable remi-php73
4yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo 
Copy
1➜  php-7.2.4 yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
2Loaded plugins: fastestmirror
3remi-release-7.rpm                                       |  15 kB     00:00
4Examining /var/tmp/yum-root-F1IWpp/remi-release-7.rpm: remi-release-7.6-1.el7.remi.noarch
5Marking /var/tmp/yum-root-F1IWpp/remi-release-7.rpm to be installed
6Resolving Dependencies
7--> Running transaction check
8---> Package remi-release.noarch 0:7.6-1.el7.remi will be installed
9--> Finished Dependency Resolution
10
11Dependencies Resolved
12
13================================================================================
14 Package           Arch        Version               Repository            Size
15================================================================================
16Installing:
17 remi-release      noarch      7.6-1.el7.remi        /remi-release-7       18 k
18
19Transaction Summary
20================================================================================
21Install  1 Package
22
23Total size: 18 k
24Installed size: 18 k
25Is this ok [y/d/N]: y
26Downloading packages:
27Running transaction check
28Running transaction test
29Transaction test succeeded
30Running transaction
31  Installing : remi-release-7.6-1.el7.remi.noarch                           1/1
32  Verifying  : remi-release-7.6-1.el7.remi.noarch                           1/1
33
34Installed:
35  remi-release.noarch 0:7.6-1.el7.remi
36
37Complete!
38➜  php-7.2.4 yum install yum-utils
39Loaded plugins: fastestmirror
40Loading mirror speeds from cached hostfile
41 * base: mirror.fileplanet.com
42 * epel: d2lzkl7pfhq30w.cloudfront.net
43 * extras: mirror.jaleco.com
44 * remi-safe: mirrors.mediatemple.net
45 * updates: centos-distro.cavecreek.net
46remi-safe                                                | 3.0 kB     00:00
47remi-safe/primary_db                                       | 1.4 MB   00:03
48Package yum-utils-1.1.31-50.el7.noarch already installed and latest version
49Nothing to do
50➜  php-7.2.4 yum-config-manager --enable remi-php73
51Loaded plugins: fastestmirror
52=============================== repo: remi-php73 ===============================
53[remi-php73]
54async = True
55bandwidth = 0
56base_persistdir = /var/lib/yum/repos/x86_64/7
57baseurl =
58cache = 0
59cachedir = /var/cache/yum/x86_64/7/remi-php73
60check_config_file_age = True
61compare_providers_priority = 80
62cost = 1000
63deltarpm_metadata_percentage = 100
64deltarpm_percentage =
65enabled = 1
66enablegroups = True
67exclude =
68failovermethod = priority
69ftp_disable_epsv = False
70gpgcadir = /var/lib/yum/repos/x86_64/7/remi-php73/gpgcadir
71gpgcakey =
72gpgcheck = True
73gpgdir = /var/lib/yum/repos/x86_64/7/remi-php73/gpgdir
74gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
75hdrdir = /var/cache/yum/x86_64/7/remi-php73/headers
76http_caching = all
77includepkgs =
78ip_resolve =
79keepalive = True
80keepcache = False
81mddownloadpolicy = sqlite
82mdpolicy = group:small
83mediaid =
84metadata_expire = 21600
85metadata_expire_filter = read-only:present
86metalink =
87minrate = 0
88mirrorlist = http://cdn.remirepo.net/enterprise/7/php73/mirror
89mirrorlist_expire = 86400
90name = Remi's PHP 7.3 RPM repository for Enterprise Linux 7 - x86_64
91old_base_cache_dir =
92password =
93persistdir = /var/lib/yum/repos/x86_64/7/remi-php73
94pkgdir = /var/cache/yum/x86_64/7/remi-php73/packages
95proxy = False
96proxy_dict =
97proxy_password =
98proxy_username =
99repo_gpgcheck = False
100retries = 10
101skip_if_unavailable = False
102ssl_check_cert_permissions = True
103sslcacert =
104sslclientcert =
105sslclientkey =
106sslverify = True
107throttle = 0
108timeout = 30.0
109ui_id = remi-php73
110ui_repoid_vars = releasever,
111   basearch
112username =
113
114➜  php-7.2.4 yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo
115Loaded plugins: fastestmirror
116Loading mirror speeds from cached hostfile
117 * base: mirror.fileplanet.com
118 * epel: d2lzkl7pfhq30w.cloudfront.net
119 * extras: repos-lax.psychz.net
120 * remi-php73: mirrors.mediatemple.net
121 * remi-safe: mirrors.mediatemple.net
122 * updates: centos-distro.cavecreek.net
123remi-php73                                               | 3.0 kB     00:00
124remi-php73/primary_db                                      | 189 kB   00:01
125Package 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
126Package php-mysql is obsoleted by php-mysqlnd, trying to install php-mysqlnd-7.3.2-1.el7.remi.x86_64 instead
127Resolving Dependencies
128--> Running transaction check
129---> Package php.x86_64 0:7.3.2-1.el7.remi will be installed
130---> Package php-cli.x86_64 0:5.4.16-46.el7 will be updated
131---> Package php-cli.x86_64 0:7.3.2-1.el7.remi will be an update
132---> Package php-common.x86_64 0:5.4.16-46.el7 will be updated
133--> Processing Dependency: php-json(x86-64) = 7.3.2-1.el7.remi for package: php-common-7.3.2-1.el7.remi.x86_64
134---> Package php-common.x86_64 0:7.3.2-1.el7.remi will be an update
135---> Package php-gd.x86_64 0:7.3.2-1.el7.remi will be installed
136---> Package php-ldap.x86_64 0:7.3.2-1.el7.remi will be installed
137---> Package php-mysqlnd.x86_64 0:7.3.2-1.el7.remi will be installed
138--> Processing Dependency: php-pdo(x86-64) = 7.3.2-1.el7.remi for package: php-mysqlnd-7.3.2-1.el7.remi.x86_64
139---> Package php-pecl-mcrypt.x86_64 0:1.0.2-2.el7.remi.7.3 will be installed
140--> Processing Dependency: libmcrypt.so.4()(64bit) for package: php-pecl-mcrypt-1.0.2-2.el7.remi.7.3.x86_64
141---> Package php-pecl-zip.x86_64 0:1.15.4-1.el7.remi.7.3 will be installed
142--> Processing Dependency: libzip5(x86-64) >= 1.5.1 for package: php-pecl-zip-1.15.4-1.el7.remi.7.3.x86_64
143--> Processing Dependency: libzip.so.5()(64bit) for package: php-pecl-zip-1.15.4-1.el7.remi.7.3.x86_64
144--> Running transaction check
145---> Package libmcrypt.x86_64 0:2.5.8-13.el7 will be installed
146---> Package libzip5.x86_64 0:1.5.1-1.el7.remi will be installed
147---> Package php-json.x86_64 0:7.3.2-1.el7.remi will be installed
148---> Package php-pdo.x86_64 0:7.3.2-1.el7.remi will be installed
149--> Finished Dependency Resolution
150
151Dependencies Resolved
152
153================================================================================
154 Package             Arch       Version                    Repository      Size
155================================================================================
156Installing:
157 php                 x86_64     7.3.2-1.el7.remi           remi-php73     3.2 M
158 php-gd              x86_64     7.3.2-1.el7.remi           remi-php73      78 k
159 php-ldap            x86_64     7.3.2-1.el7.remi           remi-php73      76 k
160 php-mysqlnd         x86_64     7.3.2-1.el7.remi           remi-php73     231 k
161 php-pecl-mcrypt     x86_64     1.0.2-2.el7.remi.7.3       remi-php73      29 k
162 php-pecl-zip        x86_64     1.15.4-1.el7.remi.7.3      remi-php73      51 k
163Updating:
164 php-cli             x86_64     7.3.2-1.el7.remi           remi-php73     4.9 M
165 php-common          x86_64     7.3.2-1.el7.remi           remi-php73     1.1 M
166Installing for dependencies:
167 libmcrypt           x86_64     2.5.8-13.el7               epel            99 k
168 libzip5             x86_64     1.5.1-1.el7.remi           remi-safe       55 k
169 php-json            x86_64     7.3.2-1.el7.remi           remi-php73      63 k
170 php-pdo             x86_64     7.3.2-1.el7.remi           remi-php73     124 k
171
172Transaction Summary
173================================================================================
174Install  6 Packages (+4 Dependent packages)
175Upgrade  2 Packages
176
177Total download size: 10 M
178Is this ok [y/d/N]: y
179Downloading packages:
180Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
181(1/12): libmcrypt-2.5.8-13.el7.x86_64.rpm                  |  99 kB   00:02
182warning: /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
183Public key for php-cli-7.3.2-1.el7.remi.x86_64.rpm is not installed
184(2/12): php-cli-7.3.2-1.el7.remi.x86_64.rpm                | 4.9 MB   00:03
185(3/12): php-json-7.3.2-1.el7.remi.x86_64.rpm               |  63 kB   00:00
186(4/12): php-ldap-7.3.2-1.el7.remi.x86_64.rpm               |  76 kB   00:00
187(5/12): php-mysqlnd-7.3.2-1.el7.remi.x86_64.rpm            | 231 kB   00:00
188(6/12): php-pdo-7.3.2-1.el7.remi.x86_64.rpm                | 124 kB   00:00
189(7/12): php-pecl-mcrypt-1.0.2-2.el7.remi.7.3.x86_64.rpm    |  29 kB   00:00
190(8/12): php-pecl-zip-1.15.4-1.el7.remi.7.3.x86_64.rpm      |  51 kB   00:00
191(9/12): php-gd-7.3.2-1.el7.remi.x86_64.rpm                 |  78 kB   00:00
192Public key for libzip5-1.5.1-1.el7.remi.x86_64.rpm is not installed
193(10/12): libzip5-1.5.1-1.el7.remi.x86_64.rpm               |  55 kB   00:03
194(11/12): php-common-7.3.2-1.el7.remi.x86_64.rpm            | 1.1 MB   00:07
195(12/12): php-7.3.2-1.el7.remi.x86_64.rpm                   | 3.2 MB   00:12
196--------------------------------------------------------------------------------
197Total                                              786 kB/s |  10 MB  00:13
198Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
199Importing GPG key 0x00F97F56:
200 Userid     : "Remi Collet <RPMS@FamilleCollet.com>"
201 Fingerprint: 1ee0 4cce 88a4 ae4a a29a 5df5 004e 6f47 00f9 7f56
202 Package    : remi-release-7.6-1.el7.remi.noarch (installed)
203 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-remi
204Is this ok [y/N]: y
205Running transaction check
206Running transaction test
207Transaction test succeeded
208Running transaction
209  Updating   : php-common-7.3.2-1.el7.remi.x86_64                          1/14
210  Installing : php-json-7.3.2-1.el7.remi.x86_64                            2/14
211  Updating   : php-cli-7.3.2-1.el7.remi.x86_64                             3/14
212  Installing : php-pdo-7.3.2-1.el7.remi.x86_64                             4/14
213  Installing : libzip5-1.5.1-1.el7.remi.x86_64                             5/14
214  Installing : libmcrypt-2.5.8-13.el7.x86_64                               6/14
215  Installing : php-pecl-mcrypt-1.0.2-2.el7.remi.7.3.x86_64                 7/14
216  Installing : php-pecl-zip-1.15.4-1.el7.remi.7.3.x86_64                   8/14
217  Installing : php-mysqlnd-7.3.2-1.el7.remi.x86_64                         9/14
218  Installing : php-7.3.2-1.el7.remi.x86_64                                10/14
219  Installing : php-ldap-7.3.2-1.el7.remi.x86_64                           11/14
220  Installing : php-gd-7.3.2-1.el7.remi.x86_64                             12/14
221  Cleanup    : php-cli-5.4.16-46.el7.x86_64                               13/14
222  Cleanup    : php-common-5.4.16-46.el7.x86_64                            14/14
223  Verifying  : php-pecl-mcrypt-1.0.2-2.el7.remi.7.3.x86_64                 1/14
224  Verifying  : php-mysqlnd-7.3.2-1.el7.remi.x86_64                         2/14
225  Verifying  : php-ldap-7.3.2-1.el7.remi.x86_64                            3/14
226  Verifying  : php-pecl-zip-1.15.4-1.el7.remi.7.3.x86_64                   4/14
227  Verifying  : php-json-7.3.2-1.el7.remi.x86_64                            5/14
228  Verifying  : php-7.3.2-1.el7.remi.x86_64                                 6/14
229  Verifying  : php-cli-7.3.2-1.el7.remi.x86_64                             7/14
230  Verifying  : php-gd-7.3.2-1.el7.remi.x86_64                              8/14
231  Verifying  : php-common-7.3.2-1.el7.remi.x86_64                          9/14
232  Verifying  : libmcrypt-2.5.8-13.el7.x86_64                              10/14
233  Verifying  : libzip5-1.5.1-1.el7.remi.x86_64                            11/14
234  Verifying  : php-pdo-7.3.2-1.el7.remi.x86_64                            12/14
235  Verifying  : php-cli-5.4.16-46.el7.x86_64                               13/14
236  Verifying  : php-common-5.4.16-46.el7.x86_64                            14/14
237
238Installed:
239  php.x86_64 0:7.3.2-1.el7.remi
240  php-gd.x86_64 0:7.3.2-1.el7.remi
241  php-ldap.x86_64 0:7.3.2-1.el7.remi
242  php-mysqlnd.x86_64 0:7.3.2-1.el7.remi
243  php-pecl-mcrypt.x86_64 0:1.0.2-2.el7.remi.7.3
244  php-pecl-zip.x86_64 0:1.15.4-1.el7.remi.7.3
245
246Dependency Installed:
247  libmcrypt.x86_64 0:2.5.8-13.el7         libzip5.x86_64 0:1.5.1-1.el7.remi
248  php-json.x86_64 0:7.3.2-1.el7.remi      php-pdo.x86_64 0:7.3.2-1.el7.remi
249
250Updated:
251  php-cli.x86_64 0:7.3.2-1.el7.remi     php-common.x86_64 0:7.3.2-1.el7.remi
252
253Complete!
254➜  php-7.2.4 php -v
255PHP 7.3.2 (cli) (built: Feb  5 2019 13:10:03) ( NTS )
256Copyright (c) 1997-2018 The PHP Group
257Zend Engine v3.3.2, Copyright (c) 1998-2018 Zend Technologies
Copy

亲亲留个评论再走呗

正在加载评论区...