Fedora php apache mysql

How to Install Apache, MySQL, and PHP (LAMP) Stack on Fedora 34

The LAMP stack is a software bundle composed of Linux, Apache, MySQL or MariaDB, and PHP. These free open-source software applications drive dynamic web applications such as WordPress, Joomla, Magento, and more.

In this guide, you’ll install Apache as the HTTP server, MySQL or MariaDB as a relational database management system, and PHP as the server-side scripting language. On the Linux part, you’ll use Fedora 34 operating system. After completing this guide, your Apache web server will run a PHP script, connect to a database, and return a successful response.

Prerequisites

Before you begin, ensure you have the following:

1. Install Apache Web Server

SSH to your server and ensure your system is up to date.

In Fedora, the Apache HTTP server runs as an httpd daemon. Install the package by running the command below.

$ sudo systemctl start httpd 

Visit your server’s domain name or public IP address in a web browser to test the installation.

You should now see a Fedora Web Server Test Page as shown below.

Fedora Web Server Test Page

Enable the web server to start automatically.

$ sudo systemctl enable httpd 

You may also find these control command useful:

    To stop the web server when performing maintenance:

$ sudo systemctl stop httpd 
$ sudo systemctl restart httpd 
$ sudo systemctl reload httpd 

After installing Apache, you can locate the httpd service main configuration file from this location.

When working in a system architecture that calls for separation of concerns, you can include different configuration files under the directory below.

By default, Apache serves all requests from /var/www/html .

2. Install MySQL/MariaDB Server

When setting up a LAMP stack, you have a choice of either MySQL or MariaDB server. Both are compatible with most popular content management systems.

Please note: MariaDB is a fork of the MySQL package, and installing both packages on the same server causes conflicts.

Option 1: Install the MariaDB Server

To set up the MariaDB server, run the command below.

$ sudo dnf install -y mariadb-server 

After installation, the MariaDB server runs under the daemon mariadb . Start the mariadb service.

$ sudo systemctl start mariadb 

Enable the service to start automatically when your server boots.

$ sudo systemctl enable mariadb 

You can find the main MariaDB configuration file in the location below.

You can add more configuration files that load when the MariaDB server starts in /etc/my.cnf.d/ .

If you make any changes to the MariaDB configuration file, you must always restart the mariadb service using the command below.

$ sudo systemctl restart mariadb 

To stop the mariadb service, use the command below.

$ sudo systemctl stop mariadb 

To continue testing this guide, make sure the MariaDB server is running.

$ sudo systemctl start mariadb 

Option 2: Install the MySQL Server

If you have a particular need for MySQL server or prefer it over the MariaDB server, follow these installation steps.

To install the MySQL server, pull the community-mysql-server package from the main Fedora repository.

$ sudo dnf install -y community-mysql-server 

After completing the installation, start the MySQL service. It runs under the service — mysqld

$ sudo systemctl start mysqld 

Enable the MySQL server to run automatically when your server boots.

$ sudo systemctl enable mysqld 

You can locate the main MySQL configuration file in the location below.

/etc/my.cnf.d/community-mysql-server.cnf 

Also, you can place fragmented configuration files under the directory below.

Remember to restart the mysqld service if you make any configuration changes.

$ sudo systemctl restart mysqld 

To stop the MySQL server at any time, run the command below.

$ sudo systemctl stop mysqld 

To proceed with this guide, ensure the MySQL server is running.

$ sudo systemctl start mysqld 

Secure the Database Server

Secure the database server by running the command below. This applies to both MySQL and MariaDB.

$ sudo mysql_secure_installation 

Answer the prompts depending on the package that you’re configuring. Replace EXAMPLE_PASSWORD with a strong value for the root user. For this guide, you may skip setting up the validate_password component that validates the strength of passwords in the MySQL server. However, in a production environment, you can enable it to avoid using weak passwords.

After you’ve finished securing MySQL/MariaDB server, log in to the database server as a root user.

Enter your root password for the MySQL/MariaDB server and press ENTER to proceed. Then, issue the command below to create a sample_db database and a test_user user.

mysql> CREATE DATABASE sample_db; CREATE USER 'test_user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'EXAMPLE_PASSWORD'; GRANT ALL PRIVILEGES ON sample_db.* TO 'test_user'@'localhost'; FLUSH PRIVILEGES; 
MariaDB> CREATE DATABASE sample_db; GRANT ALL PRIVILEGES on sample_db.* TO 'test_user'@'localhost' identified by 'EXAMPLE_PASSWORD'; 
Query OK, 1 row affected (0.00 sec) . 

Exit from the database server command-line interface.

3. Install PHP

Install some common PHP extensions required to create dynamic websites and web applications.

$ sudo dnf install -y php-cli php-fpm php-common php-mbstring php-curl php-gd php-mysqlnd php-json php-xml php-intl php-pecl-apcu php-opcache 

You can locate the main PHP configuration file in this location.

In case you make any changes to the PHP configuration file, remember to reboot the Apache web server. PHP also scans the directory below for configuration files.

Restart the httpd service to load the PHP package.

$ sudo systemctl restart httpd 

Install nano text editor and open a new /var/www/html/test.php to test PHP connectivity to the MySQL/MariaDB database.

$ sudo dnf install -y nano $ sudo nano /var/www/html/test.php 

Paste the content below into the file.

connect_error) < die("Failed to connect to the database: " . $con->connect_error); > echo "Connection to the database was successful"; 

Save the file by pressing CTRL + X , then Y and ENTER .

Visit your web server’s domain name or IP address in a web browser.

You should see a success message. Your PHP script is now able to connect to the MySQL/MariaDB database.

Connection to the database was successful 

Your Apache web server is serving the web content from the /var/www/html directory. Up to this point, your LAMP stack is working as expected.

Conclusion

In this tutorial, you’ve installed a LAMP stack on your Fedora 34 server. With this setup in place, you can now upload your website/web application or probably install a content management system like WordPress.

Want to contribute?

You could earn up to $600 by adding new articles.

Источник

How To Install LAMP (Linux, Apache, MySQL, PHP) on Fedora 22

How To Install LAMP (Linux, Apache, MySQL, PHP) on Fedora 22

A 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.

Prerequisites

Before beginning this tutorail you should have a running Fedora 22 droplet and be logged in via SSH.

Before you start installing the LAMP programs, you should first download and install all of the updates with dnf update dnf replaced yum as the default package manager for Fedora in version 22:

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:

Once it installs, you can start apache running on your VPS:

sudo systemctl start httpd.service 

Fedora Default

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

###How to find your Droplet’s IP address

You can run the following command to reveal your server’s IP address.

ifconfig eth0 | grep inet | awk '< print $2 >' 

MySQL/MariaDB 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 dnf install mysql mysql-server sudo systemctl start mariadb.service 

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 MariaDB installation has an anonymous user, allowing anyone to log into MariaDB 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, MariaDB 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 MariaDB installation should now be secure. Thanks for using MariaDB! 

PHP is an open source web scripting language that is widely used to build dynamic web pages.

To install PHP on your virtual private server, open terminal and type in this command:

sudo dnf 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:

The 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.

dnf info name of the module 

Once you decide to install the module, type:

sudo dnf 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 mariadb on 

##Step Four—RESULTS: See PHP on your Server

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 install the nano text editor and create a new file:

sudo dnf install nano sudo nano /var/www/html/info.php 

Add in the following line:

Restart apache so that all of the changes take effect on your virtual server:

sudo systemctl restart httpd.service 

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:

PHP Info

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Источник

Читайте также:  Изменять прозрачность элементов позволяет css свойство
Оцените статью