איך להתקין Linux ,Apache ,MySQL ,PHP (LAMP)

התקנת lamp

מה זה LAMP?

ראשי תיבות של 4 תוכנות חופשיות, עליהן מבוססים מספר רב של שרתים ואתרי אינטרנט:

L – Linux
A – Apache
M – MySQL
P – PHP

במאמר זה אנו נתייחס להתקנה על מערכות מבוססות Debian/Ubuntu.

התקנת Apache:

Apache זאת תוכנת Web Server חופשית.
היא בעצם התוכנה שמטפלת בבקשות HTTP שמגיעות לשרת, וכ – 50% מכלל אתרי האינטרנט בעולם מבוססים עלייה.

להתקנה הקלד את הפקודות הבאות:

sudo apt-get update sudo apt-get install apache2

מעולה. עכשיו צריך לבדוק ש – Apache עובד בצורה תקינה. העתק את כתובת ה – IP של השרת והדבק אותה בדפדפן. במידה והכול תקין, תוצג ההודעה It works!

התקנת MySQL:

MySQL הנה מערכת ניהול מסד נתונים,  אשר משתמשים בה לאחסון נתונים, אחזור נתונים, ועוד.
להתקנת MySQL העתק את הפקודות הבאות:

sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql

בזמן ההתקנה, MySQL יבקש להגדיר סיסמת root, במידה ולא הופיעה האופציה להגדרת סיסמא במהלך ההתקנה, אפשר לאחר מכן בקלות להגדיר סיסמא עם MySQL shell.

לאחר התקנת MySQL, נבצע פעולת הפעלה עם הפקודה הבאה:

sudo mysql_install_db

לסיום, הרץ את הסקריפט:

sudo /usr/bin/mysql_secure_installation

לאחר מכן, ה – Prompt יבקש ממך את סיסמת ה – root:

Enter current password for root (enter for none): OK, successfully used password,  moving on

לאחר מכן, תופיע בקשה של שינוי סיסמא, יש להקליד N.

הדרך הקלילה ביותר לביצוע ההתקנה, היא בחירה  ב – YES בכלל השאלות המופיעות בתהליך.
בסופו של תהליך ההתקנה, ה – MySQL יטען ויוגדר:

By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y … Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] y … Success! By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] y – Dropping test database… … Success! – Removing privileges on test database… … Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y … Success! Cleaning up

התקנת PHP:

PHP הנה שפת קוד פתוח, אשר משומשת לבניית דפים דינמיים. להתקנת PHP הרץ את הפקודות הבאות:

sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt

לאחר שהשבת YES לכלל השאלות, ה – PHP יותקן באופן עצמאי. יהיה שימושי להוסיף את ה – PHP לנתיב של index.
לצורך כך, נערוך את קובץ הקונפיגורציה:

sudo nano /etc/apache2/mods-enabled/dir.conf

נוסיף את הקובץ index.php לרשימת קבצי ה – index. בסיום, הקובץ אמור להיראות כך:

<IfModule mod_dir.c> DirectoryIndex index.php index.html index.cgi index.pl index.php index.xhtml index.htm </IfModule>

מודולים של PHP:

ל – PHP יש המון ספריות שונות ומודולים שאפשר להוסיף לשרת שלכם, ניתן לבדוק אלו ספריות קיימות:

-apt-cache search php5

באפשרותינו לבחור ולהתקין מודולים וספריות אשר נמצאו בחיפוש, בהתאם לפורמט הבא:

<sudo apt-get install <name of the module

איך רואים את ה - PHP בשרת?

לאחר שסיימנו להתקין LAMP, נוכל ליצור דף info של PHP, אשר יפרט לנו את התוכנות/ספריות המותקנות, וגרסאותיהן.
ניצור דף PHP באמצעות הפקודה:

sudo nano /var/www/info.php

אל הדף נוסיף את השורה הבאה:

<?php phpinfo(); ?>

לאחר מכן נבצע שמירה ויציאה.
ליתר ביטחון, כדאי לבצע restart ל Apache כדי שהשינויים יכנסו לפעולה:

sudo service apache2 restart

לסיום, הכנס את כתובת השרת שלך, ותוכל לראות את דף PHP info:

http://<your-server-ip>/info.php

יש לכם שאלות? מעוניינים לשמוע על סוגי השירותים שלנו? מוזמנים ליצור איתנו קשר!

Facebook
Twitter
LinkedIn