Bygga en LAMP Stack på CentOS 6

Genom att kompilera din egen LAMP-stack kan du använda de senaste versionerna av Apache, MySQL och PHP. Med CentOS 6-pakethanteraren får du Apache 2.2, MySQL 5.1 och PHP 5.3. Pakethanteraren installerar bara säkerhetsuppdateringar från CentOS-teamet.

Som systemadministratör vet du att det är viktigt att hålla programvaran uppdaterad. Och med din webbserver vänd mot internet måste du se till att webbserverns programvara är uppdaterad för att förhindra sårbarheter.

Den här artikeln lär dig hur du kompilerar din egen LAMP-stack. Vart och ett av kommandona kommer att förklaras med följande format.

# Commands will be listed here

An explanation of the commands will be stated here.

Steg 1: Ladda ner/installera Apache 2.4

För den här artikeln kommer vi att använda en förinställd spegel; men om du vill kan du använda en annan spegel från Apache-spegelsidan med ett samtal från din VPS.

curl -q -s apache.org/dyn/closer.cgi > /tmp/closer
sed -e 151b -e '$!d' /tmp/closer

The curl command sends an HTTP request to the URL, and retrieves its contents. We redirect the output to /tmp/closer, and then the sed command cuts it down to something you can read.

Du kommer att se en spegellänk som finns i avsnittet. Byt bara ut alla länkar som anges i den här artikeln med den spegeln.

Ladda ner källan till Apache 2.4.

cd /usr/src && wget http://apache.mirrors.ionfish.org/httpd/httpd-2.4.17.tar.gz && tar xvf httpd-2.4.17.tar.gz

The first part of this command will change our current directory to /usr/src, then the wget section will download the source. The last part of this command unzips the source.

Eftersom Apache kräver APR och APR-util, gör följande:

wget http://apache.mirrors.ionfish.org/apr/apr-1.5.2.tar.gz && tar xvf apr-1.5.2.tar.gz && mv apr-1.5.2 httpd-2.4.17/srclib/apr
wget http://apache.mirrors.ionfish.org/apr/apr-util-1.5.4.tar.gz && tar xvf apr-util-1.5.4.tar.gz && mv apr-util-1.5.4 httpd-2.4.17/srclib/apr-util

These commands will download the sources for APR and APR-util, and unzip them. Then, we move the source into Apache's build directory so that Apache will build properly.

Eftersom vi behöver en ordentlig C-kompilator, måste vi installera en med pakethanteraren.

yum groupinstall 'Development Tools' -y
yum install gcc-c++ -y
yum install pcre-devel -y
yum install bison bison-devel -y
yum install ncurses-devel -y
yum install perl-devel -y

As I've mentioned above, we still need to obtain Apache's prerequisites, so we'll be installing them using the package manager.

Bra jobbat! Nu är det dags att konfigurera och bygga Apache.

cd httpd-2.4.17 && ./configure

The cd httpd-2.4.17 part changes our current working directory to httpd-2.4.17/. When we run ./configure, we're configuring our system to build Apache.

Tillåt systemet att konfigurera källan för installation, det bör inte ta för lång tid. När du är klar, kör:

make && make install
cp support/apachectl /usr/sbin
chmod 755 /usr/sbin/apachectl

The make section of these commands will build the software. When we run make install, we effectively install Apache onto our system. Now, we need to copy it to the secure bin directory (cp signifies copy). Finally, we'll give it permissions to execute with chmod 755.

Grattis, du har framgångsrikt installerat Apache 2.4!

Steg 2: Ladda ner/installera MySQL

Nu ska vi installera MySQL, en databas som används av många webbapplikationer. Eftersom MySQL redan tillhandahåller den senaste versionen i form av en RPM, är det lättare att använda deras förbyggda installationsfil och sedan konfigurera den. Vi kommer att använda det officiella MySQL-förrådet.

cd /usr/src && wget http://dev.mysql.com/get/mysql57-community-release-el6-7.noarch.rpm && rpm -i mysql57-community-release-el6-7.noarch.rpm
yum install mysql-community-server -y

The first command is where we download the RPM file to enable the MySQL repository on our system. Then, rpm -i installs the RPM file. Finally, we'll install MySQL from the official MySQL repository.

Steg 3: Ladda ner/installera PHP

PHP har vissa beroenden som vi behöver installera, så låt oss komma till det först.

yum install -y libxml2-devel libcurl-devel libmcrypt libmcrypt-devel

We're using the package manager once more - but this time, we're installing some components to allow PHP applications to run properly.

Ladda ner källan för PHP, vilket görs genom att utföra följande kommandon:

wget http://docs.php.net/distributions/php-5.6.15.tar.gz && tar xvf php-5.6.15.tar.gz
cd php-5.6.15
./configure --with-pear=/usr/lib/pear --enable-libxml --with-pdo-mysql --with-mysqli --with-mysql --enable-mbstring --with-mcrypt --with-apxs2=/usr/local/apache2/bin/apxs --enable-maintainer-zts --with-curl=/lib
make && make install

The first part, wget, is where we download the source to PHP 5.6.15. Then, we change our working directory to php-5.6.15. Finally, we configure PHP with the features required to run various web applications, such as e-commerce websites.

Observera att om du får ett meddelande som innehåller "/path/to/perl", måste du redigera filen /usr/local/apache2/bin/apxs.

nano /usr/local/apache2/bin/apxs

Ändra den första raden till:

#!/usr/bin/perl -w

Steg 4: Starta/stoppa LAMP-stacken

Eftersom vi har byggt Apache från grunden, innehåller den inte en förbyggd tjänst. Vi måste ställa in init-skriptet själva.

cd /usr/src && wget https://gist.githubusercontent.com/anonymous/62b0b788f86e7773e901/raw/6bcc88f9354f7139916272ac7a4eb998b1f26fdd/httpd-init
mv httpd-init /etc/init.d/httpd
chmod 755 /etc/init.d/httpd

The first part, where we cd, changes our working directory to the directory where we build/compile software. Then, with &&, we execute anything after it as well, which in this case, downloads the service file for Apache. Finally, we give permission for it to be executed with the chmod command.

Klart och klart!

Låt oss nu starta Apache + MySQL + PHP:

service httpd start
service mysqld start

With the service commands, we can manage the status of services. In this case, we've started the services httpd and mysqld.

PHP startas med Apache, det kommer inte igång via en tjänst.

Slutsats

I den här artikeln behandlade vi hur man ställer in en LAMP-stack från början med uppdaterade versioner av Apache/PHP/MySQL. Även om det kräver mer administration att hantera, är den här tekniken användbar när vi vill ha en nyare stack än vad operativsystemsleverantören erbjuder.

Lämna en kommentar

Blogg