LAMP (Linux, Apache, MySQL, PHP)
In this guide, we will walk through installing all of these components (except for Linux, which is already installed as your OS when you create the server).
Install Apache
- Make sure that your software is up to date:
#sudo yum update
- Install Apache:
#sudo yum install httpd
- Start Apache:
#sudo systemctl start httpd.service
- Set Apache to start on server boot:
#sudo systemctl enable httpd.service
Install MySQL
- Install MariaDB, which is a community-developed fork of MySQL:
#sudo yum install mariadb-server mariadb
- Start the service:
#sudo systemctl start mariadb
- Set MySQL to start on server boot:
#sudo systemctl enable mariadb.service
- Run this command to finish setting up the installation:
#sudo mysql_secure_installation
Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorization. New password: password Re-enter new password: password Password updated successfully! Reloading privilege tables.. ... Success!
- You will be asked for the root password. Because you didn’t set it earlier, press Enterto set a password now.
- Type “Y” to set the root password.
- Enter and confirm the new password.
- You will be asked more questions as part of the security configuration. It is a best practice to respond “Y” to these system prompts
Install PHP
- Install PHP:
#sudo yum install php php-mysql
Enter “Y” to install.
- Restart Apache:
#sudo systemctl restart httpd.service
Update Firewall
#sudo firewall-cmd --permanent --zone=public --add-service=http #sudo firewall-cmd --permanent --zone=public --add-service=https #sudo firewall-cmd --reload
<
Test PHP processing on Apache
- Create a new PHP file under the
/var/www/html
directory:sudo vi /var/www/html/info.php - When the file opens, type in the following code:
<?php phpinfo(); ?>
- Save and close the file:
:wq!
- To verify it worked, type this URL in your browser:
http://your server’s IP address/info.php
A page displays with the PHP version, extensions, build date, and other information.