User Tools

Site Tools


laravel_development_on_fedora_31

Laravel Development on Fedora 31

This also applies to PHP development in general.

Install Apache

sudo dnf install httpd
sudo systemctl start httpd
systemctl status httpd
sudo systemctl enable httpd
sudo firewall-cmd --permanent --add-service={http,https}
sudo firewall-cmd --reload

Install PHP

sudo dnf install php php-cli
sudo dnf install php-bcmath php-json php-mbstring php-pdo php-xml
sudo dnf install php-mysqlnd php-pgsql
sudo systemctl restart httpd
sudo dnf install composer
sudo vim /etc/php.ini

Edit the date.timezone field under [Date].

Install PostgreSQL

sudo dnf install postgresql-server postgresql-contrib
sudo /usr/bin/postgresql-setup --initdb
sudo systemctl start postgresql
systemctl status postgresql
sudo systemctl enable postgresql
sudo firewall-cmd --permanent --add-service=postgresql
sudo firewall-cmd --reload

Configure PostgreSQL

sudo vim /var/lib/pgsql/data/postgresql.conf
sudo systemctl restart postgresql

Edit the following lines:

listen_addresses = '*'
port = 5432
max_connections = 100
superuser_reserved_connections = 3
shared_buffers = 4GB
huge_pages = try
work_mem = 40MB
effective_cache_size = 8GB

I was setting this up on a 4-core/8-thread laptop with 16GB RAM. Adjust settings proportionally.

See also: https://fedoraproject.org/wiki/PostgreSQL

Allow Remote Connections

Edit /var/lib/pgsql/data/pg_hba.conf on the server. The file should already have enough comments to follow.

# TYPE  DATABASE        USER            ADDRESS                 METHOD
host    all             all             samenet                 md5

Note that I initially set scram-sha-256 but it didn't work. Changing to md5 solved the problem. This is probably related to the default password encryption settings. The error was: psql: FATAL: password authentication failed for user …

After the file is updated, run this:

sudo su - postgres
pg_ctl reload

Without changing this file, you will get errors saying psql: FATAL: no pg_hba.conf entry for host …

To connect from a remote host:

$ sudo dnf install postgresql
$ psql --host=$HOST --username=$USERNAME $DB_NAME

Install pgcrypto

sudo su - postgres
psql
postgres=# create extension pgcrypto;
postgres=# select gen_random_uuid();

Create Laravel Project

cd ~/src/
composer create-project --prefer-dist laravel/laravel blog
sudo mv blog /opt
cd /opt
sudo semanage fcontext -a -t httpd_sys_content_t "/opt/blog(/.*)?"
sudo semanage fcontext -a -t httpd_sys_rw_content_t "/opt/blog/storage(/.*)?"
sudo restorecon -R -v .
sudo chgrp -R apache blog/
sudo chmod -R o-rwx blog/
sudo chmod -R g+w blog/storage/

Configure Apache

sudo mkdir /srv/blog.test
sudo chown -R $USER:$USER /srv/blog.test
cd /srv/blog.test
ln -s /opt/blog/public html
mkdir log
vim httpd.conf
sudo semanage fcontext -a -t httpd_sys_content_t "/srv/blog.test/html(/.*)?"
sudo semanage fcontext -a -t httpd_log_t "/srv/blog.test/log(/.*)?"
sudo semanage fcontext -a -t httpd_config_t "/srv/blog.test/httpd.conf"
sudo restorecon -R -v .
cd /etc/httpd/conf.d
sudo ln -s /srv/blog.test/httpd.conf blog.test.conf
sudo systemctl restart httpd

httpd.conf

<VirtualHost *:80>
	ServerName	blog.test
	DocumentRoot	/srv/blog.test/html
	ErrorLog	/srv/blog.test/log/error.log
	TransferLog	/srv/blog.test/log/access.log

	<Directory /srv/blog.test/html>
		Require all granted
		AllowOverride all
	</Directory>
</VirtualHost>
laravel_development_on_fedora_31.txt · Last modified: 2020/02/01 18:48 by root