LAMP stack is a group of open source software used to get web servers up and running. The acronym stands for Linux, Apache, MySQL, and PHP. Since the server is already running Fedora, the linux part is taken care of. Here is how to install the rest.
Before you start installing the LAMP programs, you should first download and install all of the updates with yum update:
yum update
Apache is a free open source software which runs over 50% of the world’s web servers.
To install apache, open terminal and type in this command:
sudo yum install httpd
Once it installs, you can start apache running on your VPS:
sudo service httpd start
That’s it. To check if Apache is installed, direct your browser to your server’s IP address (eg. http://12.34.56.789). You should see the default Fedora page
You can run the following command to reveal your server’s IP address.
ifconfig eth0 | grep inet | awk '{ print $2 }'
MySQL is a powerful database management system used for organizing and retrieving data on a virtual server
To install MySQL, open terminal and type in these commands:
sudo yum install mysql mysql-server sudo service mysqld start
During the installation, MySQL will ask you for your permission twice. After you say Yes to both, MySQL will install.
Once it is done installing, you can set a root MySQL password:
sudo /usr/bin/mysql_secure_installation
The prompt will ask you for your current root password.
Since you just installed MySQL, you most likely won’t have one, so leave it blank by pressing enter.
Enter current password for root (enter for none): OK, successfully used password, moving on...
Then the prompt will ask you if you want to set a root password. Go ahead and choose Y and follow the instructions.
Fedora automates the process of setting up MySQL, asking you a series of yes or no questions.
It’s easiest just to say Yes to all the options. At the end, MySQL will reload and implement the new changes.
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... All done! If you've completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL!
PHP is an open source web scripting language that is widely used to build dynamic webpages.
To install PHP on your virtual private server, open terminal and type in this command:
sudo yum install php php-mysql
Once you answer yes to the PHP prompt, PHP will install itself.
PHP also has a variety of useful libraries and modules that you can add onto your server. You can see the libraries that are available by typing:
yum search php-
Terminal then will display the list of possible modules. The beginning looks like this:
php-fpdf-doc.noarch : Documentation for php-fpdf php-libvirt-doc.noarch : Document of php-libvirt php-pear-Auth-radius.noarch : RADIUS support for php-pear-Auth php-pear-Auth-samba.noarch : Samba support for php-pear-Auth ice-php-devel.i686 : PHP tools for developping Ice applications ice-php-devel.x86_64 : PHP tools for developping Ice applications perl-PHP-Serialization.noarch : Converts between PHP's serialize() output and : the equivalent Perl structure php-IDNA_Convert.noarch : Provides conversion of internationalized strings to : UTF8 php-Kohana.noarch : The Swift PHP Framework php-LightweightPicasaAPI.noarch : A lightweight API for Picasa in PHP php-PHPMailer.noarch : PHP email transport class with a lot of features php-Smarty.noarch : Template/Presentation Framework for PHP php-ZendFramework.noarch : Leading open-source PHP framework php-ZendFramework-Auth-Adapter-Ldap.noarch : Zend Framework LDAP : Authentication Adapter php-ZendFramework-Cache-Backend-Apc.noarch : Zend Framework APC cache backend
To see more details about what each module does, type the following command into terminal, replacing the name of the module with whatever library you want to learn about.
yum info name of the module
Once you decide to install the module, type:
sudo yum install name of the module
You can install multiple libraries at once by separating the name of each module with a space.
Congratulations! You now have LAMP stack on your droplet!
We should also set the processes to run automatically when the server boots (php will run automatically once Apache starts):
sudo chkconfig httpd on sudo chkconfig mysqld on
Although LAMP is installed on your virtual server, we can still take a look and see the components online by creating a quick php info page
To set this up, first create a new file:
sudo nano /var/www/html/info.php
Add in the following line:
<?php phpinfo(); ?>
Then Save and Exit.
Restart apache so that all of the changes take effect on your virtual server:
sudo service httpd restart
Finish up by visiting your php info page (make sure you replace the example ip address with your correct one): http://12.34.56.789/info.php
It should look similar to this:
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Been using windows so long my mind continuously replaced “ifconfig” with “ipconfig” until finally realizing someones “typo” that I realized was not a typo at all. IFconfig, not IPconfig. Just wanted to point that out for other Windows long-timers.
Oh yeah, I never did get “ifconfig eth0 | grep inet | awk ‘{ print $2 }’” to work… instead I used “ifconfig” by itself and it worked fine.
Fedora doesn’t always use eth0 as the default Ethernet port, usually it is em1 so the command would be " ifconfig em1 | grep inet | awk ‘{ print $2 }’ "
A useful command I use is " ifconfig | grep -v ‘inet6|127.0.0.1’ | grep inet " optionally with | awk ‘{print $2}’ at the end as this works regardless of the Ethernet port name.
If you are new to Linux you might think this takes a long time to type out and your right but you can add this as an alias to you .bashrc file that is in your home directory. Add the following code to .bashrc, restart your terminal then when you want your ip address just type ip
alias ip=“ifconfig | grep -v ‘inet6|127.0.0.1’ | grep inet | awk ‘{ print $2 }’”
very good, thank you.
I can’t get the mySQL service to start. It also only asked me to give it permission once during the mySQL install. Am I doing something wrong?
@Daniel: What do you see if you try to run <pre>sudo service mysqld start</pre>?
I get>>>>>>>>>>
bash: service: command not found
@dheeraj08515: Does replacing <pre>service</pre> with <pre>/sbin/service</pre> fix it?
how to install Apache web server on fedora8 ?
To install the Apache web server on a more recent version of Fedora, you can follow these general steps:
Open Terminal: Press
Ctrl + Alt + T
to open a terminal window.Update System Packages: It’s a good practice to ensure your system’s package repositories are up to date before installing new software. Run the following commands:
firewalld
to open the HTTP port (80):Verify Apache Installation: Open a web browser and enter your server’s IP address in the address bar. You should see the default Apache test page, indicating that Apache is working correctly.
If you don’t know your server’s IP address, you can find it by running:
Configure Virtual Hosts (Optional): If you plan to host multiple websites or need custom configurations, you can create Apache virtual hosts. These configurations are typically stored in files under
/etc/httpd/conf.d/
or/etc/httpd/conf/httpd.conf
depending on the Fedora version.Secure Your Apache Installation (Optional): It’s important to secure your Apache installation by configuring SSL/TLS certificates, setting up authentication, and regularly applying security updates.
mysqld has to be replaced with mariadb. For some reason systemctl status mysqld will correct, but enable and start won’t.
Worked here! Thanks!
Thanks. <3 this was useful for me.
Hi. i have try: sudo chkconfig mysqld on Error: Failed to issue method call: No such file or directory
I had been working tirelessly before reading this article to run test.php I’ve to say thanks to you from the bottom of my heart.
Fedora 20 replaces service with systemctl.
Type
systemctl
on a line by itself to see all the neat things you can do with it.sudo systemctl | less
I see my php output. Ergo I am on to the next setup step
Heya,
While
systemctl
is the successor ofservice
both are available on any system.installed fedora 20 x64
after installing httpd and verifying that its running using systemctl status httpd.service (which says its active) I can’t see any page in the browser, it times-out.
@jeff, I found my self in the same situation, til’ I’ve notice that it’s probably a 403 error, try to wget localhost within the server or do a telnet localhost 80 and then GET / HTTP/1.0, if is a 403 (and if you haven’t touch the virtual dir permissions in httpd.conf) it’s most related to a permissions configuration, /var/www/html/ should be +rx by apache, chmod 755 -R /var/www/html will do the job.
Also, check if the firewall is up, add a rule to it or deactivate the firewall (not recommended).
I’ll leave this here just for the record.
Hi, while I was running an info.php script, the browser shows the php script as plain text, any suggestion?
Heya,
This means you have not installed or configured PHP on apache.
After the installation, try to load the info.php file again.
@josiastech: Have you restarted Apache after installing php?
Very helpful steps, but the step about revealing my IP address is not accurate, as not always eth0 is the name of the ethernet interface. Mine for example is em1 so to get a list of all interfaces including IP version 6 use:
ifconfig | grep inet | awk ‘{print $2}’
Heya, that is correct however that way you’ll get your IPv6 and localhost ip address.
Another similar command would be:
Just a concern (newb on web servers). When I install apache and start the service, to test do I go to the browser from my current location. Or, is it referring to the browser in the droplet? When I try to get to my IP the request times out. Someone looked and said I had port 80 closed, but I don’t want to mess with firewall rules unless it’s definitely necessary.
You should load your Droplet’s IP address.
This comment has been deleted
Thanks for the awesome tutorial!! The installation was very smooth
Note that Fedora 20 has
firewalld
running by default. You won’t be able to access the fedora test page unless you add an exception for httpd.Hi, sorry, could you help me please?
I followed all the steps but when I try to run this services, I got this warning:
Command : sudo service httpd start
Redirecting to /bin/systemctl start httpd.service Job for httpd.service failed. See ‘systemctl status httpd.service’ and ‘journalctl -xn’ for details.
Command: sudo service mysqld start
Redirecting to /bin/systemctl start mysqld.service
After run “systemctl status httpd.service’ and 'journalctl -xn” I got
Everything seems to go fine until I try to view the Apache test page. When I try entering my ip address into a browser, it just spins for awhile then says the webpage is not available. Any suggestions?
Very nice tutorial!
i’ve signed up and bookmarked this site because of the explaination : ) thanks a lot
In my PC the repositories didn’t find any package with name: “php-mysql”. The terminal says something like this: “No match for argument: php-mysql”
So I typed the command:
dnf search php- | grep mysql
It found that the real package name nowadays is “php-mysqlnd”, so try to install this instead of “php-mysql”:
dnf install php-mysqlnd